Skip to content

Conversation

bimmlerd
Copy link
Member

@bimmlerd bimmlerd commented Oct 25, 2024

The trigger waiter loop would allocate a time.Timer (via inctimer.After) per sleepInterval (1s) if not triggered, creating a bit of unnecessary garbage for the GC to collect.

Please see commit messages - we introduce a benchmark in the first commit, and improve it in the second commit.

This simulates a fast tick rate, but essentially just benchmarks the
trigger allocations in the quiescent state, i.e. when not triggered.

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
Each Trigger which are not triggered would allocate a new time.Timer (via
inctimer.After) on each iteration of the waiter loop. There's no need to
create this much garbage - we can use a ticker instead of the inctimer.

The behaviour is not _exactly_ the same, but the semantics of the
MinInterval and trigger folding are kept intact. As the stdlib docs say,
the ticker adjusts to slow readers. Therefore if the trigger _is_
triggered ofer, and we end up waiting for the MinInterval, the waiter loop is
not run more times due to queued up ticks.

goos: linux
goarch: arm64
pkg: github.com/cilium/cilium/pkg/trigger

                      │  before.txt  │              after.txt              │
                      │     B/op     │    B/op      vs base                │
UntriggeredTrigger-10   11234.5 ± 1%   767.0 ± 11%  -93.17% (p=0.000 n=10)

                      │  before.txt  │             after.txt              │
                      │  allocs/op   │ allocs/op   vs base                │
UntriggeredTrigger-10   144.000 ± 1%   8.000 ± 0%  -94.44% (p=0.000 n=10)

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Oct 25, 2024
@bimmlerd bimmlerd added area/daemon Impacts operation of the Cilium daemon. release-note/misc This PR makes changes that have no direct user impact. area/agent Cilium agent related. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Oct 25, 2024
@bimmlerd
Copy link
Member Author

/test

@bimmlerd bimmlerd marked this pull request as ready for review October 25, 2024 11:36
@bimmlerd bimmlerd requested a review from a team as a code owner October 25, 2024 11:36
@bimmlerd bimmlerd requested a review from thorn3r October 25, 2024 11:36
Copy link
Contributor

@thorn3r thorn3r left a comment

Choose a reason for hiding this comment

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

🧹

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Oct 25, 2024
@julianwiedmann julianwiedmann added this pull request to the merge queue Oct 25, 2024
Merged via the queue into cilium:main with commit d160128 Oct 25, 2024
70 checks passed
@bimmlerd bimmlerd deleted the pr/bimmlerd/less-garbage-by-triggers branch October 28, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agent Cilium agent related. area/daemon Impacts operation of the Cilium daemon. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants