Fleet-wide per-queue rate limits, set live from the CLI and admin UI

Abierto
#718 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
postgresql, python, rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

feature operational

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.

  1. 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". PartitionedQueue multiplies it again per partition. This is the failure mode Celery's per-worker rate_limit is known for; Oban Pro, River Pro, BullMQ and Temporal (TaskQueueActivitiesPerSecond) all enforce limits fleet-wide.
  2. A limit can only be retuned, not switched on or off. ADR-038 Tier 1 (#396) added queue_meta.override_rate_limit and awa queue overrides set|clear|show on main. 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.
  3. Burst can't be overridden. The override is one DOUBLE PRECISION; when it is set, burst is re-derived as ceil(rate) (dispatcher.rs:618-624).
  4. 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.
  5. 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 nor config_mismatch can show which runtimes run which value.
  6. 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, Celery control.rate_limit).
  • Report the applied value per runtime. Almost nobody does; Temporal's --report-config and Trigger.dev's current are 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_instances snapshots, 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 Option that 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::Snooze as the handler-side answer to an upstream 429; it already doesn't consume an attempt.
Operator surfaces
  • CLI: extend awa queue overrides set with --fleet-rate-limit <per-second>, --rate-burst <n>, --reason <text>. show prints base, override, effective value and how many runtimes report it applied.
  • Admin UI: GET/PUT/DELETE /api/queues/{queue}/overrides over the existing admin::set_queue_runtime_overrides, clear_queue_runtime_overrides and queue_runtime_overrides, guarded by require_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), as paused_by does 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_workers changes (#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 show and 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_size now defaults to 512), with a new ADR or an ADR-038 amendment for the fleet semantics.
  • docs/configuration.md explains runtime versus fleet limits and the Snooze pattern.
  • 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.

Lenguaje dominante
Rust
Estrellas
37
Forks
8
Merge medio
14 h 16 min
PR fusionados (30 d)
244

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hardbyte/awa

Todos los issues de hardbyte/awa

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.