Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

SQL Server 2012 : Latches and Spinlocks - Monitoring Latches and Spinlocks

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
8/24/2014 9:16:33 PM

In terms of monitoring latches, you’ve already been introduced to some of the DMVs. There’s more to monitoring latches than just DMVs, though. Performance Monitor also offers useful information about latches, as do extended events, which also provide information about spinlocks. Another option is to use memory dumps, but those are not covered here.

DMVs

The DMVs covered earlier are a useful point of reference. You should familiarize yourself with the contents of sys.dm_os_wait_stats, sys.dm_os_latch_stats, and sys.dm_os_spinlock_stats, and be comfortable with the output they provide. In addition, sys.dm_os_waiting_tasks will display a list of any tasks that are currently waiting on a resource, providing a useful session_id column that can be used to hook into other useful DMVs for information about sessions and the like.

sys.dm_os_wait_stats

This DMV has five columns.

  • wait_type
  • waiting_tasks_count
  • wait_time_ms
  • max_wait_time_ms
  • signal_wait_time_ms

The first three were described earlier. max_wait_time_ms shows the largest wait time for a single wait since the DMV was cleared. signal_wait_time_ms is less relevant for latches, although it does get used if threads hit spinlock barriers.

sys.dm_os_latch_stats

This DMV has four columns.

  • latch_class
  • waiting_requests_count
  • wait_time_ms
  • max_wait_time_ms

These columns have all been described earlier.

sys.dm_os_spinlock_stats

This DMV has six columns.

  • name
  • collisions
  • spins
  • spins_per_collision
  • sleep_time
  • backoffs

A collision is recorded when a spinlock tries to acquire a resource but finds it unavailable. As a result, the spinlock starts spinning. This increases the spins but the collision has already been recorded. Usefully, this DMV also provides a spins_per_collision column, saving the user from doing the calculation.

I’m sure you can imagine that the number of spins is potentially quite large. Let’s just say that it’s a good thing that this column is a bigint type, which handles numbers up to 19 digits long. I don’t think the correct technical term is actually “gazillions,” but it feels right when you take a look at this DMV on busy systems that have been up for a while.

The sleep_time and backoffs columns simply report the amount of time that has been spent sleeping on spinlocks, and the number of backoffs.

Performance Monitor

Performance Monitor provides several useful counters to keep an eye on. Figure 1 shows a typical screenshot containing the list of counters in the SQLServer:Latches category for a machine.

FIGURE 1

image

Table 1 describes these counters.

TABLE 1: Useful Performance Monitor Counters

COUNTER DESCRIPTION
Average Latch Wait Time (ms) Average latch wait time (in milliseconds) for latch requests that had to wait
Latch Waits/sec Number of latch requests that could not be granted immediately and had to wait before being granted
Number of SuperLatches Number of latches that are currently SuperLatches
SuperLatch Demotions/sec Number of SuperLatches that have been demoted to regular latches
SuperLatch Promotions/sec Number of latches that have been promoted to SuperLatches
Total Latch Wait Time (ms) Total latch wait time (in milliseconds) for latch requests that had to wait in the last second

These performance counter values are also available using the DMV sys.dm_os_performance_counters (see Figure 2) (code file Ch7Monitoring.sql):

FIGURE 2

image
SELECT *
FROM sys.dm_os_performance_counters
WHERE object_name LIKE '%Latches%';

Note that although the object_name field appears to end in the string ’Latches’, this field is actually stored as nchar(256), rather than nvarchar(256), so there is a large amount of whitespace at the end, and that last % is needed.

Extended Events

If you open the New Session Wizard for Extended Events from SQL Server 2012 Management Studio, you will reach a screen from which you select the events you wish to capture. After reaching this, first scroll the Event library section to reveal the Channel drop-down box. Then, as shown in Figure 3, check Debug, which is unchecked by default.

FIGURE 3

image

Now you can search for spinlock and latch to find a list of extended events related to these areas, as described in Table 2.

TABLE 2: Spinlock and Latch Extended Events

EXTENDED EVENT DESCRIPTION
spinlock_backoff Spinlock backoff
spinlock_backoff_warning Occurs when a spinlock backoff warning is sent to the Error Log
latch_acquire_time Time taken to acquire a latch
latch_demoted Occurs when a SuperLatch is demoted to an ordinary latch
latch_promoted Occurs when a latch is promoted to a SuperLatch
latch_suspend_begin Occurs when the executing task must suspend while waiting for a latch to become available in the requested mode
latch_suspend_end Occurs when the executing task is resumed after waiting for a latch
latch_suspend_warning Occurs when there is a timeout waiting for a latch possibly causing performance problems

You should now be able to create an XE session collecting these events. Bear in mind that you would typically expect to see many more latch_acquire_time events occurring than the other event types, and you might not want to bother collecting them.

Other -----------------
- SQL Server 2012 : Latches and Spinlocks - SuperLatches/Sublatches
- SQL Server 2012 : Latches and Spinlocks - Latch Types, Latch Modes
- Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - Client-Side Object Model API Coverage
- Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 3) - Creating, Updating, and Deleting
- Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 2) - Filtering and Selecting
- Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 1) - Getting Started with REST and OData
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 2) - Apps for Office Integrated with an App for SharePoint
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 1) - Standalone Apps for Office
- Sharepoint 2013 : The Office JavaScript Object Model (part 3) - App Security
- Sharepoint 2013 : The Office JavaScript Object Model (part 2) - Functional Capabilities by Office Client,Mailbox-based Apps
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server