Skip to content

Commit

Permalink
change backoff algorithm to exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
YZ775 committed Apr 26, 2024
1 parent 0dbed8d commit d70ab25
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions op/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
"k8s.io/client-go/kubernetes"
)

const drainBackOffBaseSeconds = 60
const drainBackOffBaseSeconds = 300
const drainBackOffMaxSeconds = 1200

type rebootDrainStartOp struct {
finished bool
Expand Down Expand Up @@ -571,7 +572,12 @@ func drainBackOff(ctx context.Context, inf cke.Infrastructure, entry *cke.Reboot
entry.Status = cke.RebootStatusQueued
entry.LastTransitionTime = time.Now().Truncate(time.Second).UTC()
entry.DrainBackOffCount++
entry.DrainBackOffExpire = entry.LastTransitionTime.Add(time.Second * time.Duration(drainBackOffBaseSeconds+rand.Int63n(int64(drainBackOffBaseSeconds*entry.DrainBackOffCount))))
backoffDuration := time.Second * time.Duration((1<<(entry.DrainBackOffCount-1))*drainBackOffBaseSeconds+rand.Int63n(drainBackOffBaseSeconds))
if backoffDuration > time.Second*drainBackOffMaxSeconds {
backoffDuration = time.Second * time.Duration(drainBackOffMaxSeconds+rand.Int63n(drainBackOffBaseSeconds))
}
entry.DrainBackOffExpire = entry.LastTransitionTime.Add(backoffDuration)

err = inf.Storage().UpdateRebootsEntry(ctx, entry)
if err != nil {
return err
Expand Down

0 comments on commit d70ab25

Please sign in to comment.