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 ebooks@sqlsentry.com 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: RDouglas@SQLSentry.com
• Slides:
http://www.Slideshare.net/SQLRich
INTRODUCTION
Onceuponatime we usedto checkserver performancelike this:
INTRODUCTION
Onceuponatime we usedto checkserver performancelike this:
MOVING ON – PERFORMANCE COUNTERS
Thenwe abletolookatresources throughperformancecounters…
INTRODUCING WAIT STATISTICS
• In SQLServer2000Microsoftintroducedawaytolookatwhatit
waswaitingforwhen askingforresources.
• This wasimprovedsignificantlyin 2005withDynamic
ManagementObjects.
• In 2008wecoulddo even morewithExtendedEvents.
• Versions 2012& 2014haveaddedmorevalue with morewaits
tofurtherdiagnoseissues.
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 isthatbothcountersandwaitstatisticsonlytell partofa story,unless used together.
My Holiday
OBLIGATORY ANALOGY
• Going throughSecurity:
Queue
Bag
Scan
Body
Scan
My Holiday
OBLIGATORY ANALOGY
Queue
Bag
Scan
Ready
Body
Scan
• Going throughSecurity:
My Holiday
OBLIGATORY ANALOGY
Queue
Bag
Scan
Processed
Body
Scan
• Going throughSecurity:
My Holiday
OBLIGATORY ANALOGY
• Going throughSecurity:
Queue
Bag
Scan
Body
Scan
Processed
My Holiday
OBLIGATORY ANALOGY
• Going throughSecurity:
Queue
Bag
Scan
Body
Scan
Suspended / Ready
My Holiday
OBLIGATORY ANALOGY
• Going throughSecurity:
Queue
Bag
Scan
Body Scan
Processed
My Holiday
OBLIGATORY ANALOGY
• Going throughSecurity:
Queue
Bag
Scan
Body 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 Scheduler
THREAD EXECUTION
Running Scheduler 1
55 - Running
Suspended Scheduler 1
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SPID 55
Single Scheduler
THREAD EXECUTION
Running Scheduler 1 Suspended Scheduler 1
55 - PAGEIOLATCH_SH
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SPID60
Single Scheduler
THREAD EXECUTION
Running Scheduler 1
60 - Running
Suspended Scheduler 1
55 - PAGEIOLATCH_SH
Runnable Scheduler 1
65 - Runnable
SPID65
SPID60
Single Scheduler
THREAD EXECUTION
Running Scheduler 1
65 - Running
Suspended Scheduler 1
Runnable Scheduler 1
55 - Runnable
SPID55
SPID65
VIEWING
WAIT STATISTICS
INFORMATION
VIEWING WAITS
• DynamicManagement Views
Wewill cover anumberofthesetoday.
• ExtendedEvents
Notenough timetocoverthis in anydetail today.Contactme atrdouglas@SQLSentry.comif youwouldlike tosee a sessionon thisor
anyothersubject.
• Thirdpartytools
Wehavesomegreattools,get in touchif youwanttoknowmore
athttp://www.SQLSentry.comandwatchsomefreetrainingathttp://www.SQLSentry.tv
DBCC SQLPERF
“GOIN’ OLD SKOOL” WITH DBCC
• DBCCSQLPERF(waitstats)
• It will showyouall possiblewaitsforyoureditioneven if theyhavenotoccurred.
• Youcanalso cleardownthe waitstatsinformationusing:
DBCCSQLPERF("sys.dm_os_wait_stats",clear)
Sys.dm_exec_requests
DYNAMIC MANAGEMENT VIEWS
• Waitinformation
• Tasklevel
• Veryaccurate
• Transientdata
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
• Similartosys.dm_exec_requestsin thatitreturnscurrentinformationratherthanaggregated.
• Will notreturninfoonsessions thataresleeping –theyarenotwaiting!
• Will returnrecordsthathaveno SessionIDandarenotinsys.dm_exec_requests.
• Youwill notseeSOS_SCHEDULER_YIELDhere, it’s notwaiting.
Moreon thislater…
DECIPHERING
WAIT
INFORMATION
COMMON WAIT TYPES
PAGEIOLATCH_*
• 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
• Runningtaskswill be kicked offthe scheduler soothersessions in theRunnabledon’tstarve
Single Scheduler
THREAD EXECUTION
Running Scheduler 1
55 - Running
Suspended Scheduler 1
Runnable Scheduler 1
60 - Runnable
65 - Runnable
SPID 55
Single Scheduler
THREAD EXECUTION
Running Scheduler 1 Suspended Scheduler 1
55 – PAGEIOLATCH_SH
Runnable Scheduler 1
60 – Runnable
65 - Runnable
SPID60
Single Scheduler
THREAD EXECUTION
Running Scheduler 1
60 – Running
Suspended Scheduler 1
55 – PAGEIOLATCH_SH
Runnable Scheduler 1
65 - Runnable
SPID65
SPID60
Single Scheduler
THREAD EXECUTION
Running Scheduler 1
65 – Running
Suspended Scheduler 1
Runnable Scheduler 1
55 – Runnable
60 – Runnable
(SOS_Scheduler_Yield)
SPID55
SPID65
This happened earlier
THANK YOU!
• Slides will be available at http://Slideshare.net/SQLRich
• More information at:
o SQLSkills, et al
• E-mail ebooks@sqlsentry.com for free copies of our e-books:
o Just tell them where you met me
• My contact info for other questions:
o RDouglas@SQLSentry.com
o Twitter: @SQLRich
o Blogs: http://SQL.RichardDouglas.co.uk /
http://http://blogs.sqlsentry.com/author/RichardDouglas
SOME GREAT RESOURCES
• SQLServer2005Waitsand Queues;SQLServerBest PracticesArticle
• Recommendationsandguidelines forthe "maxdegree of parallelism"configurationoptionin SQL
Server- http://support.microsoft.com/kb/2806535
• Books:ProfessionalSQLServer2008/ 2012 InternalsandTroubleshooting
• Books:MicrosoftSQLServer2008/ 2012 Internals

Wait Watchers ; Gain SQL Performance Increases Fast!

  • 1.
    WAIT WATCHERS; GAIN PERFORMANCE INCREASESFAST! Richard Douglas • Sales Engineer, SQL Sentry • Social Media: @SQLRich, LinkedIn, • Blog Info: http://blogs.sqlsentry.com/author/RichardDouglas/; http://SQL.RichardDouglas.co.uk
  • 2.
    Tuning blog: http://www.sqlperformance.com/ E-mailebooks@sqlsentry.com for free copies of our $10 e-books:
  • 3.
    AGENDA • Introduction • Howand why waits occur • Looking at and deciphering waits • Demo • Q&A
  • 4.
    YOUR HOST • RichardDouglas • Sales Engineer at SQL Sentry • Blog: http://SQL.RichardDouglas.co.uk • Twitter: @SQLRich • Email: RDouglas@SQLSentry.com • Slides: http://www.Slideshare.net/SQLRich
  • 5.
    INTRODUCTION Onceuponatime we usedtocheckserver performancelike this:
  • 6.
    INTRODUCTION Onceuponatime we usedtocheckserver performancelike this:
  • 7.
    MOVING ON –PERFORMANCE COUNTERS Thenwe abletolookatresources throughperformancecounters…
  • 8.
    INTRODUCING WAIT STATISTICS •In SQLServer2000Microsoftintroducedawaytolookatwhatit waswaitingforwhen askingforresources. • This wasimprovedsignificantlyin 2005withDynamic ManagementObjects. • In 2008wecoulddo even morewithExtendedEvents. • Versions 2012& 2014haveaddedmorevalue with morewaits tofurtherdiagnoseissues. 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
  • 9.
    THE WHOLE TRUTHAND NOTHING BUT THE TRUTH? A BIG problem isthatbothcountersandwaitstatisticsonlytell partofa story,unless used together.
  • 10.
    My Holiday OBLIGATORY ANALOGY •Going throughSecurity: Queue Bag Scan Body Scan
  • 11.
  • 12.
  • 13.
    My Holiday OBLIGATORY ANALOGY •Going throughSecurity: Queue Bag Scan Body Scan Processed
  • 14.
    My Holiday OBLIGATORY ANALOGY •Going throughSecurity: Queue Bag Scan Body Scan Suspended / Ready
  • 15.
    My Holiday OBLIGATORY ANALOGY •Going throughSecurity: Queue Bag Scan Body Scan Processed
  • 16.
    My Holiday OBLIGATORY ANALOGY •Going throughSecurity: Queue Bag Scan Body Scan Shopping!
  • 17.
    WHY THE SQLOS? • 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.
  • 18.
    WHY THE SQLOS? (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…
  • 19.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 55 - Running Suspended Scheduler 1 Runnable Scheduler 1 60 - Runnable 65 - Runnable SPID 55
  • 20.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 Suspended Scheduler 1 55 - PAGEIOLATCH_SH Runnable Scheduler 1 60 - Runnable 65 - Runnable SPID60
  • 21.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 60 - Running Suspended Scheduler 1 55 - PAGEIOLATCH_SH Runnable Scheduler 1 65 - Runnable SPID65 SPID60
  • 22.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 65 - Running Suspended Scheduler 1 Runnable Scheduler 1 55 - Runnable SPID55 SPID65
  • 23.
  • 24.
    VIEWING WAITS • DynamicManagementViews Wewill cover anumberofthesetoday. • ExtendedEvents Notenough timetocoverthis in anydetail today.Contactme atrdouglas@SQLSentry.comif youwouldlike tosee a sessionon thisor anyothersubject. • Thirdpartytools Wehavesomegreattools,get in touchif youwanttoknowmore athttp://www.SQLSentry.comandwatchsomefreetrainingathttp://www.SQLSentry.tv
  • 25.
    DBCC SQLPERF “GOIN’ OLDSKOOL” WITH DBCC • DBCCSQLPERF(waitstats) • It will showyouall possiblewaitsforyoureditioneven if theyhavenotoccurred. • Youcanalso cleardownthe waitstatsinformationusing: DBCCSQLPERF("sys.dm_os_wait_stats",clear)
  • 26.
    Sys.dm_exec_requests DYNAMIC MANAGEMENT VIEWS •Waitinformation • Tasklevel • Veryaccurate • Transientdata
  • 27.
    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.
  • 28.
    Sys.dm_os_waiting_tasks DYNAMIC MANAGEMENT VIEWS •Similartosys.dm_exec_requestsin thatitreturnscurrentinformationratherthanaggregated. • Will notreturninfoonsessions thataresleeping –theyarenotwaiting! • Will returnrecordsthathaveno SessionIDandarenotinsys.dm_exec_requests. • Youwill notseeSOS_SCHEDULER_YIELDhere, it’s notwaiting. Moreon thislater…
  • 29.
  • 30.
    COMMON WAIT TYPES PAGEIOLATCH_* •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
  • 31.
    Not all waitsare bad ANALOGY 2 Waiting for elevator Ready Suspended
  • 32.
    Not all waitsare bad ANALOGY 2 Waiting for elevator Processing
  • 33.
    Not all waitsare bad ANALOGY 2 Waiting for elevator Stops at other floors Suspended
  • 34.
    Not all waitsare 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.
  • 35.
    COMMON WAIT TYPES WRITELOG •Writing transaction log to disk LCK_M_* • Waiting for a lock SOS_SCHEDULER_YIELD • Yielding processor time • See signal wait
  • 36.
    (Of Solace) THEQUANTUM • Runningtaskswill be kicked offthe scheduler soothersessions in theRunnabledon’tstarve
  • 37.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 55 - Running Suspended Scheduler 1 Runnable Scheduler 1 60 - Runnable 65 - Runnable SPID 55
  • 38.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 Suspended Scheduler 1 55 – PAGEIOLATCH_SH Runnable Scheduler 1 60 – Runnable 65 - Runnable SPID60
  • 39.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 60 – Running Suspended Scheduler 1 55 – PAGEIOLATCH_SH Runnable Scheduler 1 65 - Runnable SPID65 SPID60
  • 40.
    Single Scheduler THREAD EXECUTION RunningScheduler 1 65 – Running Suspended Scheduler 1 Runnable Scheduler 1 55 – Runnable 60 – Runnable (SOS_Scheduler_Yield) SPID55 SPID65
  • 41.
  • 42.
    THANK YOU! • Slideswill be available at http://Slideshare.net/SQLRich • More information at: o SQLSkills, et al • E-mail ebooks@sqlsentry.com for free copies of our e-books: o Just tell them where you met me • My contact info for other questions: o RDouglas@SQLSentry.com o Twitter: @SQLRich o Blogs: http://SQL.RichardDouglas.co.uk / http://http://blogs.sqlsentry.com/author/RichardDouglas
  • 43.
    SOME GREAT RESOURCES •SQLServer2005Waitsand Queues;SQLServerBest PracticesArticle • Recommendationsandguidelines forthe "maxdegree of parallelism"configurationoptionin SQL Server- http://support.microsoft.com/kb/2806535 • Books:ProfessionalSQLServer2008/ 2012 InternalsandTroubleshooting • Books:MicrosoftSQLServer2008/ 2012 Internals