Wait States SQL 2005 8
Wait States SQL 2005 8
Neuss, Germany
w w w. s q l p a s s . o r g / e u 2 0 1 0
Welcome to My World
DMVs,
Code, Debugger, and APIs
We created this to help us find bottlenecks In a galaxy, far, far, away we had locks, I/O and network But as time has moved on we went a bit overboard The name of the type is up to the developer
485 in SQL Server 2008 Resource Synchronization Forced External
I/O, Network, Thread, Memory Locks, Latches, and bunch of others Yield or Sleep
Preemption
Background tasks
Queue
A conflict exists
Call LockOwner::Sleep
last_wait_type explained
Last wait type used to be stored with session Now stored with the worker Only valid while worker bound to task
true last wait type when task is still running but not waiting
Good example is SOS_SCHEDULER_YIELD
LCK_XX
Resource
ASYNC_NETWORK_IO
Hint: Network or your app
Queue Waits
CLR_AUTO_EVENT
Inside SQL Server Wait Types
Which one is not CXPACKET? Some other wait may be the issue
Sync
sys.dm_os_latch_stats sys.dm_exec_requests.wait_resource
FGCB_ADD_REMOVE Latch
SQL Server Engine
INSERT Need space INSERT Need space Need space Need space
LATCH_SH: FGCB_ADD_REMOVE
Sync
FGCB
Autogrow
mydb.mdf
INSERT
INSERT
Moral of the story: Use instant file initialization butit doesnt work for the tlog
SOS_SCHEDULER_YIELD
I/O, Lock, Latch Forced
A task that does not naturally wait must yield When quantum of 4ms is exceeded What if we dont do this right?
************************ * * BEGIN STACK DUMP: * 10/17/09 15:51:52 spid 0 * * Non-yielding Scheduler * ************************
Examples
No I/O needed for pages T-SQL variables only or just expressions Query compile Small hashes and sorts
Indicators
High count/low wait this is actually good High count/High wait CPU queries competing Low count/High wait someone not yielding or preemptive threads hogging CPU
THREADPOOL
Applies to any task TDS Login
Receive TDS packet Engine creates SQLOS Task
Resource
Login Timeout
Often a long blocking chain DO NOT assume you need more worker threads
Mylog.ldf
INSERT
Log Cache
All buffers in use
Page I/O
DISKIO_SUSPEND
ASYNC_IO_COMPLETION
Engine Workers
Resource
compiles
RESOURCE_SEMAPHORE_ QUERY_COMPILE
Pre-Emptive Waits
Workers go pre-emptive when calling external APIs that may take some time
External
************************ * * BEGIN STACK DUMP: * 10/17/09 15:51:52 spid 0 * * Non-yielding Scheduler * ************************
PREEMPTIVE_OS_GETPROCADDRESS
Wraps calls to GetProcAddress() and xproc function Wraps calls to WriteFileGather() to zero out a section of a file Wrapped calls to LookupAccountSid()
PREEMPTIVE_OS_WRITEFILEGATHER
Long autogrow for tlog file or database files (if not using instant file init) Mostly used during login authentication. Long waits could indicate DC issues. Helps fill in gaps where OLEDB wait not set.
PREEMPTIVE_OS_LOOKUPACCOUNTSID
PREEMPTIVE_OLEDBOPS
Wrapped around various code fragments that will call OLE-DB methods for linked server queries.. Wrapped around WaitForSingleObject() calls in network I/O and waiting for recovery to complete
PREEMPTIVE_OS_WAITFORSINGLEOBJECT
wait_type
Normal waits
Preemptive waits
opcode
Timings
Get query, session, or stack dump On by Default System_Health Session Has These SQLCAT Waits Stats Per Session Project
Inside SQL Server Wait Types
The plan
Post new findings on this blog post Comment on the blog or send email to [email protected] Use the blog to update the BOL Blog may contain scenarios and more details
Resources
Our CSS Escalation Blog The Wait Type Repository Blog Post BOL reference on sys.dm_os_wait_stats SQLCAT Waits Stats Per Session CodePlex Craig Freedman blog posts on Parallelism CLR Wait Types blog post SQL Server 2005 Waits and Queues Whitepaper The System_Health XEvent Session Blog
Questions
Appendix
Anyone querying the DMVS sees the wait type and accumulated wait time
Resource
External
Sync
CMEMTHREAD
Thread synchronization for memory allocation High wait times = A likely bug
backoffs in sys.dm_os_spinlock_stats
Thank you!