Skip to content

cache/disk: replace fixed Contains worker pool with semaphore#2

Open
ajwerner wants to merge 2 commits into
mainfrom
semaphore-contains-checks
Open

cache/disk: replace fixed Contains worker pool with semaphore#2
ajwerner wants to merge 2 commits into
mainfrom
semaphore-contains-checks

Conversation

@ajwerner

@ajwerner ajwerner commented Jun 12, 2026

Copy link
Copy Markdown

WithProxyBackend spawned 512 permanent containsWorker goroutines at startup to serve proxy Contains lookups for FindMissingBlobs. In deployments where the proxy is rarely exercised, that is 512 idle goroutines for the life of the process — in our fleet, two-thirds of the embedding agent's entire goroutine count.

Bound the concurrency with a weighted semaphore (same 512 limit) and spawn one goroutine per check instead. Goroutine spawn cost is noise next to a proxy HEAD request, so throughput is unchanged, and the process carries zero pool goroutines at rest. This also makes admission context-aware: the old bare channel send could park a producer indefinitely with no way to be interrupted by cancellation, while semaphore.Acquire(ctx, 1) returns as soon as the request or fail-fast context is cancelled.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled. (Staging)


View with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is enabled.

ajwerner and others added 2 commits June 12, 2026 12:15
WithProxyBackend spawned 512 permanent containsWorker goroutines at
startup to serve proxy Contains lookups for FindMissingBlobs. In
deployments where the proxy is rarely exercised, that is 512 idle
goroutines for the life of the process — in our fleet, two-thirds of
the embedding agent's entire goroutine count.

Bound the concurrency with a weighted semaphore (same 512 limit) and
spawn one goroutine per check instead. Goroutine spawn cost is noise
next to a proxy HEAD request, so throughput is unchanged, and the
process carries zero pool goroutines at rest. This also makes
admission context-aware: the old bare channel send could park a
producer indefinitely with no way to be interrupted by cancellation,
while semaphore.Acquire(ctx, 1) returns as soon as the request or
fail-fast context is cancelled.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant