fix: prevent connection pool exhaustion from concurrent is-active checks#3278
Closed
fix: prevent connection pool exhaustion from concurrent is-active checks#3278
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Benchmark resultsCompared against |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates database connection pool exhaustion caused by many ConcurrencyManager instances concurrently performing “is-active” checks in the scheduler subsystem.
Changes:
- Added a shared semaphore in the scheduling pool to cap concurrent
is_activechecks across all tenants/strategies. - Switched
loopCheckActiveto a randomized ticker interval and ensured the ticker is stopped. - Updated
UpdateConcurrencyStrategyIsActiveto usepg_try_advisory_xact_lock(non-blocking) to reduce lock-wait connection usage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/scheduling/v1/pool.go | Introduces and initializes a shared semaphore to throttle concurrent is-active checks. |
| pkg/scheduling/v1/concurrency.go | Uses the shared semaphore to limit concurrent is-active checks and randomizes the check interval. |
| pkg/repository/scheduler_concurrency.go | Replaces blocking advisory lock acquisition with try-lock to avoid holding DB connections while waiting. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
72
to
76
| schedulerConcurrencyRateLimit: schedulerConcurrencyRateLimit, | ||
| schedulerConcurrencyPollingMinInterval: schedulerConcurrencyPollingMinInterval, | ||
| schedulerConcurrencyPollingMaxInterval: schedulerConcurrencyPollingMaxInterval, | ||
| isActiveSemaphore: make(chan struct{}, 10), | ||
| }, |
Comment on lines
+172
to
+177
| // Limit the number of concurrent is-active checks to avoid saturating the connection pool. | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| case c.isActiveSemaphore <- struct{}{}: | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes # (issue)
Type of change
What's Changed