wait watchers; gain sql performance increases fast!
TRANSCRIPT
WAIT WATCHERS;
GAIN PERFORMANCE
INCREASES FAST!
Richard Douglas• Sales Engineer, SQL Sentry
• Social Media: @SQLRich, LinkedIn,
• Blog Info: http://blogs.sqlsentry.com/author/RichardDouglas/;
http://SQL.RichardDouglas.co.uk
Tuning blog: http://www.sqlperformance.com/
E-mail [email protected] for free copies of our $10 e-books:
AGENDA
• Introduction
• How and why waits occur
• Looking at and deciphering waits
• Demo
• Q&A
YOUR HOST• Richard Douglas
• Sales Engineer at SQL Sentry
• Blog: http://SQL.RichardDouglas.co.uk
• Twitter: @SQLRich
• Email: [email protected]
• Slides:http://www.Slideshare.net/SQLRich
INTRODUCTIONOnce upon a time we used to check server performance like this:
INTRODUCTIONOnce upon a time we used to check server performance like this:
MOVING ON – PERFORMANCE COUNTERSThen we able to look at resources through performance counters…
INTRODUCING WAIT STATISTICS• In SQL Server 2000 Microsoft introduced a way to look at what it
was waiting for when asking for resources.
• This was improved significantly in 2005 with Dynamic Management Objects.
• In 2008 we could do even more with Extended Events.
• Versions 2012 & 2014 have added more value with more waits to further diagnose issues.
SQL 2000: 78 wait types
SQL 2005: 202 wait types
SQL 2008: 484 wait types
SQL 2008 R2: 490 wait types
SQL 2012: 650 wait types
SQL 2014: 772 wait types
THE WHOLE TRUTH AND NOTHING BUT THE TRUTH?
A BIG problem is that both counters and wait statistics only tell part of a story, unless used together.
My HolidayOBLIGATORY ANALOGY
• Going through Security:
QueueBag
Scan
Body Scan
My HolidayOBLIGATORY ANALOGY
QueueBag
Scan
Ready
Body Scan
• Going through Security:
My HolidayOBLIGATORY ANALOGY
QueueBag
Scan
Processed
Body Scan
• Going through Security:
My HolidayOBLIGATORY ANALOGY
• Going through Security:
QueueBag
Scan
Body Scan
Processed
My HolidayOBLIGATORY ANALOGY
• Going through Security:
QueueBag
Scan
Body Scan
Suspended / Ready
My HolidayOBLIGATORY ANALOGY
• Going through Security:
QueueBag
ScanBody Scan
Processed
My HolidayOBLIGATORY ANALOGY
• Going through Security:
QueueBag
ScanBody Scan
Shopping!
WHY THE SQL OS?• The SQL OS?
SQL runs on Windows that’s an OS what is this guy talking about?
• Windows Server isn’t a highly optimized Operating System by default. It’s designed to allow
development teams to write applications that will run and allow them to compete in their field
of business.
• In other words Microsoft built Windows Server to be stable and available, not to be optimal.
WHY THE SQL OS? (2)• The SQL Server team realized the limitations with a number
of the scheduling routines and decided to write their own scheduling routines which would enhance the performance of SQL Server.
• In 2005 the SQL OS was born.
• Any Dynamic Management Objects that start sys.dm_os_provide an insight into the working of the SQLOS.
• Let’s see how the SQL OS controls requests for CPU time using a simplified example on just one logical processor…
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
55 - Running
Suspended Scheduler 1
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SPID 55
Single SchedulerTHREAD EXECUTION
Running Scheduler 1 Suspended Scheduler 1
55 - PAGEIOLATCH_SH
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SP
ID 6
0
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
60 - Running
Suspended Scheduler 1
55 - PAGEIOLATCH_SH
Runnable Scheduler 1
65 - Runnable
SP
ID 6
5
SP
ID 6
0
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
65 - Running
Suspended Scheduler 1
Runnable Scheduler 1
55 - Runnable
SP
ID 5
5
SP
ID 6
5
VIEWING
WAIT STATISTICS
INFORMATION
VIEWING WAITS• Dynamic Management Views
We will cover a number of these today.
• Extended Events
Not enough time to cover this in any detail today. Contact me at [email protected] if you would like to see a session on this or any other subject.
• Third party tools
We have some great tools, get in touch if you want to know moreat http://www.SQLSentry.com and watch some free training at http://www.SQLSentry.tv
DBCC SQLPERF
“GOIN’ OLD SKOOL” WITH DBCC
• DBCC SQLPERF(waitstats)
• It will show you all possible waits for your edition even if they have not occurred.
• You can also clear down the wait stats information using:
DBCC SQLPERF("sys.dm_os_wait_stats", clear)
Sys.dm_exec_requests
DYNAMIC MANAGEMENT VIEWS
• Wait information
• Task level
• Very accurate
• Transient data
sys.dm_os_wait_stats
DYNAMIC MANAGEMENT VIEWS
• wait_type – The name of the wait type.
• waiting_tasks_count – The number of waits on this wait type.
• wait_time_ms – The total wait time for this wait type in milliseconds, this includes
signal_wait_time.
• max_wait_time_ms – The maximum wait time on this wait type.
• signal_wait_time – The difference between the time the waiting thread was signalled and
when it started running (runnable queue)
• Books Online has a list of descriptions for some of the wait types, worth a look.
Big Warning from Books Online
In SQL Server the wait-time counters are bigint values and therefore are not as prone to counter rollover as the equivalent counters in earlier versions of SQL Server.
Sys.dm_os_waiting_tasks
DYNAMIC MANAGEMENT VIEWS
• Similar to sys.dm_exec_requests in that it returns current information rather than aggregated.
• Will not return info on sessions that are sleeping – they are not waiting!
• Will return records that have no SessionID and are not in sys.dm_exec_requests.
• You will not see SOS_SCHEDULER_YIELD here, it’s not waiting.More on this later…
DECIPHERING
WAIT
INFORMATION
COMMON WAIT TYPESPAGEIOLATCH_*
• Latch on a memory address while data is pulled
from disk
PAGELATCH_*
• Latch on a page in memory
CXPACKET• Query parallelism
Remember you need to correlate wait stats with perfmon counters.
There’s a breakdown of counters and suggested thresholds available in my presentation “The Day After Tomorrow; Why You Need to Baseline”
http://www.SlideShare.net/SQLRich
Not all waits are bad ANALOGY 2
Waiting for elevator
Ready Suspended
Not all waits are bad ANALOGY 2
Waiting for elevator
Processing
Not all waits are bad ANALOGY 2
Waiting for elevator
Stops at other floors Suspended
Not all waits are bad ANALOGY 2
Waiting for elevator
Stops at other floors
Stops at my floor
Processing
• The waits weren’t bad per se.
• There’s only a problem if the combined ready (runnable) and suspended states were greater then the time it would take to walk the stairs.
• If we could remove or reduce the “suspended” waiting time we would experience better performance.
COMMON WAIT TYPES
WRITELOG• Writing transaction log to disk
LCK_M_*• Waiting for a lock
SOS_SCHEDULER_YIELD• Yielding processor time
• See signal wait
(Of Solace) THE QUANTUM• Running tasks will be kicked off the scheduler so other sessions in the Runnable don’t starve
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
55 - Running
Suspended Scheduler 1
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SPID 55
Single SchedulerTHREAD EXECUTION
Running Scheduler 1 Suspended Scheduler 1
55 – PAGEIOLATCH_SH
Runnable Scheduler 1
60 – Runnable
65 - Runnable
SP
ID 6
0
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
60 – Running
Suspended Scheduler 1
55 – PAGEIOLATCH_SH
Runnable Scheduler 1
65 - Runnable
SP
ID 6
5
SP
ID 6
0
Single SchedulerTHREAD EXECUTION
Running Scheduler 1
65 – Running
Suspended Scheduler 1
Runnable Scheduler 1
55 – Runnable
60 – Runnable (SOS_Scheduler_Yield)
SP
ID 5
5
SP
ID 6
5
This happened earlier
THANK YOU!
• Slides will be available at http://Slideshare.net/SQLRich
• More information at:o SQLSkills, et al
• E-mail [email protected] for free copies of our e-books:o Just tell them where you met me
• My contact info for other questions:o [email protected]
o Twitter: @SQLRich
o Blogs: http://SQL.RichardDouglas.co.uk /
http://http://blogs.sqlsentry.com/author/RichardDouglas
SOME GREAT RESOURCES
• SQL Server 2005 Waits and Queues; SQL Server Best Practices Article
• Recommendations and guidelines for the "max degree of parallelism" configuration option in SQL Server - http://support.microsoft.com/kb/2806535
• Books: Professional SQL Server 2008 / 2012 Internals and Troubleshooting
• Books: Microsoft SQL Server 2008 / 2012 Internals