Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

First Look: A Troubleshooting Guide Series 1: How to troubleshoot SQL Server Performance Issue (High CPU) Introduction: First

important thing in any incident is to understand the issue and validate the symptoms. This will help us in selecting a proper troubleshooting plan, and get to a solution faster. Probing and Scoping: Specific: The environment experiencing the performance problem and its impact should be clearly understood and documented. Measurable: How do you know that the problem is occurring? What metrics did you use to measure the problem? Thumb Rule: When does a resource become a bottleneck? Demand greater than Supply. So we need to understand why there is an increase in the demand. What are the general resources? CPU IO Memory Data Gathering (For Understanding): It is very important that we gather limited data to understand and list the possible causes which we are going to target in our troubleshooting. Look @, Application and System Event log ERRORLOG sp_configure settings Task Manager Basics Initial Troubleshooting & Data Collection (High CPU Issues): In this specific discussion we will talk about troubleshooting High CPU issue. From looking at the task manager we understood that there is a high CPU consumption in the server (Always monitor for 5 mins and ensure that the CPU usage is consistently above 80%.) From now, there should be parallel activities:

1. Check in SQL Processes for SPIDs that are consuming High CPU and are running for
longer time. Get the queries that are executed by those SPIDs. SELECT distinct top 5 [Spid] = session_Id , [Database] = DB_NAME(sp.dbid) , [User] = nt_username , [Status] = er.status , (er.cpu_time/1000) as

[CPU(secs)] , (er.total_elapsed_time/1000) as [Duration(secs)] , er.percent_complete as PercentDone , [Individual Query] = SUBSTRING (qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE er.statement_end_offset END er.statement_start_offset)/2) ,[Parent Query] = qt.text , [CurrWaitype] = er.wait_type , [Waitime]= er.wait_time , [LastWaitype] = er.last_wait_type , [Command] = er.command , Program = program_name , Hostname , nt_domain , start_time FROM sys.dm_exec_requests er INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt WHERE session_Id > 50 ORDER BY 5 desc 2. Capture Performance Monitor with the below counters.

C:\Docum ents and Settings\Adm inistrator\Desktop\Perform ance Mon

Few Common Causes for High CPU: 1. Bad Query Causing a lot of resource consumption 2. Excessive Compilations and Recompilations 3. Degree of Parallelism Further Troubleshooting: 1. Bad Query causing a lot of resource consumption Once you have the query, Please list out the tables that are touched by the Query. Capture the Fragmentation Information and Statistics Information belonging to those tables. If there was no proper maintenance done in the tables perform rebuild index and update statistics. In Parallel, start SQL Server Profiler with Proper Counters to capture the plan used by the Query. If the Issue continues even after completing the maintenance activities, review the query plan and provide feedback to the application team to change the query if it is bad. 2. Excessive Compilations and Recompilations Once you have found from the Perfmon that there is excessive compilations or recompilations happening in SQL Server, Capture SQL Server Profiler to get more details of why are there are more compilations/recompilations. Based on the cause for the compilations, take action. 3. Excessive Parallelism

You can find from SYSPROCESSES for wait types like SOS_Scheduler, CX_PACKET which denotes that queries are going for parallelism. Check for the Max DOP Setting from SP_Configure. See if that value was set properly.

Profiler Trace Template

C:\Siva's Docum ents\ SME Initiatives\Skill Gap\Enabling the Engineers\2

You might also like