wait watchers; gain sql performance increases fast!

43
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

Upload: richard-douglas

Post on 17-Jul-2015

131 views

Category:

Technology


0 download

TRANSCRIPT

Page 2: Wait Watchers; Gain SQL Performance Increases Fast!

Tuning blog: http://www.sqlperformance.com/

E-mail [email protected] for free copies of our $10 e-books:

Page 3: Wait Watchers; Gain SQL Performance Increases Fast!

AGENDA

• Introduction

• How and why waits occur

• Looking at and deciphering waits

• Demo

• Q&A

Page 4: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 5: Wait Watchers; Gain SQL Performance Increases Fast!

INTRODUCTIONOnce upon a time we used to check server performance like this:

Page 6: Wait Watchers; Gain SQL Performance Increases Fast!

INTRODUCTIONOnce upon a time we used to check server performance like this:

Page 7: Wait Watchers; Gain SQL Performance Increases Fast!

MOVING ON – PERFORMANCE COUNTERSThen we able to look at resources through performance counters…

Page 8: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 9: Wait Watchers; Gain SQL Performance Increases Fast!

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.

Page 10: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

• Going through Security:

QueueBag

Scan

Body Scan

Page 11: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

QueueBag

Scan

Ready

Body Scan

• Going through Security:

Page 12: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

QueueBag

Scan

Processed

Body Scan

• Going through Security:

Page 13: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

• Going through Security:

QueueBag

Scan

Body Scan

Processed

Page 14: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

• Going through Security:

QueueBag

Scan

Body Scan

Suspended / Ready

Page 15: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

• Going through Security:

QueueBag

ScanBody Scan

Processed

Page 16: Wait Watchers; Gain SQL Performance Increases Fast!

My HolidayOBLIGATORY ANALOGY

• Going through Security:

QueueBag

ScanBody Scan

Shopping!

Page 17: Wait Watchers; Gain SQL Performance Increases Fast!

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.

Page 18: Wait Watchers; Gain SQL Performance Increases Fast!

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…

Page 19: Wait Watchers; Gain SQL Performance Increases Fast!

Single SchedulerTHREAD EXECUTION

Running Scheduler 1

55 - Running

Suspended Scheduler 1

Runnable Scheduler 1

60 - Runnable

65 - Runnable

SPID 55

Page 20: Wait Watchers; Gain SQL Performance Increases Fast!

Single SchedulerTHREAD EXECUTION

Running Scheduler 1 Suspended Scheduler 1

55 - PAGEIOLATCH_SH

Runnable Scheduler 1

60 - Runnable

65 - Runnable

SP

ID 6

0

Page 21: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 22: Wait Watchers; Gain SQL Performance Increases Fast!

Single SchedulerTHREAD EXECUTION

Running Scheduler 1

65 - Running

Suspended Scheduler 1

Runnable Scheduler 1

55 - Runnable

SP

ID 5

5

SP

ID 6

5

Page 23: Wait Watchers; Gain SQL Performance Increases Fast!

VIEWING

WAIT STATISTICS

INFORMATION

Page 24: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 25: Wait Watchers; Gain SQL Performance Increases Fast!

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)

Page 26: Wait Watchers; Gain SQL Performance Increases Fast!

Sys.dm_exec_requests

DYNAMIC MANAGEMENT VIEWS

• Wait information

• Task level

• Very accurate

• Transient data

Page 27: Wait Watchers; Gain SQL Performance Increases Fast!

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.

Page 28: Wait Watchers; Gain SQL Performance Increases Fast!

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…

Page 29: Wait Watchers; Gain SQL Performance Increases Fast!

DECIPHERING

WAIT

INFORMATION

Page 30: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 31: Wait Watchers; Gain SQL Performance Increases Fast!

Not all waits are bad ANALOGY 2

Waiting for elevator

Ready Suspended

Page 32: Wait Watchers; Gain SQL Performance Increases Fast!

Not all waits are bad ANALOGY 2

Waiting for elevator

Processing

Page 33: Wait Watchers; Gain SQL Performance Increases Fast!

Not all waits are bad ANALOGY 2

Waiting for elevator

Stops at other floors Suspended

Page 34: Wait Watchers; Gain SQL Performance Increases Fast!

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.

Page 35: Wait Watchers; Gain SQL Performance Increases Fast!

COMMON WAIT TYPES

WRITELOG• Writing transaction log to disk

LCK_M_*• Waiting for a lock

SOS_SCHEDULER_YIELD• Yielding processor time

• See signal wait

Page 36: Wait Watchers; Gain SQL Performance Increases Fast!

(Of Solace) THE QUANTUM• Running tasks will be kicked off the scheduler so other sessions in the Runnable don’t starve

Page 37: Wait Watchers; Gain SQL Performance Increases Fast!

Single SchedulerTHREAD EXECUTION

Running Scheduler 1

55 - Running

Suspended Scheduler 1

Runnable Scheduler 1

60 - Runnable

65 - Runnable

SPID 55

Page 38: Wait Watchers; Gain SQL Performance Increases Fast!

Single SchedulerTHREAD EXECUTION

Running Scheduler 1 Suspended Scheduler 1

55 – PAGEIOLATCH_SH

Runnable Scheduler 1

60 – Runnable

65 - Runnable

SP

ID 6

0

Page 39: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 40: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 41: Wait Watchers; Gain SQL Performance Increases Fast!

This happened earlier

Page 42: Wait Watchers; Gain SQL Performance Increases Fast!

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

Page 43: Wait Watchers; Gain SQL Performance Increases Fast!

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