SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Find Batch Requests/sec from SYSPERFINFO
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 01/02/2009 :  18:33:29  Show Profile  Reply with Quote
I ran into some problems trying to use table master.dbo.sysperfinfo to get the batch requests per second, and posted a question on this thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=117084

The reply from Mladen let me know that there was a known issue with these counters in SQL 2000 that was documented in this Knowledge Base Article:
BUG: sysperfinfo counters are not time-adjusted
http://support.microsoft.com/kb/555064

The problem is that all time based counters are aggregated values from the point in time that SQL Server starts.

The script below is a workaround that uses two queries with a time delay in between to capture the counter before and after the delay and then calculates the value from the difference divided by the number of seconds.

This script is for Batch Requests/sec, but the same idea could be used for any of the time based counters. By adjusting the @seconds parameter in the script, you can adjust the interval over which the value is calculated.



-- Find_Batch_Requests_Per_Second.sql

declare @cntr_value_1 	numeric(20,3)
declare @cntr_value_2 	numeric(20,3)
declare @seconds	int
declare @delay_time	varchar(12)

-- Set interval in seconds to measure the parameter
set @seconds = 5

-- Set the delay time parameter
set @delay_time = right(convert(varchar(30),dateadd(second,@seconds,0),121),12)

select
	@cntr_value_1 = cntr_value
from
	master.dbo.sysperfinfo
where 
	object_name	= 'SQLServer:SQL Statistics'	AND
	counter_name 	= 'Batch Requests/sec'

-- Wait for @delay_time
waitfor delay @delay_time

select
	@cntr_value_2 = cntr_value
from
	master.dbo.sysperfinfo
where 
	object_name	= 'SQLServer:SQL Statistics'	AND
	counter_name 	= 'Batch Requests/sec'

print	'Compute average Batch Requests/sec over time interval of '+
	convert(varchar(30),@seconds)+' seconds.'
select [Batch Requests/sec] =
	convert(numeric(20,3),round((@cntr_value_2-@cntr_value_1)/@seconds,3))


Results:
Compute average Batch Requests/sec over time interval of 5 seconds.
Batch Requests/sec     
---------------------- 
9.000

(1 row(s) affected)


CODO ERGO SUM
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000