Set Title in 40pt. No more than 2 lines

Set Title in 40pt. No more than 2 lines

Inside SQL Server Wait Types Bob Ward Microsoft Corporation SQL 2005 and SQL 2005 and SQL 2008 SQL 2008 Microsoft CSS at PASS 2009 Pre-Conference Seminar Tackling Top Reporting Services Issues Mon 11/2 8:30am-4:30pm Adam Saxton Main Conference Talks (DBA-500-SC) Inside SQL Server Wait Types Tues 11/3 10:15 11:45am 3AB Bob Ward SQL Server Clinic Room 611 11/3 11/5/2009 After Keynote 6:00pmish (DBA-X69-C) Implementing and Supporting SQL 2008 Failover Clustering Tues 11/3 1:30-2:45pm 4C1-2

Shon Hauck (BIA-X45-C) Top customer support issues in Analysis Services Wed 11/4 1:30-2:45pm 2AB John Sirmon (AD-X43-C ) Troubleshooting applications accessing SQL Server Thurs 11/5 1:00-2:15pm 613-614 Abirami Iyer and Lakshmi Jonnakuti 2 3 All scripts will be available Stay for questions as Stuff you can use long as you want This means your brain may hurt =

We will move DMVs, Code, fast and Debugger, and furious APIs I assume SQL knowledge This is a 500 level talk Welcome to My World What is a wait type? Not the best Not the best of docs of docs 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 485 in SQL Server 2008 The name of the type is up to the developer Background tasks

Queue Preemption External Yield or Sleep Forced Locks, Latches, and bunch of others Synchronization I/O, Network, Thread, Memory Resource 4 How does a wait type work? Developer writes code that runs Anyone querying the DMVS sees the wait type and accumulated wait time Code is signaled to

wake-up Developer knows they might execute code that waits Code saves last wait type Code clears wait type, time, and last wait type Developer sets a wait type Developer calls SQLOS routines to wait 5 Lets look at an example Common for a Common for a SELECT SELECT Request LCK_M_IS (Shared Intent) lock

Understands SQLOS scheduling Wait() results in SignalObjectAndWait() We know we need to wait A conflict exists Setup a SOS_WaitInfo with LCK_M_IS Use SOS_EventAuto class to wait Call LockOwner::Sleep Ultimately it always comes down to WaitForSingleObject() or SignalObjectAndWait() SOS_EventAuto is a SOS_EventAuto is a wrapper for Windows wrapper

forEvent Windows Kernel object Kernel Event object 6 Where do wait types show up? sys.dm_os_wait_stats sys.dm_exec_requests sys.dm_os_waiting_tasks sys.sysprocesses Extended Events Management Data Warehouse Activity Monitor Performance Monitor Counters Historical stats Historical stats Live state Live state legacy legacy Tracing in 2008 Tracing in 2008 In the tools In the tools Wait Statistics Wait Statistics Counter Counter

7 Dive into Wait Types 8 Common Wait Types Hint: Your app Locks sync LCK_XX Hint: System table or allocation BUF latch - sync PAGELATCH and PAGEIOLATCH Hint: I/ O delay Andrew Kellys talk on Capturing and Analyzing File & Wait Stats Resource

Make up ~50 of the wait types ASYNC_NETWORK_IO Hint: Network or your app 9 Some Waits may not be bottlenecks MISCELLANEOUS Should be called not Should be called not waiting waiting Background Task Waits LAZYWRITER_SLEEP BOL calls these BOL calls these SQLTRACE_BUFFER_FLUSH Queue Waits Queue Waits CHECKPOINT_QUEUE

REQUEST_FOR_DEADLOCK_SEARCH CLR_AUTO_EVENT Normal for SQL Normal for SQL CLR CLR 10 Busting the Myth of CXPACKET Craig Freedman Talk Craig Freedman Talk is a must read is a must read Used to synchronize parallel query workers Just means you have a parallel query Do you expect parallel queries? Do you have high wait times? wait_resource shows coordination Sync

High wait times mean long running parallel queries What Should I Do? Look at the Tasks You may not need to do anything Which one is not CXPACKET? Some other wait may be the issue Find queries and tune them Use the MAXDOP query hint Modify max degree of parallelism Dont jump to these 11 12 sys.dm_os_latch_stats sys.dm_exec_requests.wait_resource

Latch class Same modes as BUFs (KP, SH, UP, EX, DT) As opposed to PAGELATCH or PAGEIOLATCH Not just for BUFs Thread sync of memory structure How many are there? Appears as LATCH_XX Latch can be generic The non BUFFER Latch Sync FGCB_ADD_REMOVE latch Sync SQL Server Engine INSERT Need space INSERT


Moral of the Moral of the story: Use story: Use instant file initi instant file initi alization alization butit doesnt butit doesnt work for the work for the tlog tlog 13 SOS_SCHEDULER_YIELD Forced I/O, Lock, Latch A task that does not naturally wait must yield

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 CPU intensive query High wait time CPU intensive queries competing or someone not yielding very well Could be

Could be preemptive preemptive thread(s) thread(s) 14 THREADPOOL Resource Applies to any task TDS Login Receive TDS packet Engine creates SQLOS Task Find available worker on scheduler If none, set THREADPOOL wait type Next available worker runs

task Login Timeout These are pure victims Only seen in stats and tasks Request Request = task + = task + worker worker You may need DAC to see it live PENDING tasks and work_queue_count in schedulers > 0 Look for other waits Often a long blocking chain DO NOT assume you need more worker threads 15 What about I/O Waits?

COMMIT COMMIT TRAN TRAN INSERT INSERT Copy model SQLTrace File Sort I/O Create database files Zero Log Files Sync Flush Log Buffer Log Writer WRITELOG LOGBUFFER Request Log Buffer Resource IO_COMPLETION File ASYNC_IO_COMPLETION Resource Log Log

Buffer Buffer Log Cache Mylog.ldf All buffers in use Resource Page I/O Mylog.ldf and .mdf DISKIO_SUSPEND Engine Workers VDI App BACKUP WITH SNAPSHOT Backup Sync media 16

17 Why are you compiling so much? Factor of limited memory or memory hungry compiles Throttled on a system of levels (gateways) with thresholds High Query Memory lowers thresholds Not often seen on 64bit systems sys.dm_os_memory_brokers sys.dm_os_memory_brokers DBCC MEMORYSTATUS DBCC MEMORYSTATUS Limited memory or too many concurrent users MEMORYCLERK_SQLQUERYEXEC and MEMORYCLERK_SQLQERESERVATIONS clerks dm_exec_query_resource_semaphores dm_exec_query_memory_grants RESOURCE_SEMAPHORE_SMALL_QUERY waits RESOURCE_SEMAPHORE_ QUERY_COMPILE compiles RESOURCE_SEMAPHORE (Query Memory) Hashes and sorts

Resource Queries, Memory, and RESOURCE semaphores Pre-emptive Waits May wrap more Maycode wrapthan more just code than just the API the API ************************ * * BEGIN STACK DUMP: * 10/17/09 15:51:52 spid 0 * * Non-yielding Scheduler * ************************ Windows API Xproc Workers go preemptive when calling external APIs that may take some time

External What does this look like pre-SQL 2008? Status = RUNNING Wait_type = NULL What does this look like in SQL 2008? Status = RUNNING Wait_type = PREEMPTIVE_XXXX 18 What are some I might see? Type Description Scenario PREEMPTIVE_OS_GETPROCADDRESS Wraps calls to GetProcAddress() and xproc function Measure of xproc execution time

PREEMPTIVE_OS_WRITEFILEGATHER Wraps calls to WriteFileGather() to zero out a section of a file Long autogrow for tlog file or database files (if not using instant file init) PREEMPTIVE_OS_LOOKUPACCOUNTSID Wrapped calls to LookupAccountSid() Mostly used during login authentication. Long waits could indicate DC issues. PREEMPTIVE_OLEDBOPS Wrapped around various code fragments that will call OLE-DB methods for linked server queries.. Helps fill in gaps where OLEDB wait not set. ~190 of ~190 of

these these 19 Extended Events and Waits wait_info wait_info_externa l Normal waits Preemptive waits dm_xe_map_values dm_xe_map_values wait_type opcode Timings Begin and End Begin and End Duration, Total, Max Duration, Total, Max Get query, session, or stack dump

On by Default System_Health Session Has These SQLCAT Waits Stats Per Session Project 20 There are other waits Why cant I Why cant I truncate the truncate the log log log_reuse_wait A poorly A poorly written DLL written DLL PRECONNECT PRECONNECT status status loader lock wait Spinlocks backoffs in backoffs in

sys.dm_os_spinlock_stats sys.dm_os_spinlock_stats sessions Resource Governor You decide to You decide to throttle throttle 21 Where is THE LIST? In a header file in the source code and in sys.dm_xe_map_values for SQL Server 2008 The BOL list KB article on waittypes is only for SQL 2000 and prior The plan The Wait Type Repository The Wait Type Repository Blog Blog 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 22 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 23 Appendix 24 What does MDW tell you about I/O Waits sync reads, sorts, SQLTrace I/O, load CLR assembly Buffer Pool I/O for pages Backups, Recovery, DBM WRITELOG wait time =

Log Flush Wait (perfmon) LOGBUFFER is just waiting on folks waiting on WRITELOG 25 The mapping has changed sys.sysprocesses.waittype is a binary value Binary to string mapping changed in SQL 2005 KB 822101 wrong for 2005 and 2008 lastwaittype may NOT be current mapping if wait_type != NULL sys.dm_xe_map_values has the correct mapping.kind of 26 Whats About These? Forced SLEEP_TASK Fixed time Hard to figure out scenario Resource DBMIRROR_DBM_EVENT Log shipping delayed to secondary External

OLEDB Wrapped around linked server OLE-DB API calls Wait time will fluctuate since set and cleared for each call wait_resource is remote server and remote SPID PREEMPTIVE_XX type can now also show up Sync CMEMTHREAD Thread synchronization for memory allocation Hot stored proc in SQL Serv High wait times = A likely bug Hot stored proc in SQL Serv er 2005 er 2005 27 Complete the Evaluation Form & Win! You could win a Dell Mini Netbook every day just for handing in your completed form! Each session form is another chance to win! Pick up your Evaluation Form: Within each presentation room

At the PASS Booth near registration area Sponsored by Dell Drop off your completed Form: Near the exit of each presentation room At the PASS Booth near registration area 28 Visit the Microsoft Technical Learning Center Located in the Expo Hall Microsoft Ask the Experts Lounge Microsoft Chalk Talk Theater Presentations Microsoft Partner Village 29 Thank you for attending this session and the 2009 PASS Summit in Seattle

Recently Viewed Presentations

  • Booze, Bullets, and Babes - Suffolk City Public Schools

    Booze, Bullets, and Babes - Suffolk City Public Schools

    White Sheets, Red Scares, Black Monday and all those Blues Yeah, well he ain't got nothing on the original! This is Leon James 1920s Booze, Bullets, and Babes
  • M&R Global meeting -

    M&R Global meeting -

    MARPOL IV & ECA "MARPOL IV" International regulation for the prevention of pollution from ships to minimize pollution of the sea, including dumping, oil and exhaust pollution. ECA(Emission Control Area) Area which severely controled SOx(Sulphur Oxide) emission from ship designated...
  • 80 60 Percent (%) 40 20 0 N305D

    80 60 Percent (%) 40 20 0 N305D

    SD 0.421 Geometric Mean 1.578 B Cluster (n=365) 80 The a.a. positions in the green ovals were used for tree splitting. The blue and red color indicate an amino acid as wild type or polymorphism respectively. Rectangles indicate terminal nodes.
  • Chapter 6: Microbial Growth

    Chapter 6: Microbial Growth

    Microbial Growth Increase in number of cells, not cell size Populations Colonies Metabolic activity estimating bacterial numbers is measuring the metabolic activity of the population for example, acid production or oxygen consumption Measuring Dry Weight For filamentous organisms such as...
  • Joint Meeting City of Conroe / SJRA February

    Joint Meeting City of Conroe / SJRA February

    GRP History Timeline (cont.) November 23, 2009. First meeting of Conroe and SJRA representatives on the GRP contract. Mayor Melder expresses his concern about "representation" of Conroe in the decision-making process and asks the Authority whether it will sell raw...
  • Common Core State Standards Writing from Sources 6-12

    Common Core State Standards Writing from Sources 6-12

    In history/social studies, students must be able to incorporate narrative accounts into their analysis of individuals or events of historical importance. In science and tech. subjects, students must be able to write precise enough descriptions of the step-by-step procedures they...
  • Life Life in in aa Coral Coral Reef

    Life Life in in aa Coral Coral Reef

    Decomposers take all the material that is left over or further broken down by the detritivores and scavengers, as well as waste, and convert it to forms that are usable for algae to grow. * * A food chain shows...
  • MVP -

    MVP -

    Founder Nick Swinmurm had a problem. He wanted a online store but couldn't afford inventory. He visited stores and took pictures of the shoes. Only after he received an order would he return to the store to purchase the shoes....