I am having a problem with my SQL Server 2005 where stored procs, specifically ones that run Bulk Inserts, are sometimes taking a really long time to execute. This stored proc, let’s call it DatabaseUpdate, shold take about 2 secs to complete. However, between 20-40% of the time it takes much more than that and it is very common that it will timeout after 30 secs.
What’s so strange about this is that I have a very controlled environment. The logs I am currently looking at, show a period in which the exact same events occur at regular intervals. There are handful of clients and they all make requests based on timers and these machines are all running atomic clock synchronization apps. So I can say with near certainty that the same sequence of events occurs every five minutes, yet my stored proc that imports a 100Kb file into the database varies in its execution time from 1.5-30+ secs.
What I had not noticed before, because I was only seeing the timeout errors, is that the longer execution times are occurring every other update, so the times look like this:
10:30 2062 ms
10:35 24250 ms
10:40 1921 ms
10:45 25703 ms
10:50 1734 ms
10:55 25406 ms
11:00 1625 ms
Any ideas?
Further to Mitch’s recommendations I would also suggest that troubleshoot your issue by running a SQL Trace to verify that the same “Actual” not “Estimated” execution plan is being used for each call of the stored procedure.
Also, validate that the same or a similar number of records is being processed with each execution/BULK INSERT because naturally the more records that are inserted by the procedure the longer it will take to execute.
Have you considered that your database may not be adequately sized to support your inserts? For example, does your database data file need to grow in order to accomodate every other procedure execution?
Provided these elements are the same between each execution then the only other element that will be changing is the database data itself and so would require investigations into statistics and index usage.