Skip to content

Commit

Permalink
change backoff algorithm to exponential backoff (#726)
Browse files Browse the repository at this point in the history
change backoff algorithm to exponential backoff
  • Loading branch information
YZ775 authored Apr 30, 2024
1 parent b6cfd26 commit 10f3043
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))))
var backoffSeconds int64 = (1 << (entry.DrainBackOffCount - 1)) * drainBackOffBaseSeconds
if backoffSeconds > drainBackOffMaxSeconds {
backoffSeconds = drainBackOffMaxSeconds
}
entry.DrainBackOffExpire = entry.LastTransitionTime.Add(time.Second * time.Duration(backoffSeconds+rand.Int63n(drainBackOffBaseSeconds)))

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

0 comments on commit 10f3043

Please sign in to comment.