Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add engine configuration options for exponential backoff #8

Merged
merged 3 commits into from
Oct 23, 2018

Conversation

howbazaar
Copy link
Contributor

Add EngineConfig options to allow exponential backoff when determining worker restart delays.

Also tweaks some of the logging to make the default debug output for a restarting engine somewhat quieter.

@@ -80,6 +88,14 @@ func (config *EngineConfig) Validate() error {
if config.BounceDelay < 0 {
return errors.New("BounceDelay is negative")
}
if config.BackoffFactor != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not consolidate into one line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no real reason

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh

Copy link

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - only a couple of minor comments.

@@ -80,6 +88,14 @@ func (config *EngineConfig) Validate() error {
if config.BounceDelay < 0 {
return errors.New("BounceDelay is negative")
}
if config.BackoffFactor != 0 {
if config.BackoffFactor < 1 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nicer as config.BackoffFactor != 0 && config.BackoffFactor < 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -368,7 +389,17 @@ func (engine *Engine) requestStart(name string, delay time.Duration) {
// Always fuzz the delay a bit to help randomise the order of workers starting,
// which should make bugs more obvious
if delay > time.Duration(0) {
delay += time.Duration(rand.Int31n(60)) * time.Millisecond
if engine.config.BackoffFactor > 0 {
for i := 1; i < info.startAttempts; i++ {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not math.Pow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then...

delay = engine.config.MaxDelay
}
}
// Fuzz to ±10% of final duration.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of ±! (I had to copy it because I couldn't be bothered to work out how to type one.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameinel made me use it.

@howbazaar
Copy link
Contributor Author

$$merge$$

@jujubot jujubot merged commit c8e59e2 into juju:v1 Oct 23, 2018
@howbazaar howbazaar deleted the backoff branch October 23, 2018 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants