delay and splay replication starts
This is a cherry-pick of:
https://github.com/cloudant/couch_replicator/commit/d279150d959cfd46cbd77c5dd17f14d6dc3d0291
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 17c766e..eefa0cd 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -454,7 +454,14 @@
true = ets:insert(?DOC_TO_REP, {{DbName, DocId}, RepId}),
couch_log:notice("Attempting to start replication `~s` (document `~s`).",
[pp_rep_id(RepId), DocId]),
- Pid = spawn_link(?MODULE, start_replication, [Rep, 0]),
+ StartDelaySecs = erlang:max(0,
+ config:get_integer("replicator", "start_delay", 10)),
+ StartSplaySecs = erlang:max(1,
+ config:get_integer("replicator", "start_splay", 50)),
+ DelaySecs = StartDelaySecs + random:uniform(StartSplaySecs),
+ couch_log:notice("Delaying replication `~s` start by ~p seconds.",
+ [pp_rep_id(RepId), DelaySecs]),
+ Pid = spawn_link(?MODULE, start_replication, [Rep, DelaySecs]),
State#state{rep_start_pids = [Pid | State#state.rep_start_pids]};
#rep_state{rep = #rep{doc_id = DocId}} ->
State;