Newsflash

Most of the SQL Developers/DBA would have come across a situation where they need to store the temporary result sets. This is where Temp tables and Table variables come into effect and helps in storing the data sets in a temporary location.

(0 votes, average 0 out of 5)
Share/Save/Bookmark

This script can be used to measure Latency in your Replication Subsystem. This script does not use TRACER TOKENS and there would be no negative impact to the system's performance.

USE [distribution] 
GO
/****** Object: StoredProcedure [dbo].[usp_latencymonitor] Script Date: 01/20/2010 22:31:24 ******/
SET ANSI_NULLS ON 
GO
SET UOTED_IDENTIFIER ON 
GO
create procedure [dbo].[usp_latencymonitor] 
as
begin
--Written by Sugeshkumar Rajendran Dated 01/20/2010
create table #latency_monitor(pubdb varchar(100),publication varchar(100),subdb varchar(100),distagent varchar(300),distcntrvalue int NULL,logagent varchar(300),logcntrvalue int NULL) 
insert into #latency_monitor(pubdb,publication,subdb,distagent,logagent) 
select a.publisher_db,a.publication,a.subscriber_db,  a.name as 'DistAgent',b.name as 'LogreaderAgent' 
from dbo.MSdistribution_agents a, dbo.MSlogreader_agents b 
where a.publisher_db=b.publisher_db 
--select * from #latency_monitor
declare @distagent varchar(300) 
declare @logagent varchar(300) 
declare @distcntr int 
declare @logcntr int 
DECLARE replmonitor CURSOR FOR 
select a.name as 'DistAgent',b.name as 'LogreaderAgent' 
from dbo.MSdistribution_agents a, dbo.MSlogreader_agents b 
where a.publisher_db=b.publisher_db 
OPEN replmonitor 
FETCH
NEXT FROM replmonitor into @distagent,@logagent 
WHILE @@FETCH_STATUS = 0 
BEGIN
select @distcntr=cntr_value from sys.dm_os_performance_counters 
where 
object_name like '%Replication%' 
and
counter_name like '%Latency%' and ltrim(rtrim(instance_name)) = ltrim(rtrim(@distagent)) 
select @logcntr=cntr_value from sys.dm_os_performance_counters 
where object_name like '%Replication%' 
and counter_name like '%Latency%' and ltrim(rtrim(instance_name)) = ltrim(rtrim(@logagent)) 
update #latency_monitor set logcntrvalue = @logcntr where ltrim(rtrim(logagent)) = ltrim(rtrim(@logagent)) 
update #latency_monitor set distcntrvalue = @distcntr where ltrim(rtrim(distagent)) = ltrim(rtrim(@distagent)) 
FETCH
NEXT FROM replmonitor intO @distagent,@logagent 
END
CLOSE replmonitor 
DEALLOCATE replmonitor 
select * from #latency_monitor 
drop table #latency_monitor 
end

Comments  

 
#6 2010-02-02 01:56
i tried select
pubdb
,publication
,subdb
,distagent,
--CONVERT(VARCHAR (8), DATEADD(ss, distcntrvalue, 0) ,114),

CONVERT(VARCHAR (8), DATEADD(ms, distcntrvalue * 1000, 0), 114)
logagent,

--CONVERT(VARCHAR (8), DATEADD(ss, logcntrvalue, 0) ,114)
CONVERT(VARCHAR (8), DATEADD(ms, logcntrvalue * 1000, 0) ,114)

from #latency_monito r
drop table #latency_monito r

and i still get more latency of what the replication monitor latency column says...
Quote
 
 
#5 2010-02-01 20:39
Quoting jessi:
i did it by using select
pubdb
,publication
,subdb
,distagent,
CONVERT(VARCHAR (8), DATEADD(ss, distcntrvalue, 0) ,114),
logagent,

CONVERT(VARCHAR (8), DATEADD(ss, logcntrvalue, 0) ,114)

from #latency_monito r
drop table #latency_monito r

at the end, but i get very high number not as what the replication monitor reflects as latency :(


Jessi,

the values that you see there are in milliseconds, you need to convert it into seconds and then do your manipulation to the desired result.
Quote
 
 
#4 2010-02-01 13:47
i did it by using select
pubdb
,publication
,subdb
,distagent,
CONVERT(VARCHAR (8), DATEADD(ss, distcntrvalue, 0) ,114),
logagent,

CONVERT(VARCHAR (8), DATEADD(ss, logcntrvalue, 0) ,114)

from #latency_monito r
drop table #latency_monito r

at the end, but i get very high number not as what the replication monitor reflects as latency :(
Quote
 
 
#3 2010-02-01 13:17
hi thanks for your reply, is there any way to put those columns into 00:00:00 format? i tried by i don't get the same results as the replication monitor maybe i am doing something wrong..
Quote
 
 
#2 2010-01-30 13:53
Hi Jessi,

The columns distcntrvalue and log cntrvalue are the latency values for distributor and log reader respectively. Let me know if you have more questions. Also, if you are in need of more scripts in replication, let me know I can script tham and post here.
Quote
 
 
#1 2010-01-30 09:06
hi which one is your latency column?
Quote
 

Add comment


Security code
Refresh