简体   繁体   English

SQL Server 2005:间歇性缓慢插入

[英]SQL Server 2005 : intermittently slow Inserts

I have a client app that is submitting the following command to SQL Server 2005. At a specific time of day we are having performance issues where some of the requests are taking between 2 - 8 seconds to run when the norm is below 300ms. 我有一个客户端应用程序正在向SQL Server 2005提交以下命令。在一天的特定时间,我们遇到性能问题,当规范低于300ms时,某些请求将花费2-8秒才能运行。 We are researching SQL Server options as well as all external variables that can impact the server. 我们正在研究SQL Server选项以及所有可能影响服务器的外部变量。

My question here is how/why can a request take 8 seconds and during this time many other identical requests start and finish during this 8 second window? 我的问题是,请求为何/为什么要花费8秒,而在这段时间内,许多其他相同的请求在这8秒内开始和结束? What can be preventing the 8 second call from finishing, but not prevent or slow down the other calls? 是什么可以阻止8秒通话结束,但不能阻止或减慢其他通话的速度呢?

Running server profiler during this time the number of reads are around 20 and the writes less than 5 for all (long and short durations) the calls. 在这段时间内运行服务器事件探查器,读取的次数大约为20,而所有(长时间和短时)调用的写入次数均少于5。

The table being inserted into has around 22M records. 插入的表大约有2200万条记录。 We are keeping about 30 days worth of data. 我们将保留大约30天的数据。 We will probably change the approach to archive this data daily and keep the daily insert table small and index free, but really want to understand what is happening here. 我们可能会改变每天存档此数据的方法,并使每天的插入表保持较小且没有索引,但实际上是想了解这里发生的情况。

  • There are no triggers on this table. 该表上没有触发器。
  • There are 3 indexes for GUID, Time and WebServerName (none are clustered) GUID,时间和WebServerName共有3个索引(均未集群)

Here's the command being submitted: 这是正在提交的命令:

exec sp_executesql N'Insert Into WebSvcLog_Duration (guid,time,webservername,systemidentity,useridentity,metricname,details,duration,eventtype)values(@guid,@time,@webservername,@systemidentity,@useridentity,@metricname,@details,@duration,@eventtype)',N'@guid nvarchar(36),@time datetime,@webservername nvarchar(10),@systemidentity nvarchar(10),@useridentity nvarchar(8),@metricname nvarchar(5),@details nvarchar(101),@duration float,@eventtype int',@guid=N'...',@time='...',@webservername=N'...',@systemidentity=N'...',@useridentity=N'...',@metricname=N'...',@details=N'...',@duration=0.0,@eventtype=1

The probable reason why is heap fragmentation; 堆碎片的可能原因; you didn't mention if you had some sort of index maintenance going on, so I'm assuming that it's non-existent. 您没有提到是否正在进行某种索引维护,因此我假设它不存在。 The best way to minimize fragmentation is to build a clustered index on a monotonic value (a column with a naturally increasing order). 最小化碎片的最佳方法是在单调值(具有自然递增顺序的列)上建立聚簇索引。 I'm not sure what the time column is supposed to represent, but if it's the time of insertion, then it might be a good candidate for a clustered index; 我不确定时间列应该代表什么,但是如果是插入时间,那么它可能是聚集索引的不错选择; if not, then I'd add a column that captures the time inserted into the table and build a clustered index on that. 如果没有,那么我将添加一列来捕获插入表中的时间,并在此基础上建立聚簇索引。

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

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