30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: OS and Hardware Interaction<br />

switches, indicating that many <strong>SQL</strong> <strong>Server</strong> tasks are giving up control before completing,<br />

is not ideal as it increases load on the CPU simply to allow more users to feel as if they are<br />

being served.<br />

With the values from the query in Listing 7.19 we can get the counts of the various<br />

operations related to context switching that have occurred since the last reboot.<br />

SELECT scheduler_id ,<br />

preemptive_switches_count ,<br />

context_switches_count ,<br />

idle_switches_count ,<br />

failed_to_create_worker<br />

FROM sys.dm_os_schedulers<br />

WHERE scheduler_id < 255<br />

Listing 7.19: Investigating context switching.<br />

One-off queries of this sort, using the "History" columns, are not necessarily very useful.<br />

A large number of context switches, accumulated over a long period, may simply reflect<br />

the activity of scheduled nightly processes, where such context switching does not affect<br />

the users. In order to detect excessive context switching during normal OLTP operations<br />

caused, for example, by abnormally high user loads, we need to take a baseline measurement<br />

and then track and compare the results over time.<br />

As noted during the earlier discussion on common wait types, hyper-threading<br />

(parallel execution) in OTLP systems can lead to context switching, and to CXPACKET<br />

and SOS_SCHEDULER_YIELD waits. Furthermore, certain hyper-threading<br />

implementations in older processors do not "play nicely" <strong>with</strong> the <strong>SQL</strong> <strong>Server</strong> engine<br />

and can exacerbate the issue. According to Zach Nichter, in his Technet Magazine<br />

article, Optimizing <strong>SQL</strong> <strong>Server</strong> CPU performance, at http://technet.microsoft.com/<br />

en-us/magazine/2007.10.sqlcpu.aspx, if hyper-threading is enabled and you are seeing<br />

more than 5000 * (Number of Processors) context switches per second, it suggests that<br />

the scheduler is context switching between the same processor, yet thinking it is<br />

swapping to a different one, and you should consider turning hyper-threading off and<br />

298

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!