Skip to content

Commit

Permalink
common.Backoff now implements jitter instead of sleeping for a fixed …
Browse files Browse the repository at this point in the history
…amount of time (elastic#10177)

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: elastic#10172
  • Loading branch information
ph authored Jan 21, 2019
1 parent 36c9242 commit 24736da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions reader/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 24736da

Please sign in to comment.