From 903789aee4f69343b47e02eb3b10787b04ed3ee4 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 23 Apr 2014 12:21:34 -0700 Subject: [PATCH] agent: Adding random stagger to anti-entropy. Fixes #72. --- command/agent/local.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/command/agent/local.go b/command/agent/local.go index 9254564bf2..540e29b9a6 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -11,7 +11,8 @@ import ( ) const ( - syncRetryIntv = 30 * time.Second + syncStaggerIntv = 3 * time.Second + syncRetryIntv = 15 * time.Second ) // syncStatus is used to represent the difference between @@ -223,7 +224,13 @@ SYNC: l.logger.Printf("[ERR] agent: failed to sync remote state: %v", err) select { case <-l.consulCh: - case <-time.After(aeScale(syncRetryIntv, len(l.iface.LANMembers()))): + // Stagger the retry on leader election, avoid a thundering heard + select { + case <-time.After(randomStagger(aeScale(syncStaggerIntv, len(l.iface.LANMembers())))): + case <-shutdownCh: + return + } + case <-time.After(randomStagger(aeScale(syncRetryIntv, len(l.iface.LANMembers())))): case <-shutdownCh: return }