feat!: implement token-bucket rate limiting per task type and group#82
Merged
Conversation
) Gate-native rate limiting that caps task start rate independently of concurrency. Token buckets use f64 fractional tokens for precision and return the next-available Instant on denial so the run loop can set run_after to avoid head-of-line blocking. Breaking: DispatchGate::admit() now returns Admission enum (Admit/Deny/ RateLimited) instead of bool. SchedulerSnapshot gains a rate_limits field.
Contributor
Benchmark ComparisonClick to expand |
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
DefaultDispatchGate::admit()) so tokens are never wasted on tasks rejected by earlier checks (backpressure, IO budget, concurrency)run_afterset to the next token availability, preventing head-of-line blocking — other task types dispatch freely while the throttled type waitsCloses #35
Breaking changes
DispatchGate::admit()returnsAdmissionenum (Admit/Deny/RateLimited(Instant)) instead ofbool— custom gate implementations must updateOk(true)→Admission::AdmitandOk(false)→Admission::DenySchedulerSnapshotgains arate_limits: Vec<RateLimitInfo>fieldPublic API additions
RateLimit(config withper_second,per_minute,with_burst),RateLimitInfo(snapshot),Admission(gate result)SchedulerBuilder::rate_limit(),group_rate_limit()Scheduler::set_rate_limit(),remove_rate_limit(),set_group_rate_limit(),remove_group_rate_limit()DomainHandleandModuleHandle(auto-prefixed)TaskStore::set_run_after()for deferred requeueSchedulerSnapshot::rate_limitswith per-bucket utilizationFiles changed
rate_limit.rs(new),gate.rs,mod.rs,run_loop.rsbuilder.rs,control.rs,event.rs,queries.rsmodule.rs,domain.rs,lib.rsstore/query/scheduling.rstests/integration/rate_limit.rs(new, 9 tests),tests/integration.rsREADME.md,configuration.md,priorities-and-preemption.md,glossary.md