feat: add fair-share admission control - #120
Open
tisonkun wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new admission-control domain module (mea::admission) with a concrete work-conserving policy (FairShare) to bound global concurrency while fairly distributing permits across contending keys.
Changes:
- Add
mea::admission::FairSharewith borrowed + owned permits, keyed FIFO wait queues, and fairness based on fewest in-flight permits (queue order as tie-breaker). - Expose observability helpers (
capacity,available_permits,queue_len,in_flight,is_idle) and integrate the module into crate docs/public API. - Add comprehensive tests covering fairness, ordering, cancellation behavior, owned permits, Send futures, custom hashers, and stress capacity.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new admission::FairShare feature and positions it among existing primitives. |
| mea/src/lib.rs | Exposes the new admission module publicly and adds Send/Sync/Unpin assertions for the new types. |
| mea/src/admission/mod.rs | Defines the admission domain module and re-exports FairShare and permit types. |
| mea/src/admission/fair_share.rs | Implements the FairShare admission controller, permits, waiter scheduling, and cancellation behavior. |
| mea/src/admission/tests.rs | Adds targeted unit and stress tests validating fairness, ordering, cancellation, and Send behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
mea::admissionas the problem-domain module andFairShareas its concrete work-conserving policyavailable_permitsfor state observation and keep queue depth, per-key usage, and idle bookkeeping privateSemaphoretypes, including acquire/try entry points and drop behaviorThis supersedes #114. It preserves the intended scheduling behavior, but deliberately replaces the semaphore-oriented API and flat waiter queue with an admission-domain design.
Verification
cargo x testcargo x lintRUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-depscargo +1.85.0 check --workspace --all-targets --all-featurescargo package -p mea --allow-dirty