I am currently facing a performance issue on my website. The situation can be summarized as follows:
- This is the .Net Mvc website using SQL Server 2012 Express. It was hosted on Windows Server 2012.
- The main system contains about 10 million UPDATE queries per day (5 million in 2 different tables) and another 10 million for user statistics purposes (again, 2 * 5 million).
- There are far fewer INSERT requests.
- There are no performance issues on the MVC website, most requests are handled by a single method that returns simple content (rather than html).
Since statistics are not as important as the main system, and I see that SQL Server is struggling a lot, I thought it might be useful to move these statistics tables somewhere else.
The main question . What is the best way to handle statistics where updates prevail? The idea is also to save only one server.
I tried to see what can be done to improve the situation:
- Having a separate SQL Server database for statistics on another hard drive? Maybe SQL Server can breathe better, but I'm not sure.
- Using a NoSQL Database? I just have little experience with MongoDb (but not for millions of queries), and I am tempted to try RavenDB.
- ? Redis , , Windows. AppFabric ?
.
:
TABLE [dbo].[UserStat](
[Id] [int] IDENTITY(1,1) NOT NULL,
[UserId] [int] NOT NULL,
[Hits] [int] NOT NULL,
[Points] [decimal](38, 6) NOT NULL,
[Date] [datetime] NOT NULL,
[LastHit] [datetime] NOT NULL,
[Ip] [varchar](256) NULL,
)
stat :
UPDATE [UserStat] SET Hits = Hits + 1, Points = Points + @Points, LastHit = @Last WHERE UserId = @Id AND [Ip] = @Ip AND [Date] = @Date
, :
INSERT INTO [UserStat] ([UserId],[Hits],[Points],[Date],[LastHit],[Ip]) VALUES (@UserId,@Hits,@Points,@Date,@LastHit,@Ip)
:
- 1
1
INDEX [Select_UpdateUserStatNavigation] ON [dbo].[UserStat](
[UserId] ASC,[Date] ASC) INCLUDE ([Id],[Hits],[Points], [LastHit],[Ip])
- VPS. . .
SELECT, , :
SELECT Points, Hits, [Date] FROM [UserStat] WHERE UserId = @UId AND [Date] >= @date
SELECT Ip FROM [UserStat] WHERE UserId = @UId AND LastHit >= DATEADD(MINUTE,-15,getdate())
SELECT COUNT(Id) FROM [UserStat] WHERE [LastHit] >= DATEADD(MINUTE,-15,getdate())
SELECT, UPDATEs ^^.