Fleet-wide per-queue rate limits, set live from the CLI and admin UI
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
Start with ADR-010 and ADR-038, then read awa-worker/src/dispatcher.rs and the existing queue override CLI on main; inspect the runtime snapshot and admin paths named in the proposal. The work spans fleet-wide limit semantics, persistence, applied-state reporting, CLI, UI, and Python bindings, so first decide the ADR changes and implementation scope. Done means the listed multi-runtime rate tests pass and operators can enable, change, remove, and inspect limits live.
索引モデルが issue の本文から書いたものです。
説明
Problem
An operator who needs to protect a downstream API wants to say "this queue starts at most 50 jobs a second" and change that number during an incident from the CLI or the admin UI. Awa can't do that today.
- The limit is per runtime, not per fleet. ADR-010's token bucket lives in each runtime's dispatcher (
awa-worker/src/dispatcher.rs,shared_rate_limiter). With N runtimes serving a queue, the effective rate is N ×max_rate, and it changes whenever the fleet scales. ADR-010 calls this out under "Per-worker, not global".PartitionedQueuemultiplies it again per partition. This is the failure mode Celery's per-workerrate_limitis known for; Oban Pro, River Pro, BullMQ and Temporal (TaskQueueActivitiesPerSecond) all enforce limits fleet-wide. - A limit can only be retuned, not switched on or off. ADR-038 Tier 1 (#396) added
queue_meta.override_rate_limitandawa queue overrides set|clear|showonmain. The bucket is created only when the builder configured a limit, so overriding an unlimited queue is ignored with a warning ("enabling limiting live is Tier 2",dispatcher.rs:631-637). An operator can't throttle a queue that was deployed without a limit, which is the incident case. - Burst can't be overridden. The override is one
DOUBLE PRECISION; when it is set, burst is re-derived asceil(rate)(dispatcher.rs:618-624). - No UI or Python surface. awa-ui has no route that reads or writes overrides, and Python has no admin binding. The queue page's rate-limit field shows the builder value from runtime snapshots, not the override in force.
- No way to see what was applied. Each dispatcher applies overrides on its own ~10 s refresh and only logs "Applied queue runtime overrides". Snapshots publish the builder
QueueConfig, so neither the UI norconfig_mismatchcan show which runtimes run which value. - 0.6 has none of this. ADR-038 overrides are
main-only; on 0.6 a rate limit needs a code change and a rolling restart.
Prior art
| System | Scope | Algorithm | Live change | Applied value visible |
|---|---|---|---|---|
| Oban Pro (Postgres) | local_limit per node; global_limit, rate_limit fleet-wide |
Sliding window (default), fixed window, token bucket; weighted jobs | Oban Web edits limits; Oban.Pro.Queues persists them in the DB |
Persisted row, live view |
| River Pro (Postgres) | GlobalLimit / LocalLimit (concurrency only) |
— | River UI overrides the limit, persisted until removed | UI shows real running counts |
| BullMQ | Global, stored in Redis | Fixed window | setGlobalRateLimit; Bull Board edits concurrency |
Bull Board shows configured vs active |
| Temporal | TaskQueueActivitiesPerSecond server-side; WorkerActivitiesPerSecond per worker |
Rate split across partitions; GCRA for fairness keys | temporal task-queue config set --queue-rps-limit overrides the worker value |
describe --report-config shows the value and its source |
| Trigger.dev | Global concurrency, per key | — | override() / reset(); overrides survive deploys |
{base, override, current, overriddenAt} |
| Celery | Per worker | Token bucket | control.rate_limit broadcast, not persisted |
None |
Lessons that apply here:
- Make the fleet-wide meaning the default, and give the per-runtime cap its own name.
- Store base and override separately in the database, with who and why. Never keep a runtime-only value in worker memory (BullMQ
groupConcurrency, Celerycontrol.rate_limit). - Report the applied value per runtime. Almost nobody does; Temporal's
--report-configand Trigger.dev'scurrentare the best examples. - Avoid one hot counter row per limit. Oban had to tune autovacuum on
oban_producers, and River Pro documents transaction collisions on limited queues. Hatchet keeps usage in memory and flushes in batches. - Prefer a token bucket or GCRA with an explicit burst over fixed windows, which allow 2× bursts at the boundary.
Proposal
Semantics
- A queue gets an optional fleet rate limit (jobs started per second, plus burst) alongside the existing per-runtime limit. When both are set, the lower effective rate wins in each runtime.
- Each runtime enforces its share of the fleet limit with the existing local bucket. Share = fleet rate × (this runtime's permits for the queue ÷ permits of all live runtimes serving the queue). Live runtimes and their queue configs come from
awa.runtime_instancessnapshots, which every runtime already reads. - Shares are recomputed on the existing override refresh (~10 s) and when snapshots show a runtime joining or leaving. Between refreshes the fleet can run slightly under or over; document the bound.
- Queue storage could later hand out the budget through claimer leases (
queue_claimer_state/queue_claimer_leases, which are already one coordinated row per claimer slot written at lease frequency). That is tighter, but it doesn't cover the canonical engine; treat it as a follow-up.
Rejected: a token-bucket row updated inside the claim transaction. Every claim on every shard would serialise on one hot row, undoing ADR-025, and every claim would leave a dead tuple under pinned horizons (#169, ADR-026). A GCRA timestamp in a sequence guarded by a per-queue advisory lock avoids dead tuples but is still a serialisation point; worth a benchmark only if share-based limits turn out too loose.
Behaviour
- Always build the dispatcher's limiter (as an
Optionthat can be swapped), so an override can enable, retune or remove a limit live. This closes the Tier 2 gap in #397 for rate limits. - Add burst to the override.
- An over-limit queue leaves jobs unclaimed, as now. Jobs are never claimed and then rescheduled, which burns attempts and causes retry storms (Sidekiq's
OverLimit, GoodJob's retry-with-backoff). - Document
JobResult::Snoozeas the handler-side answer to an upstream 429; it already doesn't consume an attempt.
Operator surfaces
- CLI: extend
awa queue overrides setwith--fleet-rate-limit <per-second>,--rate-burst <n>,--reason <text>.showprints base, override, effective value and how many runtimes report it applied. - Admin UI:
GET/PUT/DELETE /api/queues/{queue}/overridesover the existingadmin::set_queue_runtime_overrides,clear_queue_runtime_overridesandqueue_runtime_overrides, guarded byrequire_writable. The queue page shows base, override, effective fleet rate, per-runtime share and "applied by N of M runtimes", plus an edit form with a reason field. - Python: admin bindings for the same functions.
- Applied state: each runtime publishes its applied override revision and effective limit in its snapshot (
awa.runtime_instances). Follow the 0.6 runtime-controls model (awa.runtime_control_observations,awa control status), which already reports pending, degraded and unconfirmed runtimes. - Audit: record who and why with each override (
overrides_updated_by,overrides_reason), aspaused_bydoes for pause.
Permissions
Overrides are plain writes to awa.queue_meta, and the documented runtime role has DML on every awa table, so any runtime credential can change them. Consider routing operator writes through SECURITY DEFINER functions granted to an operator role, as 0.6's halt_runtime_scope / resume_runtime_scope do. Resolve #677 first so the definer pattern stays narrow.
Out of scope
- Per-key rate limits (per tenant or per argument). That belongs with #340, which this should leave room for: a later key-partitioned limit should reuse the same override, share and applied-state plumbing.
- Live
max_workerschanges (#397).
Done when
- A queue with a fleet rate limit started across 1, 2 and 4 runtimes holds the configured fleet rate within a documented tolerance on PostgreSQL 17 and 18.
- An operator can enable, retune and remove a limit on a queue built without one, from the CLI and the UI, without a restart, and the change applies within one refresh interval.
awa queue overrides showand the UI report base, override, effective value and applied-by counts.- ADR-010 is updated (fleet scope; its batch-size line still says 10, while
claim_batch_sizenow defaults to 512), with a new ADR or an ADR-038 amendment for the fleet semantics. docs/configuration.mdexplains runtime versus fleet limits and theSnoozepattern.- A decision is recorded on whether 0.6 gets any of this, given it lacks ADR-038.
Related: ADR-010, ADR-011, ADR-038, #385, #396, #397, #340, #341, #677.
- 主要言語
- Rust
- スター
- 38
- フォーク
- 8
- 平均マージ
- 14時間 16分
- マージ済み PR(30日)
- 244
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
hardbyte/awa のほかの issue
-
feature
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
operational
難易度 5/5 1週間以上 初心者へのやさしさ 8/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
marketing
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
area: engine bug needs milestone
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Mudcrab-Team/mudcrab#1197 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
zeabur-oss/builder#304 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
prometheion/ares#159 ·
メンテナーはふだん 1 日以内に返信
-
Multi-select question chips show no picked state; on touch the last tap looks like the only pickオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
eliasstravik/herdr-projects#1710 · コメント 1 件 ·