Sql-server – High usage of CPU Without use

performanceperformance-tuningsql-server-2012

I'm trying to figure out what is happening but at this point I cannot troubleshoot this issue…

I have 2 servers with same specs, actually also with almost same users connected (Only me)…

One of the servers is stable at 20% CPU usage while the other is at 1%… Same Databases, same Processes…

How I can know what is actually consuming this high amount of CPU on SQL Server compared to the other server if both of them are idle?

Best Answer

First of all you should find out, which service/process consuming maximum CPU.

You can you Process Monitor tool provided by Microsoft, which give details information.

You can find it here https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx

If it's SQL Server, then

1st I would recommend to use master.dbo.sysprocess as

select * from master.dbo.sysprocesses order by cpu desc

if it returns spid < 50 on top means, it's SQL Server own process not user process. So, on the basis of lastwaittype column value you can change recommended (according the wait type) SQL Server configuration or tune your HW.

If it returns process id >50 means it's user process and you can use below query to find details about the process and tune your query.

if the session is active (running, runable, suspanded)

select
            db_name(sp.dbid),sp.spid,er.wait_type,er.wait_time,er.wait_resource,er.total_elapsed_time,st.text,qp.query_plan
            ,ec.net_packet_size,ec.client_net_address,es.host_name,es.program_name,es.client_interface_name
            ,es.status,es.cpu_time,qmg.granted_memory_kb,es.total_scheduled_time,es.total_elapsed_time
            ,es.reads,es.writes,es.logical_reads

from
                sys.dm_exec_requests er
inner join      master.dbo.sysprocesses sp
on              er.session_id=sp.spid
inner join      sys.dm_exec_connections ec
on              er.session_id=ec.session_id
inner join      sys.dm_exec_sessions es
on              ec.session_id=es.session_id
inner join      sys.dm_exec_query_memory_grants qmg
on er.session_id=qmg.session_id
cross apply     (select text from sys.dm_exec_sql_text(er.sql_handle)) st
cross apply     (select * from sys.dm_exec_query_plan(er.plan_handle)) qp

If the session is not active (sleeping).

select a.spid,db_name(b.dbid) [DB Name],b.text [Query],a.cpu
from master.dbo.sysprocesses a
cross apply sys.dm_exec_sql_text(a.sql_handle) b where status='sleeping'

Thanks