Performance analysis of SQL Server — about CPU

- the most since the query compilation of the total amount of cpu time consuming before 50 (Total_woker_time)
the SELECT TOP 50
total_worker_time / 1000 AS [total consumption of CPU time (MS)],
execution_count [number of runs],
qs.total_worker_time / qs.execution_count / 1000 the AS [average consumed CPU time (MS)],
last_execution_time the AS [last execution time],
max_worker_time / the AS 1000 [maximum execution time (MS)],
the SUBSTRING (qt.text, qs.statement_start_offset / 2 +. 1,
(the WHEN the CASE = -1 qs.statement_end_offset
THEN the DATALENGTH (qt.text)
the ELSE qs.statement_end_offset the END -qs.statement_start_offset) / 2 +. 1)
the AS [CPU usage syntax], qt.text [complete syntax],
qt.dbid, dbname = db_name (qt.dbid),
qt.objectid, object_name (qt.objectid, qt.dbid) the ObjectName
the FROM QS the sys.dm_exec_query_stats the WITH (NOLOCK)
The Apply sys.dm_exec_sql_text the CROSS (qs.sql_handle) AS qt
the WHERE execution_count> 1
the ORDER BY DESC total_worker_time
sql Server as a holistic system, which are closely linked, for example: sql statement to solve the more I / O overhead problem that the corresponding CPU overhead will be reduced, contrary to solve the most CPU overhead, and that the corresponding I / O overhead will be reduced. Solve the I / O after consuming CPU overhead is also reduced, because of Worker threads in CPU need to scan I / O pages for less, obstruction of emerging resource lock also reduced

2. high CPU database query problem SQL, according to the time "waiting milliseconds", to identify the problems of the SELECT SPID SQL, blocked, DB_NAME (sp.dbid)
AS DBName, program_name, the waitresource, sp.waittime wait milliseconds, sp. stmt_start,,
the lastwaittype, sp.loginame, sp.Status, sp.hostname, A. [the Text] the AS [the TextData],
the SUBSTRING (A.text, sp.stmt_start / 2, (the WHEN sp.stmt_end the CASE = -1 THEN
the DATALENGTH ( A.text) the ELSE sp.stmt_end the END - sp.stmt_start) / 2) the AS [current_cmd]
the FROM OUTER the APPLY the sys.dm_exec_sql_text the sys.sysprocesses the AS SP (sp.sql_handle) the AS
A SPID the WHERE> = 50 --and the lastwaittype 'HADR_SYNC_COMMIT 'the AND the Status <>' Sleeping '
the ORDER BY sp.waittime desc;

3. Case Studies
SQL Server cause high CPU burst, usually caused by abnormal SQL, suspected disk performance server problem, stop SQL services, with a test disk performance, disk performance really is not how, but also not bad to the point where . Later found a query SQL, there are 300 million queries taskid field is not indexed, resulting in very slow query IO, thereby affecting the CPU of high explosive. After the reconstruction of a new tb_log table, plus indexing, performance issues addressed in taskid field.

Guess you like

Origin blog.51cto.com/songlihuan/2481125
Recommended