Encontro XII:
  Por dentro dos
  Wait Types (ext. ed.)
Luciano Moreira - {Luti}
luciano.moreira@srnimbus.com.br
www.srnimbus.com.br
http://luticm.blogspot.com
@luticm
About PASS

The PASS community encompasses everyone who uses the Microsoft SQL
Server or Business Intelligence Platforms. This includes database
administrators, application developers, Business Intelligence professionals,
information technology professionals, executives, consultants, educators,
instructors, and students.


The Professional Association for SQL Server (PASS) is the only
independent, user-run, not-for-profit association dedicated to the SQL
Server community helping its members Connect, Share, and Learn by:
 –   Facilitating member networking and exchange of information through our websites, Chapters,
     annual Summits, regional and local events, and virtual communities
 –   Working with Microsoft to influence the evolution of SQL Server products and services
 –   Delivering high quality, up-to-date, technical content, presentations, and other educational
     material for professional development
Eventos
Agenda
• O que é um wait?
• Entendendo as DMVs
• Demonstrações de wait types
   –   ASYNC_NETWORK_IO
   –   PREEMPTIVE_XX
   –   WRITELOG e PAGEIOLATCH
   –   CXPACKET
   –   SOS_SCHEDULER_YIELD
   –   RESOURCE_SEMAPHORE

• Outros wait types
• Conclusão e referências
O que é um wait?

• O que é um wait?
• A ideia é simples e intuitivamente
  você já sabe o que fazer.
• Monitorar, verificar maiores esperas
  e fazer um trobleshooting quando
  problemas aparecerem.
• Então...


    Qual o objetivo dessa palestra?
O que é um wait?

• CPU  Threads
• Scheduler  Workers
                              Running




                  Suspended             Runnable
O que é um wait?

• O SQL Server mantém cinco listas:
   –   Worker: lista os worker disponíveis.
   –   Runnable: workers prontos para executar uma tarefa.
   –   Waiter: lista os workers que estão esperando por um recurso.
   –    I/O: lista as requisições de I/O que estão pendentes.
   –   Timer: registra lista com workers que são ativados em intervalos
       regulares.
• Para as threads não ficarem sempre sendo escalonadas
  pelo Windows, WaitForSingleObject.
• Estados do worker: Init, Running, Runnable e
  Suspended.
   – E o sleeping, não está na lista?
SQLOS Scheduler
      O SQL Server mantém cinco listas:
          Worker: lista os worker disponíveis.
          Runnable: workers prontos para executar uma tarefa.
          Waiter: lista os workers que estão esperando por um recurso.
           I/O: lista as requisições de I/O que estão pendentes.
          Timer: registra lista com workers que são ativados em intervalos
          regulares.
      Para as threads não ficarem sempre sendo
      escalonadas pelo Windows,
      WaitForSingleObject.
      Estados do worker: Init, Running, Runnable e
      Suspended.
          E o sleeping, não está na lista?



Módulo 02| Arquitetura do SQL Server
We know
       Os detalhes de uma espera we need to
          Common for
                                                         wait
           a SELECT

         Request
                                                                Setup a
        LCK_M_IS
                                     A conflict exists      SOS_WaitInfo with
      (Shared Intent)
                                                              LCK_M_IS
           lock



                                Agradecimento pelo
 Understands SQLOS
     scheduling                  slide: Bob Ward
                                         Use
                                                                 Call
                                    SOS_EventAuto
                                                            LockOwner::Sleep
                                     class to wait
   Wait() results in
SignalObjectAndWait()
              Ultimately it always comes
                       down to                             SOS_EventAuto is a
                WaitForSingleObject()                      wrapper for Windows
                                                           Kernel Event object
              or SignalObjectAndWait()
9 |          Footer Goes Here
Entendendo as DMVs

       • Visão global
         – sys.dm_os_wait_stats
       • Visão pontual / fina
         – Sys.dm_exec_requests
         – sys.dm_os_waiting_tasks
       • sys.dm_exec_sessions
       • sys.processes e KB 822101
         – Description of the waittype and lastwaittype columns
           in the master.dbo.sysprocesses table in SQL Server
           2000 and SQL Server 2005


10 |       Footer Goes Here
Demo time…

        1.     ASYNC_NETWORK_IO
        2.     PREEMPTIVE_XX
        3.     WRITELOG e PAGEIOLATCH
        4.     CXPACKET
        5.     SOS_SCHEDULER_YIELD
        6.     RESOURCE_SEMAPHORE




11 | 26/11/2011 | Footer Goes Here
Outros wait types

       – ThreadPool = atingiu o limite de threads do SQL
         Server
       – FGCB_ADD_REMOVE = File Group Control Block
       – LOGBUFFER = próximo wait depois do
         WRITELOG.
       – IO_COMPLETION = sort IO, SQLTrace, copy model
       – ASYNC_IO_COMPLETION = create database,
         reading backup files
       – PREEMPTIVE_OLEDBOPS = fecha gaps que o
         OLEDB não cobria antes.

12 |      Footer Goes Here
Outros wait types

       •   Queue Waits
       •   LAZYWRITER_SLEEP
       •   SQLTRACE_BUFFER_FLUSH
       •   LOGMGR_QUEUE
       •   CHECKPOINT_QUEUE
       •   REQUEST_FOR_DEADLOCK_SEARCH
       •   CLR_AUTO_EVENT




13 |        Footer Goes Here
Conclusão

       – Novos wait types aparecem continuamente no
         SQL Server
       – Segredo não está em rodar scripts para coletar
         os wait types, está em saber analisar a causa do
         problema
       – Estudo contínuo (blogs, artigos e fóruns) dos
         wait types irá dar segurança no assunto.
       – Documentação ainda é fraca…



14 |      Footer Goes Here
Referências

       • Repositório publicado pelo Bob Ward
         • http://blogs.msdn.com/b/psssql/archive/2009/11/0
           3/the-sql-server-wait-type-repository.aspx
       • SQLCAT
         • http://sqlcat.codeplex.com/Release/ProjectReleas
           es.aspx?ReleaseId=26601
       • SQL Server 2005 Waits and Queues
         • http://technet.microsoft.com/en-
           us/library/cc966413.aspx


15 |      Footer Goes Here
Thank You from PASS

  www.sqlpass.org

SQLServerDF XII - Wait Types

  • 1.
    Encontro XII: Por dentro dos Wait Types (ext. ed.) Luciano Moreira - {Luti} luciano.moreira@srnimbus.com.br www.srnimbus.com.br http://luticm.blogspot.com @luticm
  • 2.
    About PASS The PASScommunity encompasses everyone who uses the Microsoft SQL Server or Business Intelligence Platforms. This includes database administrators, application developers, Business Intelligence professionals, information technology professionals, executives, consultants, educators, instructors, and students. The Professional Association for SQL Server (PASS) is the only independent, user-run, not-for-profit association dedicated to the SQL Server community helping its members Connect, Share, and Learn by: – Facilitating member networking and exchange of information through our websites, Chapters, annual Summits, regional and local events, and virtual communities – Working with Microsoft to influence the evolution of SQL Server products and services – Delivering high quality, up-to-date, technical content, presentations, and other educational material for professional development
  • 3.
  • 4.
    Agenda • O queé um wait? • Entendendo as DMVs • Demonstrações de wait types – ASYNC_NETWORK_IO – PREEMPTIVE_XX – WRITELOG e PAGEIOLATCH – CXPACKET – SOS_SCHEDULER_YIELD – RESOURCE_SEMAPHORE • Outros wait types • Conclusão e referências
  • 5.
    O que éum wait? • O que é um wait? • A ideia é simples e intuitivamente você já sabe o que fazer. • Monitorar, verificar maiores esperas e fazer um trobleshooting quando problemas aparecerem. • Então... Qual o objetivo dessa palestra?
  • 6.
    O que éum wait? • CPU  Threads • Scheduler  Workers Running Suspended Runnable
  • 7.
    O que éum wait? • O SQL Server mantém cinco listas: – Worker: lista os worker disponíveis. – Runnable: workers prontos para executar uma tarefa. – Waiter: lista os workers que estão esperando por um recurso. – I/O: lista as requisições de I/O que estão pendentes. – Timer: registra lista com workers que são ativados em intervalos regulares. • Para as threads não ficarem sempre sendo escalonadas pelo Windows, WaitForSingleObject. • Estados do worker: Init, Running, Runnable e Suspended. – E o sleeping, não está na lista?
  • 8.
    SQLOS Scheduler O SQL Server mantém cinco listas: Worker: lista os worker disponíveis. Runnable: workers prontos para executar uma tarefa. Waiter: lista os workers que estão esperando por um recurso. I/O: lista as requisições de I/O que estão pendentes. Timer: registra lista com workers que são ativados em intervalos regulares. Para as threads não ficarem sempre sendo escalonadas pelo Windows, WaitForSingleObject. Estados do worker: Init, Running, Runnable e Suspended. E o sleeping, não está na lista? Módulo 02| Arquitetura do SQL Server
  • 9.
    We know Os detalhes de uma espera we need to Common for wait a SELECT Request Setup a LCK_M_IS A conflict exists SOS_WaitInfo with (Shared Intent) LCK_M_IS lock Agradecimento pelo Understands SQLOS scheduling slide: Bob Ward Use Call SOS_EventAuto LockOwner::Sleep class to wait Wait() results in SignalObjectAndWait() Ultimately it always comes down to SOS_EventAuto is a WaitForSingleObject() wrapper for Windows Kernel Event object or SignalObjectAndWait() 9 | Footer Goes Here
  • 10.
    Entendendo as DMVs • Visão global – sys.dm_os_wait_stats • Visão pontual / fina – Sys.dm_exec_requests – sys.dm_os_waiting_tasks • sys.dm_exec_sessions • sys.processes e KB 822101 – Description of the waittype and lastwaittype columns in the master.dbo.sysprocesses table in SQL Server 2000 and SQL Server 2005 10 | Footer Goes Here
  • 11.
    Demo time… 1. ASYNC_NETWORK_IO 2. PREEMPTIVE_XX 3. WRITELOG e PAGEIOLATCH 4. CXPACKET 5. SOS_SCHEDULER_YIELD 6. RESOURCE_SEMAPHORE 11 | 26/11/2011 | Footer Goes Here
  • 12.
    Outros wait types – ThreadPool = atingiu o limite de threads do SQL Server – FGCB_ADD_REMOVE = File Group Control Block – LOGBUFFER = próximo wait depois do WRITELOG. – IO_COMPLETION = sort IO, SQLTrace, copy model – ASYNC_IO_COMPLETION = create database, reading backup files – PREEMPTIVE_OLEDBOPS = fecha gaps que o OLEDB não cobria antes. 12 | Footer Goes Here
  • 13.
    Outros wait types • Queue Waits • LAZYWRITER_SLEEP • SQLTRACE_BUFFER_FLUSH • LOGMGR_QUEUE • CHECKPOINT_QUEUE • REQUEST_FOR_DEADLOCK_SEARCH • CLR_AUTO_EVENT 13 | Footer Goes Here
  • 14.
    Conclusão – Novos wait types aparecem continuamente no SQL Server – Segredo não está em rodar scripts para coletar os wait types, está em saber analisar a causa do problema – Estudo contínuo (blogs, artigos e fóruns) dos wait types irá dar segurança no assunto. – Documentação ainda é fraca… 14 | Footer Goes Here
  • 15.
    Referências • Repositório publicado pelo Bob Ward • http://blogs.msdn.com/b/psssql/archive/2009/11/0 3/the-sql-server-wait-type-repository.aspx • SQLCAT • http://sqlcat.codeplex.com/Release/ProjectReleas es.aspx?ReleaseId=26601 • SQL Server 2005 Waits and Queues • http://technet.microsoft.com/en- us/library/cc966413.aspx 15 | Footer Goes Here
  • 16.
    Thank You fromPASS www.sqlpass.org