How do I interpret sp_who2 results?

  • I have been looking around at various articles and threads and in SQL Server 2005 Tutorial and have not come across the answers I need.

    I know CPUTime is in milliseconds and DiskIO is about read and writes in bytes.

    I have a couple SPIDs that are taking a long time and sometimes their status is SUSPENDED. Why would a SPID be marked as suspended? That SPID is not being blocked.

    The CPUTime on this SPID is 6047344 and the DiskIO is 394101.

    Another SPID has CPUTime of 6087203 and DiskIO of 683344 and has a status of RUNNABLE.

    Both have been running for over an hour.

    Does any of this indicate that the server can't handle the queries? Could the reason the status be set to suspended be because there are too many read and writes going on and the hard drive can't handle it?

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • SUSPENDED generally means the process is waiting on something that is not being done by MSSQL. For instance, if a long running process is waiting for the operating system to return something being read from disk and it take awhile, the process may be suspended while SQL waits for the operating system. Since the process is not under the control of the SQL server, it suspends the process until whatever it is waiting for is done.

    I have seen this come up a few times while TempDB is expanding or a huge query is trying to pull a lot of data from a busy disk drive.

    I also seem to remember this happening sometimes with linked servers waiting for the remote server to process something, but that part of my memory seems to be a bit fuzzy right now.

  • Thanks for your reply. I know there are no linked servers being used so it won't be that. I suspect the hard drive and yes the two stored procedures being run by the two SPIDs pull a lot of data and then performs inserts and updates.

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • And does anyone know why sometimes I see more than one row for a particular SPID. For example I have one now that has 9 rows for one SPID. All I remember is that it has something to do with threads and/or paralelism, but I am pretty sure that server does not have 9 processors.

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • Hi Robert,

    have you tried querying sys.dm_os_waiting_tasks to see what the wait types are for the SPIDs?

    K. Brian Kelley
    @kbriankelley

  • along the same line....try using this script to tell your most expensive users for the past minute. It will review the processes and tell you who is using the most CPU over the past minute.

    create procedure [dbo].[cspWhoCPU]

    as

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##FirstLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    waitfor delay '00:01:00'

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##SecondLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    Selectb.DatabaseName, b.spid, b.status, b.loginame,

    b.nt_UserName, b.hostName, b.Program_name, b.spid,

    B.cpu - isnull(A.cpu,0) as MinuteCPU,

    b.cpu as TotCPU,

    b.Physical_io - isnull(a.physical_io,0) as MinuteIO,

    b.physical_IO as totIO,

    b.memusage - isnull(a.memusage,0) as MinuteMem,

    b.memusage as TotMem, b.blocked as BlkBy

    from ##firstLook a

    right outer join ##secondLook b

    on a.spid = b.spid

    and a.databasename = b.databaseName

    and a.loginame = b.loginame

    order by 9 desc,11 desc,13 desc

    --select * from ##firstLook

    --select * from ##secondLook

    drop table ##firstLook

    drop table ##SecondLook

  • along the same line....try using this script to tell your most expensive users for the past minute. It will review the processes and tell you who is using the most CPU over the past minute.

    create procedure [dbo].[cspWhoCPU]

    as

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##FirstLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    waitfor delay '00:01:00'

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##SecondLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    Selectb.DatabaseName, b.spid, b.status, b.loginame,

    b.nt_UserName, b.hostName, b.Program_name, b.spid,

    B.cpu - isnull(A.cpu,0) as MinuteCPU,

    b.cpu as TotCPU,

    b.Physical_io - isnull(a.physical_io,0) as MinuteIO,

    b.physical_IO as totIO,

    b.memusage - isnull(a.memusage,0) as MinuteMem,

    b.memusage as TotMem, b.blocked as BlkBy

    from ##firstLook a

    right outer join ##secondLook b

    on a.spid = b.spid

    and a.databasename = b.databaseName

    and a.loginame = b.loginame

    order by 9 desc,11 desc,13 desc

    --select * from ##firstLook

    --select * from ##secondLook

    drop table ##firstLook

    drop table ##SecondLook

  • along the same line....try using this script to tell your most expensive users for the past minute. It will review the processes and tell you who is using the most CPU over the past minute.

    create procedure [dbo].[cspWhoCPU]

    as

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##FirstLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    waitfor delay '00:01:00'

    Select d.name as 'DatabaseName', spid, p.status, cmd,

    p.loginame, nt_username, hostname, program_name,

    cpu, physical_io, memusage, blocked

    into ##SecondLook

    from master.sys.sysprocesses p (nolock)

    join master.sys.sysdatabases d (nolock)

    on p.dbid = d.dbid

    order by D.name, nt_username

    Selectb.DatabaseName, b.spid, b.status, b.loginame,

    b.nt_UserName, b.hostName, b.Program_name, b.spid,

    B.cpu - isnull(A.cpu,0) as MinuteCPU,

    b.cpu as TotCPU,

    b.Physical_io - isnull(a.physical_io,0) as MinuteIO,

    b.physical_IO as totIO,

    b.memusage - isnull(a.memusage,0) as MinuteMem,

    b.memusage as TotMem, b.blocked as BlkBy

    from ##firstLook a

    right outer join ##secondLook b

    on a.spid = b.spid

    and a.databasename = b.databaseName

    and a.loginame = b.loginame

    order by 9 desc,11 desc,13 desc

    --select * from ##firstLook

    --select * from ##secondLook

    drop table ##firstLook

    drop table ##SecondLook

  • That was some nice stuff.

    Your other question - the same spid multiple times. This is caused by parallel processing. Look up the MAX DOP or Max Degrees of Parallelism in books online.

    Also, if your query is waiting a long time in SUSPENDED and you think it is the hard drive, use perfmon to look at the drive usage before and during the query running to make sure. If that is the case, you are likely to have a problem with your query and need to resolve it.

  • The Performance_Dashboard reports are very helpful. They do a good job of drilling down.

    http://www.microsoft.com/downloads/details.aspx?FamilyId=1d3a4a0d-7e0c-4730-8204-e419218c1efc&displaylang=en

  • Thanks for all your help!:)

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • Hi,

    We have threads coming to sqlserver in diffrent forms(like querys etc) and sql server os handles it by assigning the cpu's(workers) to it when one thread(query) is waiting for the resource then sql server will keep this thread in suspend state untill it finds the resource and it moves to other thread in mean while that is in the queue once resource is available to that thread then it was kept in queue that is runnable state. presently executing thread is in running state

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply