简体   繁体   English

在ASP.NET中存储大量数据

[英]Storing great amount of data in ASP.NET

I've built a website in ASP.NET (Umbraco CMS) which has a contest module. 我在ASP.NET(Umbraco CMS)中建立了一个有竞赛模块的网站。 The company launches about two contests every month and each contest has an average of ~15.000 contestants. 该公司每月举办两场比赛,每场比赛平均有约15.000名参赛者。 These contestants are stored in a database tables which is designed like this: 这些参赛者存储在数据库表中,其设计如下:

Contestant 选手

Id
Name
ZipCity
Address
Country
Email
DateAttended

ZipCity ZipCity

Id
Zipcode
City

ContestAnswer ContestAnswer

Id
AnswerNodeId (Umbraco node id)
ContestNodeId (Umbraco node id)
ContestantId
Date

Each contest can have one question and N number of answer options. 每个比赛可以有一个问题和N个答案选项。

The way I have created it to save the number of records in the database is that for every single answer, I check to see if there's already a contestant with the given e-mail in the Contestant table. 我创建它以保存数据库中的记录数量的方式是,对于每个单独的答案,我检查是否已经有参赛者表中的给定电子邮件的Contestant If there is, I use that one and if not, I create a new contestant. 如果有的话,我会使用那个,如果没有,我会创建一个新的参赛者。 Also, for every contestant I check if the provided zipcode is already in the ZipCity table and create a reference to that. 此外,对于每个参赛者,我检查所提供的邮政编码是否已经在ZipCity表中,并创建一个参考。

Even though I have done it this way instead of blindly creating a new Contestant for every contest, the database keeps getting filled up :-( I've increased the capacity twice now and still getting the same exception after some time: 即使我这样做而不是盲目地为每个比赛创建一个新的Contestant ,数据库仍然被填满:-(我现在增加了两倍的容量,并且在一段时间后仍然得到相同的异常:

Could not allocate space for object ... because the filegroup is full. 无法为对象分配空间...因为文件组已满。

The company wants to keep the contestants for each contest they launch, so deleting records after a contest has ended is not an option it seems :-/ 该公司希望为他们推出的每个比赛保留参赛者,因此在比赛结束后删除记录似乎不是一个选项: - /

So, now I've been wondering if there is a smarter way of storing these large amount of data? 那么,现在我一直想知道是否有更智能的方法来存储这些大量数据? Thoughts on this? 对此的想法?

Any inputs are greatly appreciated! 任何输入都非常感谢!

We don't know much about your hard drive setup. 我们对您的硬盘设置了解不多。

http://blog.sqlauthority.com/2009/05/31/sql-server-create-multiple-filegroup-for-single-database/ http://blog.sqlauthority.com/2009/05/31/sql-server-create-multiple-filegroup-for-single-database/

http://msdn.microsoft.com/en-us/library/bb522469.aspx http://msdn.microsoft.com/en-us/library/bb522469.aspx

The first link will explain the concept. 第一个链接将解释这个概念。

The second link will show the syntax. 第二个链接将显示语法。

The 3 items you want to look at are: 您要查看的3个项目是:

[ , SIZE = size [ KB | MB | GB | TB ] ] 
[ , MAXSIZE = { max_size [ KB | MB | GB | TB ] | UNLIMITED } ] 
[ , FILEGROWTH = growth_increment [ KB | MB | GB | TB| % ] ] 

Why? 为什么?

The first one is the initial size. 第一个是初始大小。 The second one is the maximum size. 第二个是最大尺寸。 And IF THIS IS SET, even though your harddrive may have space on it, the database will cease to grow. 如果这是设置的,即使您的硬盘可能有空间,数据库也将停止增长。 The third one is "how big will I expand, if I have not violated the maxsize rule". 第三个是“如果我没有违反maxsize规则,我会扩大多大”。

Now. 现在。 You can set the MAXSIZE to UNLIMITED. 您可以将MAXSIZE设置为UNLIMITED。

HOWEVER. 然而。 You'll start to get errors when your hard drive fills up. 当您的硬盘驱动器填满时,您将开始出错。

So you gotta play dba, and pick which option is best. 所以你必须玩dba,并选择哪个选项最好。
Personally, I would set the MAXSIZE to something less than the free space on the drive, so you don't hit the edge point. 就个人而言,我会将MAXSIZE设置为小于驱动器上的可用空间,因此您不会达到边缘点。

ALSO: You can create different file groups, and put different different tables on different file groups. 另外:您可以创建不同的文件组,并在不同的文件组上放置不同的不同表。 This is handy if you know one table will be HUGE, but the other will be small. 如果您知道一个表将是巨大的,但另一个表将是小的,这是很方便的。

So...check to see if you have a MAXSIZE setting set already. 所以......检查你是否已经设置了MAXSIZE设置。

Then you gotta play roulette with your tables and harddrives and filegroups and tables. 然后你必须用你的桌子和硬盘以及文件组和表格来玩轮盘赌。

You can also put your log files on a different hard drive as another option for space issues. 您还可以将日志文件放在另一个硬盘驱动器上作为空间问题的另一个选项。

Here is a good little sample of creating file groups, and then moving tables over to that new file group. 这是一个很好的小样本,用于创建文件组,然后将表移动到该新文件组。

http://www.daveturpin.com/2010/09/move-tables-to-new-filegroup/ http://www.daveturpin.com/2010/09/move-tables-to-new-filegroup/

Below is a script that I have for creating a database using SQLCMD Mode. 下面是我使用SQLCMD模式创建数据库的脚本。 Note the directories must "pre exist" (on the server, not your local machine if you are aren't actually sitting on the sql server). 请注意,目录必须“预先存在”(如果您实际上并不是在SQL服务器上,则在服务器上,而不是本地计算机上)。

:Setvar DBName MyFirstDatabase01
:Setvar DataFilesBaseDirectory "C:\WUTemp\Some Folder\"
:Setvar LogFilesBaseDirectory "C:\WUTemp\Some Folder\"
:Setvar DatabasePrimaryDataFileStartSizeMB 9
:Setvar DatabasePrimaryDataFileGrowthMB 8
:Setvar DatabasePrimaryLogFileStartSizeMB 7
:Setvar DatabasePrimaryLogFileGrowthMB 6




Use [master];
GO


if exists (select * from sysdatabases where name='$(DBName)')
BEGIN
        DROP DATABASE [$(DBName)];
END

GO



--Create Database $(DBName)
--G--O


DECLARE @device_directory_data NVARCHAR(520)
DECLARE @device_directory_log NVARCHAR(520)
--SELECT @device_directory_data = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1) FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1
--SELECT @device_directory_log = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1) FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1



select @device_directory_data = '$(DataFilesBaseDirectory)'
select @device_directory_log = '$(LogFilesBaseDirectory)'

print  @device_directory_data
print @device_directory_log


EXECUTE (N'CREATE DATABASE $(DBName)
  ON PRIMARY (NAME = N''$(DBName)'', FILENAME = N''' + @device_directory_data + N'$(DBName).mdf'', SIZE = $(DatabasePrimaryDataFileStartSizeMB) MB, FILEGROWTH = $(DatabasePrimaryDataFileGrowthMB)MB)
  LOG ON (NAME = N''$(DBName)_log'',  FILENAME = N''' + @device_directory_log + N'$(DBName).ldf'', SIZE = $(DatabasePrimaryLogFileStartSizeMB) MB, FILEGROWTH = $(DatabasePrimaryLogFileGrowthMB)MB)')

DECLARE @logsize char(1)
SELECT @logsize = CASE WHEN convert(varchar, Serverproperty('ProductVersion')) LIKE '9%'
                       --THEN '10'
                       --ELSE '5'
                       THEN '13'
                       ELSE '14'

                  END


EXECUTE(N'ALTER DATABASE $(DBName)
    ADD LOG FILE (NAME = N''$(DBName)_log2'',
                  FILENAME = N''' + @device_directory_log + N'$(DBName)log2.ldf'', SIZE = ' + @logsize + ' MB)')


-- Make the database case sensitive to clean up the development effort
--  EXECUTE(N'ALTER DATABASE $(DBName) COLLATE SQL_Latin1_General_CP1_CS_AS')  




exec sp_dboption '$(DBName)','trunc. log on chkpt.','true'
exec sp_dboption '$(DBName)','select into/bulkcopy','true'
GO




GO

There is not much you can do in terms of reducing space that will cause the data requirements to go down. 在减少导致数据需求下降的空间方面,您无能为力。 Also, 15k per month is not much really unless you are on some shared sql hosting that has severe limitations. 此外,每月15k并不是真的,除非你在一些有严重限制的共享sql托管。 Anyway, not much you can do here unfortunately. 无论如何,不​​幸的是,你在这里做的并不多。

Perhaps you can try with enabling sql server compression. 也许您可以尝试启用sql server压缩。 Check these articles for more details 查看这些文章了解更多详情

http://www.bradmcgehee.com/2010/03/an-introduction-to-data-compression-in-sql-server-2008/ http://www.bradmcgehee.com/2010/03/an-introduction-to-data-compression-in-sql-server-2008/

http://msdn.microsoft.com/en-us/library/cc280449.aspx http://msdn.microsoft.com/en-us/library/cc280449.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM