Skip to content

Fleet rate limits that can be set live (#718) - #887

Draft
hardbyte wants to merge 3 commits into
brian/issue-340-key-retentionfrom
brian/issue-718-fleet-rate-limits
Draft

hardbyte wants to merge 3 commits into
brian/issue-340-key-retentionfrom
brian/issue-718-fleet-rate-limits

Conversation

@hardbyte

Copy link
Copy Markdown
Owner

Part of #718: fleet-wide rate limits that can be set live, covering the runtime, the storage and the CLI. The HTTP API, admin UI and Python bindings follow in a second PR.

Stacked on #884 (migration v064), so this PR's migration is v065. Merge #884 first.

What changes

  • ADR-054, fleet rate limits.

    • Two limits. A queue keeps ADR-010's per-runtime rate_limit and gains fleet_rate_limit. Each runtime enforces the lower of the two: its own limit, or its share of the fleet limit.
    • The share. A runtime's share is its worker capacity for the queue over the capacity of every live runtime serving it. Capacity is max_workers, or min_workers plus the overflow pool in weighted mode. The share is recomputed on the ADR-038 override refresh from runtime snapshots, and a share's burst is floored at one token.
    • Tolerance. The ADR states a bound for each kind of membership change:
      • a runtime joining can push the fleet over by its own share for up to 20 s at the defaults;
      • a clean shutdown leaves the fleet under the limit for up to one refresh;
      • a crash leaves it under the limit for up to the 30 s stale cutoff.
    • Rejected: a token-bucket row updated on every claim, and splitting the limit equally between runtimes.
    • Deferred: a budget handed out through claimer leases.
  • Live limits. Each queue has one rate control per runtime, shared by its claimers. It can hold no bucket, so an override can now enable a limit on a queue built without one, retune it, or remove it. This removes ADR-038's first guard rail. A retune keeps the bucket's tokens, capped at the new burst, so it never grants a fresh burst.

  • Migration v065. Adds these columns to awa.queue_meta:

    • override_fleet_rate_limit and override_fleet_rate_burst;
    • override_rate_burst;
    • overrides_revision, which every write advances;
    • overrides_updated_by and overrides_reason.

    It only adds columns. Binaries from this release read the ADR-038 columns when the new ones are missing, so they can run before the migration.

  • Applied state. Each runtime's per-queue snapshot carries rate_control: its weight, the override revision it applied, its fleet share and the rate it enforces. rate_control sits outside the config snapshot, so differing shares don't count as a config_mismatch. admin::queue_override_application reports which live runtimes applied a revision.

  • CLI.

    • awa queue overrides set gains --fleet-rate-limit, --fleet-rate-burst, --rate-burst, --reason and --by.
    • show prints the revision, who changed the overrides and why, "applied by N of M live runtimes", and each runtime's share and enforced rate.
  • Docs.

    • ADR-010, ADR-038 and the ADR index.
    • docs/configuration.md: runtime versus fleet limits, the tolerance, and returning Snooze on an upstream 429.
    • The CHANGELOG, the v065 section of the upgrade guide, and the awa-jobs skill.

Not in this PR

  • The HTTP API (GET/PUT/DELETE /api/queues/{queue}/overrides), the admin UI and the Python bindings.
  • Limits on a partitioned queue's logical queue. Limits stay per physical queue, as the configuration docs say.
  • Routing operator writes through definer functions, which waits for Restrict EXECUTE on the lane-provisioning SECURITY DEFINER functions and validate priority #677.
  • A runtime from before this release ignores fleet limits. The other runtimes count its capacity in their shares, and show lists it as reporting no rate control.

Testing

  • awa/tests/fleet_rate_limit_test.rs:

    • 1, 2 and 4 runtimes hold a 20/s fleet limit within the stated tolerance.
    • On two runtimes built without a limit, an audited override enables a 10/s fleet limit live. Both runtimes report the revision applied, their shares sum to 1, and the rate holds. Clearing removes the limit live and the backlog drains.

    When every share is forced to 1.0, both tests fail: two runtimes start 89 jobs against a ceiling of 71.

  • Unit tests:

    • the effective rate, including how a share's burst is floored;
    • how overrides enable a limit, retune it and set its burst;
    • that a retune grants no fresh burst;
    • that a queue's claimers recompute the limit once per interval between them;
    • the share calculation.
  • Existing suites pass: rate_limit_test, queue_overrides_test, awa-ui runtime_api_test, the awa-worker, awa-model and awa-cli unit tests, and from migration_test, test_every_migration_is_individually_re_runnable and test_fresh_install_reaches_current_version.

Deferred and DLQ rows dropped the job's enqueue shard, so every path back to
ready (promotion, DLQ retry, manual retry) picked a shard through the rotor:
a keyed job's retry left its key's lane, and every job one promotion
returned to a (queue, priority) shared a single rotor-chosen shard.

Migration v064 adds a nullable enqueue_shard to deferred_jobs and
dlq_entries in every queue-storage schema, through a new installer helper.
Retry, snooze, rescue, DLQ moves, scheduled keyed enqueues and the other
moves keep the shard, and insert_claimed_ready_rows_tx puts the job back on
it, modulo the destination queue's enqueue_shards. NULL takes the rotor as
before. Binaries probe for the column, so they run before the migration and
start retaining shards after it without a restart.
Record the claim-path changes since acceptance and what each means for
per-key control, the head-of-line blocking a saturated key causes across
keys that share its lane, and a narrower E5 comparing row-local claims, key
arrays on indexed compact claim batches, and parking. Key arrays return as a
candidate now that v054 indexes compact claim batches. Tier 1 per-key rates
build on #718's fleet share. #340 moves to 0.8.
ADR-010's rate limit is per runtime, so a fleet of N runtimes starts up to
N times the configured rate, and ADR-038 could only retune a limit the
builder configured. ADR-054 adds QueueConfig::fleet_rate_limit: each
runtime enforces its share, its worker capacity for the queue over the
capacity of the live runtimes serving it, recomputed on the override
refresh from runtime snapshots.

Each queue's limiter can now hold no bucket, so an override can enable,
retune or remove a limit live; a retune never grants a fresh burst.
Migration v065 adds fleet rate and burst overrides, a per-runtime burst
override, an override revision, and who/why audit columns to queue_meta.
Runtimes publish the revision, weight, share and rate they applied, and
`awa queue overrides show` reports how many live runtimes applied the
current revision. The CLI gains --fleet-rate-limit, --fleet-rate-burst,
--rate-burst, --reason and --by.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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