码迷,mamicode.com
首页 > 其他好文 > 详细

调整Replication Agent Profile的参数

时间:2016-07-30 13:21:19      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

在Transactional Replication 中,Tracking changes 的实现机制是记录进度日志,即 history log,distributing data 分为读取和分发,分别是用 LogReader Agent 和 Distribution Agent 来实现。由于Replication使用 stand-alone programs(即 .exe file,或 executables)来实现,通过配置Agent Profile的参数,能够微调Replication的行为,使其更适合实际的Production Environment。

Replication uses many stand-alone programs, which are named "agents," to perform the tasks associated with tracking changes and distributing data. This section of the documentation contains parameter references for the following replication agents.

The behavior of each replication agent is controlled by a set of parameters that can be set through agent profiles. Each agent has a default profile, and some have additional predefined profiles; at a given time, only one profile is active for an agent.

 

Agent Profile 定义了Agent的参数和参数值的集合,每次Agent 运行时,读取Agent Profile中定义的参数值。

By default, replication agents run under Microsoft SQL Server Agent job steps. The agents are simply executables, so they can also be called directly from the command line and from batch scripts. Each replication agent supports a set of run-time parameters used to control how it runs; these parameters are specified in an agent profile or on the command line.

When replication is configured, a set of agent profiles is installed on the Distributor. An agent profile contains a set of parameters that are used each time an agent runs: each agent logs in to the Distributor during its startup process and queries for the parameters in its profile. Replication provides a default profile for each agent and additional predefined profiles for the Log Reader Agent, Distribution Agent, and Merge Agent. In addition to the profiles provided, you can create profiles suited to your application requirements.

 

事务复制用于数据仓库时,由于每天更新的数据量庞大,必须对Replication做些微调,主要从日志记录和数据分发两块入手,使其工作更有效率。

一,微调 Log Reader Agent

Replication Log Reader Agent Profile参数示例

1,轮询间隔(Poll Interval),用于检查Log File中是否存在标记为Replication 的Transaction 和 Commands.

-Continuous  

Specifies whether the agent tries to poll replicated transactions continually. If specified, the agent polls replicated transactions from the source at polling intervals even if there are no transactions pending.

-PollingInterval  polling_interval                       

Is how often, in seconds, the log is queried for replicated transactions. The default is 5 seconds.

2,控制进度消息的数量(Verbose Level)和记录消息的时间间隔(Message Interval)

-HistoryVerboseLevel [ 1| 2]  

Specifies the amount of history logged during a log reader operation. You can minimize the performance effect of history logging by selecting 1.

HistoryVerboseLevel

Description

1                    

Default. Always update a previous history message of the same status (startup, progress, success, and so on). If no previous record with the same status exists, insert a new record.

2                    

Insert new history records unless the record is for such things as idle messages or long-running job messages, in which case update the previous records.

-MessageInterval  message_interval   

Is the time interval used for history logging. A history event is logged when the MessageInterval value is reached after the last history event is logged.

If there is no replicated transaction available at the source, the agent reports a no-transaction message to the Distributor. This option specifies how long the agent waits before reporting another no-transaction message. Agents always report a no-transaction message when they detect that there are no transactions available at the source after previously processing replicated transactions. The default is 60 seconds.

-KeepAliveMessageInterval  keep_alive_message_interval_seconds  

Is the number of seconds before the history thread checks if any of the existing connections is waiting for a response from the server. This value can be decreased to avoid having the checkup agent mark the Log Reader Agent as suspect when executing a long-running batch. The default is 300 seconds.

3,控制Transaction 和 Command的读取

如果一个Transaction含有海量Commands,Replication在同步数据时,Latency会很高。-MaxCmdsInTran 控制LogReader在向Distribution写入Commands时,将一个大的Transaction拆分成多个小的Transaction fraction,每个Transaction fraction 含有指定数量的Commands。将Original Transaction拆分成多个小transaction fraction,打破Original Transaction的边界。在将Commands推送到subscriber时,每个小 Transaction fraction 都是一个独立的单元,将Original Transaction拆分成多个Batch同步到Subscriber,有利于快速同步数据。

-MaxCmdsInTran number_of_commands   

Specifies the maximum number of statements grouped into a transaction as the Log Reader writes commands to the distribution database. Using this parameter allows the Log Reader Agent and Distribution Agent to divide large transactions (consisting of many commands) at the Publisher into several smaller transactions when applied at the Subscriber. Specifying this parameter can reduce contention at the Distributor and reduce latency between the Publisher and Subscriber. Because the original transaction is applied in smaller units, the Subscriber can access rows of a large logical Publisher transaction prior to the end of the original transaction, breaking strict transactional atomicity. The default is 0, which preserves the transaction boundaries of the Publisher.

 

在一个处理周期中,LogReader从Publisher database的Log Files中,一次最多读取的Transaction的最大数量。

-ReadBatchSize number_of_transactions  

Is the maximum number of transactions read out of the transaction log of the publishing database per processing cycle, with a default of 500. The agent will continue to read transactions in batches until all transactions are read from the log. This parameter is not supported for Oracle Publishers.

-ReadBatchThreshold number_of_commands   

Is the number of replication commands to be read from the transaction log before being issued to the Subscriber by the Distribution Agent. The default is 0. If this parameter is not specified, the Log Reader Agent will read to the end of the log or to the number specified in -ReadBatchSize (number of transactions).

 

二,微调 Distribution Agent

Replication Distribution Agent 参数 和 Log Reader Agent的参数大致相同

1,轮询 和 Poll Interval

-Continuous

Specifies whether the agent attempts to poll replicated transactions continually. If specified, the agent polls replicated transactions from the source at polling intervals, even if there are no transactions pending.

-PollingInterval  polling_interval                       

Is how often, in seconds, the distribution database is queried for replicated transactions. The default is 5 seconds.

 

在一次sync中处理的Transaction的最大数量,如果到达最大数量,那么Distribution Agent将停止运行,必须手动restart。

-MaxDeliveredTransactions number_of_transactions                        

Is the maximum number of push or pull transactions applied to Subscribers in one synchronization. A value of 0 indicates that the maximum is an infinite number of transactions. Other values can be used by Subscribers to shorten the duration of a synchronization being pulled from a Publisher.

If -MaxDeliveredTransactions and -Continuous are both specified, the Distribution Agent delivers the specified number of transactions and then stops (even though -Continuous is specified). You must restart the Distribution Agent after the job completes.

 

2,控制进度消息写入的数量(Verbose Level)和消息记录的时间间隔(Message Interval)

-HistoryVerboseLevel[ 0 | 1 | 2 | 3 ]           

Specifies the amount of history logged during a distribution operation. You can minimize the performance effect of history logging by selecting 1.

HistoryVerboseLevel

Description

0                    

Progress messages are written either to the console or to an output file. History records are not logged in the distribution database.

1                    

Default. Always update a previous history message of the same status (startup, progress, success, and so on). If no previous record with the same status exists, insert a new record.

2                    

Insert new history records unless the record is for such things as idle messages or long-running job messages, in which case update the previous records.

3                    

Always insert new records, unless it is for idle messages.

-MessageInterval message_interval  

Is the time interval used for history logging. A history event is logged when one of these parameters is reached:

  • The TransactionsPerHistory value is reached after the last history event is logged.

  • The MessageInterval value is reached after the last history event is logged.

If there is no replicated transaction available at the source, the agent reports a no-transaction message to the Distributor. This option specifies how long the agent waits before reporting another no-transaction message. Agents always report a no-transaction message when they detect that there are no transactions available at the source after previously processing replicated transactions. The default is 60 seconds.

-KeepAliveMessageInterval keep_alive_message_interval_seconds  

Is the number of seconds before the history thread checks if any of the existing connections is waiting for a response from the server. This value can be decreased to avoid having the checkup agent mark the Distribution Agent as suspect when executing a long-running batch. The default is 300 seconds.

 

在同步到一定数量的Transaction之后,触发日志记录事件,记录一条进度消息。

-TransactionsPerHistory[ 0| 1|... 10000]           

Specifies the transaction interval for history logging. If the number of committed transactions after the last instance of history logging is greater than this option, a history message is logged. The default is 100. A value of 0 indicates infinite TransactionsPerHistory. See the preceding –MessageInterval parameter.

3,控制Transaction 和 Command的同步

-CommitBatchSize  commit_batch_size 

Is the number of transactions to be issued to the Subscriber before a COMMIT statement is issued. The default is 100.

-CommitBatchThreshold   commit_batch_threshold 

Is the number of replication commands to be issued to the Subscriber before a COMMIT statement is issued. The default is 1000.

4,发布类型

-SubscriptionType[ 0| 1| 2]           

Specifies the subscription type for distribution. A value of 0 indicates a push subscription, a value of 1 indicates a pull subscription, and a value of 2 indicates an anonymous subscription.

 

三,参数Agent Profile 的参数

1,通过 msdb.dbo.MSagent_profiles 和 msdb.dbo.MSagent_parameters 查看每个Agent的Profile 及其参数设置

select 
    case prof.agent_type
        when 1 then Snapshot Agent
        when 2 then Log Reader Agent
        when 3 then Distribution Agent
        when 4 then Merge Agent
        when 9 then Queue Reader Agent
        else ‘‘
    end as agent_type,
    prof.profile_name,
    prof.type as IsSystemProfile,
    prof.def_profile as isDefaultProfile,

    para.parameter_name,
    para.value as parameter_value,
    prof.description
from msdb.dbo.MSagent_profiles prof
inner join  msdb.dbo.MSagent_parameters para
    on prof.profile_id=para.profile_id
where prof.agent_type=2
    and prof.profile_name=Custom Profile
order by agent_type

2,使用sp添加参数

通过Distributor Properties 修改Agent Profile的参数有限,必要时,使用使用 sp_add_agent_parameter 增加参数,使用 sp_change_agent_parameter  修改参数值

sp_add_agent_parameter [ @profile_id = ] profile_id
        , [ @parameter_name = ] parameter_name 
        , [ @parameter_value = ] parameter_value 

sp_change_agent_parameter [ @profile_id= ] profile_id
        ,[ @parameter_name= ] parameter_name
        , [ @parameter_value= ] parameter_value

 

参考doc:

Replication Agents

sp_add_agent_profile (Transact-SQL) 

sp_add_agent_parameter (Transact-SQL)

sp_change_agent_parameter (Transact-SQL)

调整Replication Agent Profile的参数

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/5719669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!