Quantcast
Channel: Database+Disk+Performance™
Viewing all articles
Browse latest Browse all 20

BOE (Back of Envelope) Method – Quick and Dirty Method for Finding High CPU Jobs

$
0
0

Situation: Your database server is sitting at 100%. There are not that many users logged into SAP doing work. Somehow, a bad plan is running and using all your resources on the computer. Problem is, you have no idea which spid(s) have the bad plan!

Within SQL Server it is extremely difficult to find which spid is using the most CPU. There are two methods for doing this:

-Using PERFMON, looking at the Thread Performance Object: % Processor Time, ID Process, ID Thread. Select ALL SQL threads (sqlservr/*). Then flipping it to “tabular” report format (ie. NOT the graph) and scrolling over 100 entries to find the thread that is using the most CPU time. Since a query can move from thread to thread, it’s a real tough time. Once you have the thread with the CPU, then get the ID Thread. The ID Thread is the KPID in sysprocesses. Join on this to get the SPID. Then DBCC INPUTBUFFER(spid) to see what the query is running. You can also KILL the spid, too. The ID Process is the NT PID.

select spid

from master..sysprocesses

where kpid =

go

DBCC INPUTBUFFER()

go

-As you can see, this is a difficult process. A quick and dirty method that I use that isn’t 100% accurate, but is about 75% correct is to run the following query. The long running jobs that this query reports tend to be the ones using the most CPU time.

CREATE proc boe_proc as

select datediff(mi, last_batch,getdate())'minutes',spid, waittype, cpu, physical_io, convert(char(15),hostname), convert(char(15),program_name), convert(char(20),getdate()),spid, last_batch, cmd

from master..sysprocesses

where spid > 50 and

cmd not like '%WAIT%' and

datediff(mi, last_batch,getdate()) > 1

order by last_batch

Here’s sample output, it shows the backup running and a batch job that has been going for 5 minutes app server MSSAP32 Batch Process (BTC) 20.

.

exec boe_proc

minutesspidwaittype cpuphysical_iospidlast_batchcmd

----------- ------ -------- ----------- -------------------- --------------- --------------- -------------------- ------ ------------------------------------------------------ ----------------

3891500x042224247296929618MSSAP01R3D03(3) unc rd May9 20026:05PM1502002-05-09 11:36:02.040SELECT

6516870x000028755756332MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000638285756332MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000623915756332MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000592815756332MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000297035756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

65 16870x0000279845756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000296715756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000336415756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000309225756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000308595756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000284385756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000307035756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000287815756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000287195756333MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000293595756334MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6516870x0000308445756334MSSAP99SQLAgent - TSQL May9 20026:05PM16872002-05-09 17:00:03.267BACKUP DATABASE

6514670x0800746750212792823MSSAP32R3B14(3) unc rd May9 20026:05PM14672002-05-09 17:00:28.953SELECT

3513330x0800600630213123578MSSAP31R3B17(3) unc rd May9 20026:05PM13332002-05-09 17:30:26.043SELECT

515030x02086433006526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x040480786526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x042280316526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x040480006526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x040474536526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x040479066526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

515030x040477506526323MSSAP32R3B20(3) unc rd May9 20026:05PM15032002-05-09 18:00:30.493SELECT

(26 row(s) affected)


Viewing all articles
Browse latest Browse all 20

Trending Articles