Skip to content

Commit

Permalink
daemon: Add rate-limiting to device reloading
Browse files Browse the repository at this point in the history
Add a rate-limit of once per 500ms to the device reloading
to avoid reloading too often and to give the Table[NodeAddress]
a chance to update after devices change.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
  • Loading branch information
joamaki committed May 15, 2024
1 parent e72fdae commit 9ad92f1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions daemon/cmd/device-reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cilium/cilium/pkg/datapath/tables"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/promise"
"github.com/cilium/cilium/pkg/rate"
"github.com/cilium/cilium/pkg/time"
)

Expand All @@ -35,6 +36,7 @@ type deviceReloader struct {
devsChanged <-chan struct{}
prevDevices []string
jg job.Group
limiter *rate.Limiter
}

// registerDeviceReloader provides the device reloader to the hive. The device reloader reloads the
Expand All @@ -56,6 +58,8 @@ func (d *deviceReloader) Start(ctx cell.HookContext) error {
close(c)
d.addrsChanged = c

d.limiter = rate.NewLimiter(time.Millisecond*500, 1)

jg := d.params.Jobs.NewGroup(d.params.Health)
jg.Add(job.Timer("device-reloader", d.reload, time.Second))
d.jg = jg
Expand Down Expand Up @@ -85,6 +89,12 @@ func (d *deviceReloader) reload(ctx context.Context) error {
return ctx.Err()
}

// Rate-limit to avoid reinitializing too often and to allow NodeAddress table
// to update.
if err := d.limiter.Wait(ctx); err != nil {
return err
}

// Note that the consumers may see inconsistent state in between updates to
// the devices and the node addresses, but that we are eventually
// consistent.
Expand Down

0 comments on commit 9ad92f1

Please sign in to comment.