Sql-server – Stored Procedure slow after weekend

cachesql serversql-server-2012stored-procedures

When I come to work on monday some stored procedures take several minutes to execute and STATISTICS IO shows a lot of PHYSICAL READS and READ AHEADS going on.
However, after running the procedures 10-20 times with different parameters, the execution time drops to less than one second.

I think that for some reason the data buffer expires over the weekend, and it takes a lot of time to reload the buffer on monday.

How do I make sure my application works fast even if it's not used regulary. Is there a way to persist the buffer, or should I rewrite the procedures in a way that doesn't rely on the buffer?

Best Answer

The perf problem likely comes from IO that is cached under the week. The weekend work evicts those pages.

RAM is ~100x faster than sequential disk IO which again is ~100x faster than random IO. That explains why performance is falling off a cliff.

Rewrite your queries so that the working set of touched pages is smaller. This might involve adding indexes. Or, change the work that is being done over the weekend to touch less data. Or, add RAM. Or, add a cache warming job on 04:00 AM Monday that pulls the data into cache that you rely on by executing representative dummy queries.