Distribution1:Distribution Reader
在事务复制中,在发布服务器中执行了一个更新,例如:update orders set col=? Where ?,该操作产生大量的数据更新操作,在Log Reader存储事务和命令时,把该更新操作分解成多条command,每一个command只更新一条record,这些command 位于同一个Transaction中。发布服务器执行命令的基本单元是一个事务,或者一个子事务。当一个事务包含的命令过多时,可以把一个事务拆分成多个子事务,使得每个子事务只包含特定数量的command。这样,分发服务器在把一个子事务准备就绪后,就可以执行该子事务中的命令,循环该过程,最终把整个事务中完成。
在事务复制中,事务的顺序必须得到保证。事务在订阅者和发布者中的执行顺序是相同的,换句话说,订阅者接收事务的顺序和发布者执行事务的顺序是一致的。
Distribution Agent包含两个子进程,Reader和Writer。 Reader负责从distribution 数据库中读取数据,Writer负责将reader读取的数据写入到订阅数据库。Reader是通过 sys.sp_MSget_repl_commands 来读取Distribution数据库中挂起(pending)的命令和事务(读取Msrepl_transactions表和Msrepl_Commands表),并把读取到的数据存储到内部队列中。Writer从队列中顺序获取命令,通过执行以sp_MSupd…, sp_MSins…, sp_MSdel…为前缀的存储过程,把队列中的命令依次写入到subscriber,换句话说,把数据更新的命令在订阅服务器中重新执行一遍。
CREATE PROCEDURE sys.sp_MSget_repl_commands
@agent_id int,
@last_xact_seqno varbinary(16),
@get_count tinyint = 0, -- 0 = no count, 1 = cmd and tran (legacy), 2 = cmd only
@compatibility_level int = 7000000,
@subdb_version int = 0,
@read_query_size int = -1
对Reader进行调优
案例:在Distribution Agent同步数据时,发现Subscriber中有很多Session处于 ASYNC_NETWORK_IO等待状态,该Session正在执行的sp是:sys.sp_MSget_repl_commands,正在执行的语句如下,这条查询用于返回Distribution Agent读取的Commands。
select rc.xact_seqno, rc.partial_command, rc.type,
rc.command_id, rc.command, rc.hashkey,
-- extra columns for the PeerToPeer resultset
-- originator_id, srvname, dbname, originator_publication_id, originator_db_version, originator_lsn
NULL, NULL, NULL, NULL, NULL, NULL, rc.article_id
from MSrepl_commands rc with (nolock, INDEX(ucMSrepl_commands))
inner join dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
-- At end, we use the FASTFIRSTROW option which tends to force
-- a nested inner loop join driven from MSrepl_commands
ON (rc.article_id = s.article_id)
where s.agent_id = @agent_id and
rc.publisher_database_id = @publisher_database_id and
rc.xact_seqno > @last_xact_seqno and
rc.xact_seqno <= @max_xact_seqno and
(rc.type & @snapshot_bit) <> @snapshot_bit and
(rc.type & ~@snapshot_bit) not in ( 37, 38 )
and (@compatibility_level >= 9000000
or (rc.type & ~@postcmd_bit) not in (47))
order by rc.xact_seqno, rc.command_id asc
OPTION (FAST 1)
说明该Session返回的数据集太大,导致Writer不能及时读取Command,使得分发的时延增加。
1,查看正在分发的事务
通过SQL Server Profile抓取当前正在执行的SQL命令,从抓取的大量语句中发现,sp_MSget_repl_commands 一般只会用到前四个参数,第三个和第四个参数的值是固定不变的,分别是0和10000000。
exec sp_MSget_repl_commands 74,0x0008ECE200307E10014C00000000,0,10000000
2,Distribution Agent 读取的Commnd数量
sys.sp_MSget_repl_commands 返回的Result Set的大小跟变量 @max_xact_seqno 有关
rc.xact_seqno > @last_xact_seqno and rc.xact_seqno <= @max_xact_seqno
对变量 @max_xact_seqno 的赋值,是由 @read_query_size 参数控制的,在调用该sp时,其值是默认值-1。
下面代码表示 将 dbo.MSrepl_commands 最大的 xact_seqno 赋值给变量@max_xact_seqno,那么Distribution Agent 每次都会读取所有的Command。
--Note4: The max_xact_seqno is calculated based on the @read_query_size parameter -
-- this parameter limit the number of commands retrieved by this call.
if(@read_query_size <= 0)
begin
select @max_xact_seqno = max(xact_seqno) from MSrepl_commands with (READPAST)
where
publisher_database_id = @publisher_database_id and
command_id = 1 and
type <> -2147483611
end
else ....
3,是否可以修改参数 @read_query_size的值
明确为@read_query_size传递一个参数值,而不是使用默认值 -1,可以解决这个问题,但是该sp是系统存储过程,不能直接修改,而Distribution Agent profile中也没有参数能够控制Reader读取的Command数量。
┬_┬
遇到这种情况,就需要换种角度来思考,长时间出现ASYNC_NETWORK_IO,根本原因是一个Trasaction中包含的Command过多,而数据更新的速度跟不上。如果在源头把一个事务拆分成多个子事务,每个子事务可以很快地执行完成。
如果Log Reader将大事务拆分成多个小的Transaction写入到Distribution中,那么Distribution Reader很快地把commands读取,写入到in-memory queue中,进而 Distribution Writer很快把 Queued Commands 写入到Subscriber中,完成数据的一次同步。只要Distribution Reader的读取速度能够跟上Log Reader写入的速度,而Distribution Writer的写入速度也能跟上Distribution Reader的读取速度,这样Distribution Latency 就会很小。
参考文档:
Performance Tuning SQL Server Transactional Replication – Part 1
SQL Server复制系列4 – Transactional replication中如何跳过一个事务
Distribution1:Distribution Reader的更多相关文章
- Replication:Distribution Reader
在transactional replication中,在publication中执行了一个更新,例如:update table set col=? Where ?,如果table中含有大量的数据行, ...
- Distribution2:Distribution Writer
Distribution Writer 调用Statement Delivery 存储过程,将Publication的改变同步到Subscriber中.查看Publication Properties ...
- 简单的Windows Webcam应用:Barcode Reader
原文:简单的Windows Webcam应用:Barcode Reader 在Windows上用WinForm创建一个Webcam应用需要用到DirectShow.DirectShow没有提供C#的接 ...
- 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D:Distribution in Metagonia(构造)
http://codeforces.com/gym/100801/attachments 题意:给出一个数n(1 <= n <= 1e18),将 n 拆成 m 个整数,其中 m 必须是 2 ...
- Replication:distribution 中一直在运行 waitfor delay @strdelaytime 语句
Replication 自动创建来一个 Job:Replication monitoring refresher for distribution,这个Agent执行一个sp: dbo.sp_repl ...
- CVE-2012-0774:Adobe Reader TrueType 字体整数溢出漏洞调试分析
0x01 TrueType 字体 TTF 字体是 Apple 和 Microsoft 两家公司共同推出的字体格式,现在已经广泛的运用于 Windows 操作系统,其中 PDF 文档也可以嵌入 TTF ...
- 例子:RSS Reader Sample
本例演示了Rss xml信息的获取,以及如何使用SyndicationFeed来进行符合Rss规范的xml进行解析. SyndicationFeed 解析完成后 可以得到SyndicationItem ...
- Gym - 100801D:Distribution in Metagonia (数学)
题意:给定一个N,让你把它拆成若干个只含素因子2和3的数之和,且两两之间没有倍数关系,比如10=4+6. 思路:即是2因子的幂递增,3因子的幂递减:或者反之. 对于当前N,我们拆分出的数为num=2^ ...
- Scalaz(15)- Monad:依赖注入-Reader besides Cake
我们可以用Monad Reader来实现依赖注入(dependency injection DI or IOC)功能.Scala界中比较常用的不附加任何Framework的依赖注入方式可以说是Cake ...
随机推荐
- iOS 使点击事件穿透透明的UIView
如图: 悬浮的三个按钮下方有一个可以点击的灰色区域,但是点击按钮之间的透明区域, 这三个按钮的contentView会响应这个点击事件,这时候需要让这个contentView不响应这个点击事件. 解决 ...
- MCMC 、抽样算法与软件实现
一.MCMC 简介 1. Monte Carlo 蒙特卡洛 蒙特卡洛方法(Monte Carlo)是一种通过特定分布下的随机数(或伪随机数)进行模拟的方法.典型的例子有蒲丰投针.定积分计算等等,其基础 ...
- jQuery.rotate.js参数
CSS3 提供了多种变形效果,比如矩阵变形.位移.缩放.旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动.然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(fil ...
- php备份数据库
php备份数据库原理和方法 原理 查找所有表 查找所有字段,列出所有字段名 字段类型等信息 查找所有数据 读取后注意特殊符号转换addslashes() 生成sql 把数据库格式化生成对应sql 相关 ...
- REGEXP 正则的实现两个字符串组的匹配。(regexp)
主要懂3个mysql的方法:replace[替换] regexp[正则匹配] concat[连接] 由于某些原因,有时候我们没有按照范式的设计准则而把一些属性放到同一个字符串字段中.比如 ...
- map<虽然一直不喜欢map>但突然觉得挺好用的
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #inc ...
- Attention:本博客暂停更新
Attention:本博客暂停更新 2016年11月17日08:33:09 博主遗产 http://www.cnblogs.com/radiumlrb/p/6033107.html Dans cett ...
- CentOS搭建SVN记录
1.安装subversion(client and server) $ yum install subversion $ yum install mod_dav_svn 安装成功之后使用 svnser ...
- Artifact Project3:war exploded: Error during artifact deployment. See server log for details.
第一次建Struts2 idea遇到了这个问题,很莫名其妙,搞了几天没解决,几乎要放弃idea了.最后解决的时候也很突然.回想解决的过程,大致如下. 第一种情况:File->Project St ...
- CentOS安装配置redis
安装前准备,安装gcc 先用 gcc -v命令检测本机是否安装gcc,如果没有则用下面命令安装: yum install cpp yum install binutils yum install gl ...