From 6ab52449bde6617cdbae5e90af7b4737d176efaa Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Wed, 23 Jan 2019 08:37:56 -0500 Subject: [PATCH] Cherry-pick #10177 to 6.x: common.Backoff now implements jitter instead of sleeping for a fixed amount of time (#10229) Cherry-pick of PR #10177 to 6.x branch. Original message: This PR add a new interface called backoff.Backoff, this can be used to generalize any backoff interaction. It move the current Backoff strategy under an ExpBackoff type. ExpBackoff is the same as before on every wait we just exponentially increase the duration of the wait and sleep for that amount. EqualJitterBackoff uses an exponential increment of the duration but will take half of that value as fixed sleep time and the other half as a jitter. This will help distribute the new request when a cluster is done instead of having all the beats trying to reconnect at once. The Redis implementations and any clients wrapped with a backoff will now use the EqualJitterBackoff, any other code will keep using the same exponential strategy. Fixes: #10172 --- reader/journal.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reader/journal.go b/reader/journal.go index 8721bf34385..e67ad571a24 100644 --- a/reader/journal.go +++ b/reader/journal.go @@ -35,6 +35,7 @@ import ( "github.com/elastic/beats/journalbeat/config" "github.com/elastic/beats/libbeat/beat" "github.com/elastic/beats/libbeat/common" + "github.com/elastic/beats/libbeat/common/backoff" "github.com/elastic/beats/libbeat/logp" ) @@ -44,7 +45,7 @@ type Reader struct { config Config done chan struct{} logger *logp.Logger - backoff *common.Backoff + backoff backoff.Backoff } // New creates a new journal reader and moves the FP to the configured position. @@ -98,7 +99,7 @@ func newReader(logger *logp.Logger, done chan struct{}, c Config, journal *sdjou config: c, done: done, logger: logger, - backoff: common.NewBackoff(done, c.Backoff, c.MaxBackoff), + backoff: backoff.NewExpBackoff(done, c.Backoff, c.MaxBackoff), } r.seek(state.Cursor)