Query Response time keeps changing

Hello,

Question 1:I have this read only database against which I'm running couple of queries to record their response time.
Inspite of data being static and execution plan being the same, the response time keeps varying a lot.

When I run the query immediatedly after restarting my sql server, I get 3453ms, I shut down the sql server service, restarted after sometime, and reran the query. The second time, the response time is 8399ms.

Even without restarting sql server service, the response time of same query differs between each time the query is executed.

How to baseline the response time?
What is going on?
Is there a reason for this?

Question 2:
Also, based on the first response time of 3453ms, I tuned the queries by
- Adding additional indexes
- Replaced some queries with indexed views
- Made the index fill factor as 100% as the table is a read-only table and the data is refreshed only once a month.
- Made the database itself as Read-only
- Gathered STATS

After doing all this query response time went down to around 2075ms.
But when I tried the same set of queries after two days, and the response time went up to 5451ms.
Nothing changed in between.

What is the reason behind this?
How to baseline if the results are so inconsistent?

Thanks.
sath350163Asked:
Who is Participating?
 
DBAduck - Ben MillerConnect With a Mentor Principal ConsultantCommented:
One other thing to note.  Some databases that are created in SQL Server Express have Auto-Close turned on.  When you have that setting turned on for the database, when the last connection exits, the SQL Server engine will close the database.  When the next connection requests that database, it will open the database and the response times could vary each time.

So you are running into Cache issues as well as potentially the Auto-close problem as well.  Check your database settings in Properties.  Or look at the SQL Server Error logs to see what is going on in the SQL Server that could also be impacting things.
0
 
sath350163Author Commented:
Forgot to mention that I'm running SQL SERVER 2008 EXPRESS EDITION in Windows 7 operating system.
0
 
Anthony PerkinsCommented:
>>Is there a reason for this? <<
In a word cache.

>>How to baseline the response time? <<
Clear the cache and make sure stats are updated.

>>Nothing changed in between.<<
Sure it did.  To be precise 48 hours happened.

>>What is the reason behind this?
How to baseline if the results are so inconsistent?
See responses to question 1.
0
 
VENKAT KOKULLASQL Server DBACommented:
It's not only for yours, max of the users are having same kind of issues. The response time is going to varie with in a showt time even, the reason for this is mainly depend on the back end processes running in OS level (and also might there will be changes in sql settings if any) will also leads to variation in response time.

Frequently update statisctics and re-indexing will give the best results.

Find out if any blockings are happening on the SQL backend and monitoring the disk space and the number os sessions running will also give us huge difference in response time.

As you mentioned the response time has been varied after few days even after making necessary changes to the query; This will due to statistics has been not updated might there will be inserts and deleted happened in the database level which will surely shows a variation in query O\P.

The below link might help you:
http://msdn.microsoft.com/en-us/library/ms172984(v=sql.100).aspx
0
 
SleepydogCommented:
Looking at graphical execution plan may be helpful determining why your query is slow. It will show where the bulk of the query time is being used (joins  index scans, sorts, etc).

Take a look at your query as well, can you modify it and get better performance?  

Can you break your query, loading some results into temp local tables, then use those in a latter part of your query?
0
All Courses

From novice to tech pro — start learning today.