Skip to content

perf: optimize countingWaitGroup for faster Count() operations #9162

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

Closed
wants to merge 1 commit into from

Conversation

analytically
Copy link
Contributor

@analytically analytically commented Mar 25, 2025

Improve performance of the countingWaitGroup implementation while
maintaining the original behavior:

  • Use atomic.Int64 for the counter to enable lock-free Count() reads
  • Keep mutex synchronization for Add() and Done() to ensure atomicity
    between WaitGroup operations and counter updates
  • Significantly reduce contention when multiple goroutines read the count
    while operations are in progress

This change improves performance when the beacon rebalancing logic
frequently checks the Count() value.

@analytically analytically requested a review from a team as a code owner March 25, 2025 21:23
Improve performance of the countingWaitGroup implementation while
maintaining the original behavior:

- Use atomic.Int64 for the counter to enable lock-free Count() reads
- Keep mutex synchronization for Add() and Done() to ensure atomicity
  between WaitGroup operations and counter updates
- Significantly reduce contention when multiple goroutines read the count
  while operations are in progress

This change improves performance when the beacon rebalancing logic
frequently checks the Count() value.

Signed-off-by: Mathias Bogaert <[email protected]>
@analytically analytically changed the title refactor: optimize countingWaitGroup with atomic.Int64 perf: optimize countingWaitGroup for faster Count() operations Mar 25, 2025
@taylorsilva
Copy link
Member

The Beacon rebalance operation is called every 4hrs by default. Not exactly "frequent".

RebalanceInterval time.Duration `long:"rebalance-interval" default:"4h" description:"Duration after which the registration should be swapped to another random SSH gateway."`

Going to leave the code as-is.

@taylorsilva taylorsilva closed this Jul 4, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Pull Requests Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants