0% found this document useful (0 votes)
19 views3 pages

CPU Bottlenecks in SQL Server Using Performance Counters 1703006371

Sql dba

Uploaded by

venkataprudhivi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

CPU Bottlenecks in SQL Server Using Performance Counters 1703006371

Sql dba

Uploaded by

venkataprudhivi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IRPHAN ALI SHAIK

Identifying CPU Bottlenecks in SQL Server Using


Performance Counters
In the realm of SQL Server performance optimization, identifying and addressing CPU bottlenecks is
crucial. Let's explore how you can leverage performance counters to pinpoint CPU issues and
optimize your server's performance.

Monitor CPU Usage

The first step is to monitor CPU usage using either Task Manager (% CPU Usage) or Windows
Performance Monitor (% Processor Time). A CPU usage around ~85% serves as a reliable indicator of
a CPU bottleneck.

Reasons for High CPU Usage

 Several factors could contribute to high CPU usage, including:


 Operating System Issues
 SQL Server Related Issues:
 High Recompilations of SQL Queries
 Calculations within the Query
 Query Design Issues (e.g., Sorting Joins, Poor Indexes, Condition Clauses)

Identify SQL Server Issues


To distinguish between operating system and SQL Server issues, examine the components
consuming CPU resources on your server. Ideally, avoid hosting other tools or server services on the
same box as SQL Server. If SQL Server emerges as a high CPU-consuming service, further
investigation is necessary.

Consider the following SQL query to identify CPU resource crunch:

SELECT scheduler_id, current_tasks_count, runnable_tasks_count


FROM sys.dm_os_schedulers
WHERE scheduler_id < 255;

Dealing with SQL Server Culprits


If SQL Server is indeed the culprit, the next step is to assess recompilations on the server. Run the
following query to gain insights into SQL query statistics:

SELECT TOP 25 sql_text.text,


sql_handle,
plan_generation_num,
execution_count,
dbid,
objectid
FROM sys.dm_exec_query_stats a
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sql_text
WHERE plan_generation_num > 1
ORDER BY plan_generation_num DESC;
IRPHAN ALI SHAIK

Evaluating Recompilations and Optimization


To understand how much CPU time is utilized for recompilations (optimizations) of queries, use the
following queries:

Total Optimization Performed from the last restart:

SELECT occurrence AS Optimizations


FROM sys.dm_exec_query_optimizer_info
WHERE counter = 'optimizations';
Average elapsed time for Optimization of main queries:

SELECT ISNULL(value, 0.0) AS ElapsedTimePerOptimization


FROM sys.dm_exec_query_optimizer_info
WHERE counter = 'elapsed time';

Breakup of Parsing, Compilation, and Execution Time

For a detailed breakdown of Parsing, Compilation, and Execution Time of your query, enable
Statistics Options by running the following query before executing your main query:

SET STATISTICS TIME ON;

By systematically analyzing these performance counters and queries, you can identify and address
CPU bottlenecks in your SQL Server, leading to improved overall performance.

 Review the Execution Plan?


Any user query’s Execution Plan can be viewed with one of the below options:
1. Select Display Estimated Execution Plan/Include Actual Execution Plan from SSMS Tool
bar.

2. Show Execution Plan in XML.


IRPHAN ALI SHAIK

 Know which is the Execution Plan currently stored in system memory


Following query can help:
SELECT st.text, qs. sql_handle, qs.plan_handle
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(sql_handle) st;
GO

This will show Query test, unique identified of the SQL Query and unique identified of the
Execution Plan.

 See the Execution Plan


Following query can help with one of the Plan Handles which you may have captured
through above step:
SELECT * FROM sys.dm_exec_query_plan (Plan Handle)

 Understand what is exactly happening in the query


Enable the STATISTICS options for your Query. Specifically Profile would help.
SET STATISTICS PROFILE ON

Some considerations for T-SQL CPU optimization are:


 Query plan reuse
 Reducing compiles and recompiles
 Sort operations
 Improper joins
 Missing indexes
 Table/index scans
 Function usage in SELECT and WHERE clauses
 Multithreaded operations

Note :unravelling performance issues is a complex challenge, and in this context, I outline
the methodology for understanding CPU bottleneck issues. The approach differs in each
case. It is essential not to mimic this process on production servers.

You might also like