Skip to content

feat(capacity-limiter): explore a borrower-aware capacity limiter - #287

Closed
orthur2 wants to merge 1 commit into
apache:mainfrom
orthur2:feat/borrower-aware-capacity-limiter
Closed

feat(capacity-limiter): explore a borrower-aware capacity limiter#287
orthur2 wants to merge 1 commit into
apache:mainfrom
orthur2:feat/borrower-aware-capacity-limiter

Conversation

@orthur2

@orthur2 orthur2 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR explores #224 with a working implementation, tests, and benchmarks. I plan to close it without merging and keep the code available for reference.

  • add an opt-in CapacityLimiter with explicit borrower identities and RAII permits
  • reject duplicate acquisitions and support resizing while permits are held
  • cover FIFO ordering, cancellation, concurrent resizing, and reentrant wakers

Design Notes

I also tried a Semaphore wrapper and a sharded borrower registry. This PR keeps borrower identities, capacity, and the waiter queue under one mutex. It allows concurrent resize calls without caller retries, but duplicates some semaphore accounting and queue management.

Local measurements favored this implementation in most runs, though it did not win consistently under contention. The benchmarks help compare implementation costs; they do not establish a need for another core primitive.

I would leave #224 in the backlog until a concrete Rust use case shows where borrower tracking provides a useful guarantee beyond the existing semaphore and owned permits.

Refs #224.

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