lib/ratelimit, lib/concurrentlimit: add protocol-neutral rate and concurrency limiters - #288
Open
Vikramarjuna wants to merge 2 commits into
Open
lib/ratelimit, lib/concurrentlimit: add protocol-neutral rate and concurrency limiters#288Vikramarjuna wants to merge 2 commits into
Vikramarjuna wants to merge 2 commits into
Conversation
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.
Adds lib/ratelimit, a three-tier token-bucket rate limiter (global, per-method, per-user-per-method) intended to be shared across SRPC, gRPC and REST handlers so quotas cannot be bypassed by switching protocols. Denials return *errors.ResourceExhaustedError.
Refactors the existing lib/srpc/serverutil.PerUserMethodLimiter, lifting its per-(user, method) semaphore into a protocol-neutral lib/concurrentlimit package so future gRPC and REST adapters can reuse it. Semantics unchanged; the SRPC adapter becomes a thin wrapper preserving NewPerUserMethodLimiter and BlockMethod signatures, so existing callers build unmodified.