Friday, 22 February 2013

SQL Performance tuning - Drilling into the problem

Example 1 – A query is slow because the response time is greater than 10 seconds and normally it’s 2 seconds
Example 2  -  Client User requests are queing up and we notice CPU usage at 100% , whereas the normal level is 25%
In Example 1, we’re using the response time  as the unit of measure for the task i.e query
In Example 2 , CPU usage is the unit of measure for the client user requests
Once the problem is quantified in this manner , break the quantities down into smaller parts. It may be session IDs (SPID), execution plan data etc. Each profile has it’s own data requirements. The key message is : attempt to gather performance data matching the problem
Creating the profile at the correct level of detail requires relevant data. SQL Server offers different methods of collecting data e.g DMV, Traces , Custom queries.   It’s important to collect data at the right range. If analysing a problem at a user level , then collect data at the user level.  Strip out  noise.
If analysing a user session resource usage , don’t use  system wide aggregates as your starting point. The main point is to collect relevant data.
At a user level, SQL Server is a collection of sessions (SPID). Nothing occurs without a session. Sessions are used to execute T-SQL statements. During execution of a  T-SQL statement , there is work on the CPU or the session goes idle – either being blocked or waiting for some activity to complete. In other words, different events are contributing to the overall time spent
Identify the SPID of the user complaint. Break the session down and analyse how the time is spent during the session. How is time spent during the session? IO, CPU, Locks , idle :  all use time and contribute to the response time.
 A chronologically ordered breakdown of how the session spends time gives clues for the delays. The delay could be on the network , application , storage etc
 So far , we’ve looked at the user level. What happens  if insufficient data is available ? At this point the DBA collects more data , waiting for a reoccurrence.
Developing a systematic and objective approach to SQL performance troubleshooting is key to fixing problems. Avoid relying on luck and focus on the facts.

#youmightbeaDBA


Your two main enemies are developers and SAN admins #youmightbeaDBA

When your girlfriend has to lean around the laptop to kiss you goodnight #youmightbeadba

You always plan an exit strategy, even when entering a McDonald's #youmightbeaDBA 

You can't explain to your family what you really do for a living #youmightbeaDBA 

You have at least one set of scripts you won't share #youmightbeaDBA 

You and the Oracle DBA would happily fight off a developer together #youmightbeaDBA 

You've sent a vendor suggestions on improving their database design or code (and been ignored) #youmightbeaDBA 

You've sent a vendor suggestions on improving their database design or code (and been ignored) #youmightbeaDBA 

You refer to clothes as "Data Abstractions" #youmightbeaDBA 

Your girlfriend knows what "ETL" means #youmightbeaDBA 

You check your server logs before you check your e-mail in the morning so you can reply "Yeah, I already fixed that." #youmightbeaDBA 

You can convince a boss that you need 16GB of RAM in your laptop #youmightbeaDBA 

You call cigarettes "work vitamins" #youmightbeaDBA 

You've tried to convince someone else to become a DBA #youmightbeaDBA 

You call texting a "queuing system" #youmightbeaDBA 

You have an e-mail rule for backup notifications #youmightbeaDBA 

You would pay money for a license plate that has the letters S-Q-L together #youmightbeaDBA 

You have actually considered making a RAID array from thumb drives #youmightbeaDBA 

You've written blog posts on technology you've never actually implemented in production #youmightbeaDBA 

Your blog would make a "best practices" or "worst practices" book #youmightbeaDBA 

The first thing you install on your netbook is SSMS #youmightbeaDBA 

You tell people that you made a database query go faster, and expect them to be happy for you #youmightbeaDBA 

You take the word "NoSQL" as a personal attack #youmightbeaDBA 

You think that something OTHER than the database might be the performance bottleneck #youmightbeaDBA 

You refer to time as a "Clustered Index" #youmightbeaDBA 

You think a millisecond is a really long time #youmightbeaDBA 

You think "Set theory" is not an verb but a noun #youmightbeaDBA

You don't like Oracle, and not just because of what she did to Neo #youmightbeaDBA 

You know when to say "sequel" and "s-q-l" #youmightbeaDBA 

Holiday == "Maintenance Window" #youmightbeaDBA

You cringe in public when the word "upgrade" is used in a sentence #youmightbeaDBA 

When someone tells you they are going to take a dump and you wonder of which database then #youmightbeaDBA 

When it's 11pm on a holiday weekend and you are working #youmightbeaDBA 

When getting milk from the fridge you check the expiry date is > getdate() #youmightbeaDBA 

Your friends don't understand why you think there's a difference between single and double quotes #youmightbeaDBA 

The thought of disrupting 500 people's work so you can do something doesn't phase you #youmightbeaDBA

Your home computer is backed up in 2 different places #youmightbeaDBA 

If you have ever set up a SQLAgent job to email your mobile phone to serve as an alarm clock #youmightbeaDBA 

The late-night security guard knows the names of your town. #youmightbeaDBA 

You have edited a data file by hand, just to see what would happen. #youmightbeaDBA 

You've built programs that access data just to keep other developers from asking you to run queries all the time. #youmightbeaDBA 

You have memorized the names of several of the AdventureWorks employees. #youmightbeaDBA 

When the waiter says he'll be your server today, you ask how many terabytes he is #youmightbeaDBA 

hmmm... #youmightbeaDBA if your recipe for dinner is "SELECT * FROM Refrigerator" 

If you're up at midnight commenting about SQL #youmightbeaDBA 

I'd noticed that. :) #youmightbeaDBA 

when people talk about "their type" you're thinking varchar, bigint, binary, etc #youmightbeadba 

Someone asks you to throw another log on the fire and you tell them not to worry about it because Autogrowth is turned on #youmightbeaDBA 

you google to trouble shoot a problem and end up at your own blog (and it fixes it) #youmightbeaDBA

You list TSQL as your native language on the 2010 census. #youmightbeaDBA 

You're sitting and typing #youmightbeaDBA when you could be outside #youmightbeaDBA