Add hierarchical token-bucket scheduler for grid capacity control (#48)#86
Merged
elizabetheonoja-art merged 5 commits intoJun 26, 2026
Conversation
…ility-Protocol#48) Replaces the flat per-meter rate limiter with a tree of rate-limited buckets (root -> region -> substation -> feeder -> meter) so hierarchical capacity is shared correctly and the sum of children can never exceed a parent: - ratelimit/htb: HtbTree of HtbNodes (atomic tokens/rate/ceil/burst/debt). A conform() debits the leaf and every ancestor; a node may go negative down to -burst (bursting/borrowing) and beyond that the request is rejected with the whole path rolled back. Refill tops up per node (rate * elapsed, capped at burst) via a CAS-claimed window; debt (negative balance) accrues interest (default 10% APR) and is repaid from refill, converging to zero. Time is injected (conform_at/refill_at(now_ns)) for deterministic behaviour. - ratelimit/topology: TopologyDef loader + validation (unique ids, existing parents, single root, cycle detection, and the invariant that the sum of a parent's children rates <= the parent ceil), building the HtbTree. Kept dependency-free / CI-runnable: no protoc (topology is a Rust def mirroring the kept topology.proto spec); dashmap and proptest are already deps. Self- contained (evaluator/admin call sites don't exist in this repo). Tests: deterministic coverage of topology validation, hierarchical debit + borrowing + rollback, refill/debt repayment, plus proptest properties that no node is ever driven below its burst floor and that a rejected request is a no-op.
…Bucket-Scheduler # Conflicts: # tests/mod.rs
Contributor
Author
|
@elizabetheonoja-art |
elizabetheonoja-art
approved these changes
Jun 26, 2026
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.
Hierarchical Token Bucket Scheduler for Multi-Tier Grid Capacity Allocation and Congestion Control (#48)
Closes #48
What's added (
src/ratelimit/)htb.rsHtbTreeofHtbNodes with atomictokens/rate/ceil/burst/debt.conform_at(leaf, requested, now_ns)debits the leaf and every ancestor; a node may go negative down to-burst(bursting/borrowing), and beyond that the request is rejected with the whole path rolled back (leaf→root, then reverse).refill_*tops up each node (rate × elapsed, capped atburst) via a CAS-claimed refill window so concurrent deductions aren't lost; debt (negative balance) accrues interest (default 10% APR) and is repaid from refill, converging to zero. Token unit = 1 µWh. Time is injected (*_at(now_ns)) for determinism.topology.rsTopologyDefloader +validate(): unique ids, existing parents, exactly one root, cycle detection, and the HTB invariant that Σ(children rates) ≤ parentceil; thenbuild()s the tree (parents-first).