Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Spikes in CPU/SQL Server connections slow

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-09-20 : 08:57:14
Jason writes "I have a SQL 2K server that is being used by about 30 clients and at certain times, the CPU goes through the use. Need to know how I can track down what or who is causing that. Any suggestions?

About the same time every day, my SQL server gets really busy and my clients get real slow connectings. I'm monitoring what I know to monitor, Memory, Hard Drives, Processor and two SQL items. Got that from;
http://www.sql-server-performance.com/sql_server_performance_audit.asp
(good site)

At this point, I'd really appreciate any ideas. This is realy driving me nuts."

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-09-20 : 11:11:35
You can use profiler to see what's going on at the time , however I find it more useful to find the spid(s) that are using the most resource e.g. CPU,IO,MEM that way i can then use DBCC INPUTBUFFER(spid) or check the profiler trace to see what they are doing. I use a procedure called sp_spidtop10 I wrote to see who the resource hogs are. It defaults to top 10 CPU bur can also do IO and MEM - it defaults to 2 snapshots 30 seconds apart to calculate the resource usage.


use master
go

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_spidtop10]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)

drop procedure [dbo].[sp_spidtop10]
GO

CREATE PROCEDURE sp_spidtop10 (@order varchar(3) ='CPU',
@spid int = NULL,
@interval int = NULL)
AS
/*
Procedure to show top 10 resource using SPID's
based on a passed in order value (default CPU)
or view the resource usage of one spid, for a
period of 30 seconds (default)

Change Description Author Date
Initial Creation J Smith 10 Sep 2001

*/

SET NOCOUNT ON

DECLARE @cinterval char(8)

IF @interval IS NOT NULL
BEGIN
IF @interval > 59 SET @interval = 59 /* max period */
SET @cinterval = '00:00:' + CAST(@interval as char(2))
END
ELSE
BEGIN
SET @cinterval = '00:00:30' /* default period */
END

CREATE TABLE #thread (RUN INT NOT NULL,
SPID INT NOT NULL,
THREAD INT NULL,
STATUS varchar(30) NOT NULL,
[IO] INT NOT NULL,
CPU INT NOT NULL,
MEM INT NOT NULL,
LOCKS int NOT NULL,
BLK INT NOT NULL

CONSTRAINT PK_thread1 PRIMARY KEY CLUSTERED
(RUN,SPID))

/* Initial snapshot */
INSERT #thread
SELECT 1,pr.spid,pr.kpid,pr.status,pr.physical_io,pr.cpu,
pr.memusage,ISNULL(count(lk.spid),0),pr.blocked
FROM master.dbo.sysprocesses pr
LEFT OUTER JOIN master.dbo.syslocks lk ON pr.spid = lk.spid
WHERE pr.spid>=50 AND pr.spid<>@@SPID
AND (@spid is NULL OR pr.spid=@spid)
GROUP BY pr.spid,pr.kpid,pr.status,pr.physical_io,
pr.cpu,pr.memusage,pr.blocked


/* controlled by @interval parameter */
WAITFOR DELAY @cinterval


/* Secondary snapshot */
INSERT #thread
SELECT 2,pr.spid,pr.kpid,pr.status,pr.physical_io,pr.cpu,
pr.memusage,ISNULL(count(lk.spid),0),pr.blocked
FROM master.dbo.sysprocesses pr
LEFT OUTER JOIN master.dbo.syslocks lk ON pr.spid = lk.spid
WHERE pr.spid>=50 AND pr.spid<>@@SPID
AND (@spid is NULL OR pr.spid=@spid)
GROUP BY pr.spid,pr.kpid,pr.status,pr.physical_io,
pr.cpu,pr.memusage,pr.blocked


/* Get the top 10 ordered by @order (default CPU) */
SELECT TOP 10 T.*
FROM(
SELECT a.SPID,b.THREAD,b.STATUS,(b.[IO]-a.[IO]) as 'IO',
(b.CPU-a.CPU) as 'CPU',(b.MEM-a.MEM) as 'MEM',
b.LOCKS,b.BLK
FROM #thread a
JOIN #thread b
ON a.SPID=b.SPID and a.RUN=1 and b.RUN=2) T
ORDER BY CASE @order
WHEN 'IO' THEN [IO]
WHEN 'CPU' THEN CPU
WHEN 'MEM' THEN MEM
WHEN 'LCK' THEN LOCKS
ELSE CPU END DESC

DROP TABLE #thread

RETURN
GO



Edited by - jasper_smith on 09/20/2002 11:15:16
Go to Top of Page
   

- Advertisement -