Repository navigation
Perf/sharded handoff queue - #110
Merged
Merged
Conversation
Replace the single taskQueue channel with N power-of-two shard channels so a large worker count no longer serialises on one channel lock. Producers round-robin across shards via a lock-free atomic cursor; workers scan shards from a per-worker cursor and only fall back to the chunked overflow buffer when every shard is empty, dropping the old double non-blocking poll. Shard count defaults to next-power-of-two(min(GOMAXPROCS,32)) for queues of at least 1024 slots, single-channel below that; each shard gets at least one slot so total capacity never shrinks. Adds WithTaskQueueShards(n); GetTaskQueueLen sums shards and GetTaskQueueCapacity reports the configured total. Measured on 20 cores, capacity 20000, queue 100000: hand-off throughput about 2.4x, CPU per hand-off about 2.4x lower, procyield -82 percent. Execution-bound 10ms tasks: +12-18 percent at high concurrency, no regression at low concurrency. Note: task execution order is not guaranteed.
Add invariant-based concurrency stress tests for the sharded handoff queue: no task loss or duplication, no deadlock across shard/queue/capacity combinations, nonblock accept accounting, reentrant submission, graceful shutdown, panic isolation and ctx cancellation, plus a 300k-task heavy run. Add benchmark/scaling_matrix_test.go (worker-count x load matrix, implementation agnostic) and benchmark/ants_compare_test.go (CPU and hand-off comparison against panjf2000/ants v2, added as a test-only dependency).
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.
No description provided.