WHAT ARE YOU   Jason Strate
               Database Architect
               Pragmatic Works, Inc.



WAITING FOR?
WHAT ARE YOU WAITING FOR?

You…
SQL Server
Developers
DBAs
AGENDA

Defining   Viewing   Collecting   Reviewing
AGENDA            Defining




Defining   Viewing   Collecting   Reviewing
WAIT, WAIT… I’LL TELL YOU


Waits & Queues Methodology
SO WHAT?!
WAIT STATISTICS



        Identity



Prioritize    Measure
EXECUTION MODEL (SIMPLIFIED)

Grocery Store
 Cashier
   Scheduler
 Customer
   Query
 Checkout Line
   Queue
     Running
     Runnable
     Suspended
EXECUTION MODEL (SIMPLIFIED)

                RUNNING
EXECUTION MODEL (SIMPLIFIED)

  RUNNABLE      RUNNING
EXECUTION MODEL (SIMPLIFIED)

  RUNNABLE          RUNNING




             WAIT



                    SUSPENDED
EXECUTION MODEL (SIMPLIFIED)

  RUNNABLE      RUNNING




                SUSPENDED
EXECUTION MODEL (SIMPLIFIED)

   RUNNABLE     RUNNING




WAIT TIME
                SUSPENDED
EXECUTION MODEL (SIMPLIFIED)

  RUNNABLE      RUNNING




                SUSPENDED
EXECUTION MODEL (SIMPLIFIED)

  RUNNABLE      RUNNING




                SUSPENDED
EXECUTION MODEL (SIMPLIFIED)

       RUNNABLE   RUNNING




SIGNAL WAIT       SUSPENDED
   TIME
AGENDA            Viewing




Defining   Viewing   Collecting   Reviewing
WAIT DMVS

 sys.dm_os_wait_stats
   Accumulated statistics on tasks that have waited for resources
 sys.dm_os_waiting_tasks
   Information on queued tasks waiting for resources
WAITS STATS
WAITS STATS

 Name of the wait type.
WAITS STATS
Number of waits on this wait type. This counter is
    incremented at the start of each wait.
WAITS STATS
Total wait time for this wait type in milliseconds. This
      time is inclusive of signal_wait_time_ms.
WAITS STATS

Maximum wait time on this wait type.
WAITS STATS
Difference between the time that the waiting thread
     was signaled and when it started running.
WAITING TASKS
WAITING TASKS
WAITING TASKS




ID of the session associated with the task.
WAITING TASKS




Total wait time for this wait type, in milliseconds. This
        time is inclusive of signal_wait_time.
WAITING TASKS




  Name of the wait type.
WAITING TASKS


ID of the session that is blocking the request. If this
 column is NULL, the request is not blocked, or the
 session information of the blocking session is not
                      available
WAITING TASKS




Difference between the time that the waiting thread
     was signaled and when it started running.
VIEWING WAIT STATS   Demo
AGENDA            Collecting




Defining   Viewing   Collecting   Reviewing
DMV STATS
MANAGEMENT DATA WAREHOUSE
DO-IT-YOURSELF




Collect     Summarize      Analyze
DO-IT-YOURSELF   Demo
AGENDA            Reviewing




Defining   Viewing   Collecting   Reviewing
WAIT T YPES

 Tied to process
     Audit
     Buffer
     I/O
     Indexing
     Lock
     SQLOS
 Categories
   Background
   External
   Queue
BACKGROUND WAITS


CLR_SEMAPHORE      CHECKPOINT_QUEUE
LAZYWRITER_SLEEP   XE_TIMER_EVENT
RESOURCE_QUEUE     BROKER_TO_FLUSH
        Not all inclusive
SLEEP_TASK         BROKER_TASK_STOP
SLEEP_SYSTEMTASK   CLR_MANUAL_EVENT
WAITFOR            CLR_AUTO_EVENT
LOGMGR_QUEUE       XE_DISPATCHER_WAIT
CXPACKET

Translation

•Contention with queries the at are executing in parallel; across multiple CPUs.
 Generally due to unbalanced execution across CPUs or tasks ahead of query
 executing longer than expected.

Guideline

•>5% for OLTP
•>10% for data warehouses

Resolution

•Review indexing
•Tune queries
•Adjust Max Degree of parallelism
•Research cost threshold for parallelism
OLEDB

Translation

• Occurs when SQL Server calls the Microsoft SQL Native Client OLE DB
  Provider. It indicates the duration of calls to the OLE DB provider.

Guideline

• Examine when it is a top wait and exceeds background waits. (TOP 5)

Resolution

• Identify queries with OLE DB waits with extended events or
  sys.dm_os_waiting_tasks
• Check application placement and Disk secs/Read and Disk secs/Write
• Tune transactions using RPC, Distributed (Linked Server), and Full Text
  Search
PAGEIOLATCH_X

Translation

• Contention caused by disk to memory transfer. Typically suggests disk IO
  subsystem issues.

Guideline

• Examine when it is a top wait and exceeds background waits. (TOP 5)

Resolution

• Review Physical disk: disk seconds/read and Physical disk: disk
  seconds/write and SQL Server Buffer Manager: Page Life Expectancy
• Review information for virtual file stats
• Reconfigure disk to improve IO throughput
• Analyze indexes to reduce need to move data to memory
• Increase memory to increase data available to SQL Server
PAGELATCH_X

Translation

• Contention between short term light weight synchronization objects.
  Latches are not held for the duration of a transaction. Occur in the
  buffer pool but unrelated to IO requests.

Guideline

• Examine when it is a top wait and exceeds background waits. (TOP 5)

Resolution

• Check tempdb configuration
  • Additional data files
  • Trace Flag 1118
• Troubleshoot memory pressure
LATCH_X

Translation

• Contention between short term light weight synchronization objects.
  Latches are not held for the duration of a transaction. Non buffer
  pool related.

Guideline

• Examine when it is a top wait and exceeds background waits. (TOP 5)

Resolution

• Review T-SQL generating LATCH waits using extended events.
• Examine memory items in sys.dm_os_latch_stats
• Partition table across multiple files
SQL SERVER MVP DEEP DIVES, VOLUME 2




                  www.operationsmile.org
                  www.manning.com/delaney
RESOURCES

Jason       e: jstrate@pragmaticworks.com
Strate
            e: jasonstrate@gmail.com
            b: www.jasonstrate.com
            t: StrateSQL
Resources   jasonstrate.com/go/Waits2013/

What are you waiting for? (#SQLSat211)

  • 1.
    WHAT ARE YOU Jason Strate Database Architect Pragmatic Works, Inc. WAITING FOR?
  • 2.
    WHAT ARE YOUWAITING FOR? You… SQL Server Developers DBAs
  • 3.
    AGENDA Defining Viewing Collecting Reviewing
  • 4.
    AGENDA Defining Defining Viewing Collecting Reviewing
  • 5.
    WAIT, WAIT… I’LLTELL YOU Waits & Queues Methodology
  • 6.
  • 7.
    WAIT STATISTICS Identity Prioritize Measure
  • 8.
    EXECUTION MODEL (SIMPLIFIED) GroceryStore  Cashier  Scheduler  Customer  Query  Checkout Line  Queue  Running  Runnable  Suspended
  • 9.
  • 10.
  • 11.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING WAIT SUSPENDED
  • 12.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING SUSPENDED
  • 13.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING WAIT TIME SUSPENDED
  • 14.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING SUSPENDED
  • 15.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING SUSPENDED
  • 16.
    EXECUTION MODEL (SIMPLIFIED) RUNNABLE RUNNING SIGNAL WAIT SUSPENDED TIME
  • 17.
    AGENDA Viewing Defining Viewing Collecting Reviewing
  • 18.
    WAIT DMVS  sys.dm_os_wait_stats  Accumulated statistics on tasks that have waited for resources  sys.dm_os_waiting_tasks  Information on queued tasks waiting for resources
  • 19.
  • 20.
    WAITS STATS Nameof the wait type.
  • 21.
    WAITS STATS Number ofwaits on this wait type. This counter is incremented at the start of each wait.
  • 22.
    WAITS STATS Total waittime for this wait type in milliseconds. This time is inclusive of signal_wait_time_ms.
  • 23.
    WAITS STATS Maximum waittime on this wait type.
  • 24.
    WAITS STATS Difference betweenthe time that the waiting thread was signaled and when it started running.
  • 25.
  • 26.
  • 27.
    WAITING TASKS ID ofthe session associated with the task.
  • 28.
    WAITING TASKS Total waittime for this wait type, in milliseconds. This time is inclusive of signal_wait_time.
  • 29.
    WAITING TASKS Name of the wait type.
  • 30.
    WAITING TASKS ID ofthe session that is blocking the request. If this column is NULL, the request is not blocked, or the session information of the blocking session is not available
  • 31.
    WAITING TASKS Difference betweenthe time that the waiting thread was signaled and when it started running.
  • 32.
  • 33.
    AGENDA Collecting Defining Viewing Collecting Reviewing
  • 34.
  • 35.
  • 36.
    DO-IT-YOURSELF Collect Summarize Analyze
  • 37.
  • 38.
    AGENDA Reviewing Defining Viewing Collecting Reviewing
  • 39.
    WAIT T YPES Tied to process  Audit  Buffer  I/O  Indexing  Lock  SQLOS  Categories  Background  External  Queue
  • 40.
    BACKGROUND WAITS CLR_SEMAPHORE CHECKPOINT_QUEUE LAZYWRITER_SLEEP XE_TIMER_EVENT RESOURCE_QUEUE BROKER_TO_FLUSH Not all inclusive SLEEP_TASK BROKER_TASK_STOP SLEEP_SYSTEMTASK CLR_MANUAL_EVENT WAITFOR CLR_AUTO_EVENT LOGMGR_QUEUE XE_DISPATCHER_WAIT
  • 41.
    CXPACKET Translation •Contention with queriesthe at are executing in parallel; across multiple CPUs. Generally due to unbalanced execution across CPUs or tasks ahead of query executing longer than expected. Guideline •>5% for OLTP •>10% for data warehouses Resolution •Review indexing •Tune queries •Adjust Max Degree of parallelism •Research cost threshold for parallelism
  • 42.
    OLEDB Translation • Occurs whenSQL Server calls the Microsoft SQL Native Client OLE DB Provider. It indicates the duration of calls to the OLE DB provider. Guideline • Examine when it is a top wait and exceeds background waits. (TOP 5) Resolution • Identify queries with OLE DB waits with extended events or sys.dm_os_waiting_tasks • Check application placement and Disk secs/Read and Disk secs/Write • Tune transactions using RPC, Distributed (Linked Server), and Full Text Search
  • 43.
    PAGEIOLATCH_X Translation • Contention causedby disk to memory transfer. Typically suggests disk IO subsystem issues. Guideline • Examine when it is a top wait and exceeds background waits. (TOP 5) Resolution • Review Physical disk: disk seconds/read and Physical disk: disk seconds/write and SQL Server Buffer Manager: Page Life Expectancy • Review information for virtual file stats • Reconfigure disk to improve IO throughput • Analyze indexes to reduce need to move data to memory • Increase memory to increase data available to SQL Server
  • 44.
    PAGELATCH_X Translation • Contention betweenshort term light weight synchronization objects. Latches are not held for the duration of a transaction. Occur in the buffer pool but unrelated to IO requests. Guideline • Examine when it is a top wait and exceeds background waits. (TOP 5) Resolution • Check tempdb configuration • Additional data files • Trace Flag 1118 • Troubleshoot memory pressure
  • 45.
    LATCH_X Translation • Contention betweenshort term light weight synchronization objects. Latches are not held for the duration of a transaction. Non buffer pool related. Guideline • Examine when it is a top wait and exceeds background waits. (TOP 5) Resolution • Review T-SQL generating LATCH waits using extended events. • Examine memory items in sys.dm_os_latch_stats • Partition table across multiple files
  • 46.
    SQL SERVER MVPDEEP DIVES, VOLUME 2  www.operationsmile.org  www.manning.com/delaney
  • 47.
    RESOURCES Jason e: jstrate@pragmaticworks.com Strate e: jasonstrate@gmail.com b: www.jasonstrate.com t: StrateSQL Resources jasonstrate.com/go/Waits2013/