Solved

Query Response time keeps changing

Posted on 2011-09-21
5
355 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:sath350163
5 Comments
 

Author Comment

by:sath350163
ID: 36577541
Forgot to mention that I'm running SQL SERVER 2008 EXPRESS EDITION in Windows 7 operating system.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36577607
>>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
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 250 total points
ID: 36577837
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
 
LVL 5

Expert Comment

by:VENKAT KOKULLA
ID: 36578782
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
 
LVL 1

Expert Comment

by:Sleepydog
ID: 36578881
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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question