SQL Replication SubscriptionStreams Setting
SQL Replication SubscriptionStreams Setting
In this blog, we will talk about improving distribution agent throughput by modifying the profile
parameter – “SubscriptionStreams”. I will be discussing a few real time scenarios where I
implemented the parameter to isolate latency issue between Distributor and Subscriber.
In your environment, you found that there are a few millions of rows that need to be
replicated from Distributor to Subscriber(s). When you check out the replication monitor,
it says that it’s going to take one or more days to replicate the data at the Subscriber(s).
But, the business demand is to sync the data ASAP.
You have a business requirement to reduces the latency when moving data from
Distributor to Subscriber.
First of all, you might be wondering what can cause the latency issue between Distributor to
Subscriber. Right?? There could be a bunch of reasons like;
The rate of incoming transactions from Publisher is too high where the subscriber is not
able to handle that transaction fast enough.
Blocking
Stale Statistics
Slow Disk Drives
Slow Network Bandwidth
Deadlock……the list goes on and on…
The question is – how would you deal the latency issue between Distributor and
Subscriber without re-initializing the replication? That’s where you can utilize the SQL
Replication SubscriptionStreams parameter.
This parameter helps to reduce the latency when moving data from Distributor to Subscriber by
using multiple parallel writer threads. It is only applicable for Distribution Agent. It is also
known as Distribution Agent SubscriptionStreams parameter.
Boon
If the incoming transaction rate from Publisher is too high and you feel that one single
thread for Distribution agent is not capable enough to catch up all the incoming
transactions fast enough, you can consider using the SubscriptionStreams parameter.
After working with storage team, you figured out that latency is coming from Distributor
to Subscriber because of slow disk. You may find enabling SubscriptionStreams
parameter helpful.
You can also consider enabling the parameter, if you find the latency because of network
slowness issue.
Curse
If you find a considerable number of deadlocks are happening at Subscriber and the
tables which are involved in the deadlock are also part of incoming replication,
enabling the SubscriptionStreams parameter may make the situation worse.
If you find blocking at Subscriber, increasing the number of concurrent connections
won’t help but might make the situation more bad.
If one of the connections fails to execute or commit at subscriber side, all connections will abort
the current batch, and the agent will use a single stream to retry the failed batches. You will have
to set it again back to multiple streams. Let’s take the example of above eight connection
(SPIDs) – If any one of the SPIDs fails to execute or commit at subscriber side, all connections
will abort the current batch, and the agent will use a single stream to retry the failed batches.
To figure out what error caused SubscriptionStreams to reset from multiple streams to single
stream, you have to enable Verbose Log parameter in the distribution agent to get the agent
log. Below is parameter which you can directly enable in the distribution agent job;
Refer the below captured verbose log to have better understanding on resetting of
SubscriptionStreams streams.
15:33:41.890, ‘ERROR CONVERTING CHARACTER DATA TO UNICODE’, ‘ERROR CONVERTING CHARACTER DATA
CHARACTER DATA TO UNICODE’} 2017-10-14 08:45:35.961 NUMBER OF SUBSCRIPTION STREAMS HAS BEEN
This is one of the advanced settings of replication. Hence I would suggest you to do a thorough
testing before implementing this to production.