Admin calls provision the lane on every call, serialising parallel DLQ drains; no bounded bulk retry

Aperta
#798 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
1/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, python, rust
Ambito
backend, databases

Direzione di ricerca

The issue says the fixes are in 0.6.19 and main, so first inspect the relevant code and tests for QueueStorage::ensure_lane, bounded DLQ retries, and the awa dlq retry-bulk CLI, then compare them with the described behavior. Done means cache misses check lane visibility before provisioning and bounded retries process at most the requested batch size, with the documented CLI, UI, and Python options.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Module-level admin calls run lane provisioning on every call, including for lanes that already exist. That serialises parallel DLQ drains on the lane's provisioning lock, and there is no bounded bulk retry to use instead. This body is the current state.

Observed

A deployment on 0.6.16/0.6.17 drained a large DLQ by calling dlq::retry_from_dlq once per job, about 766,000 calls over 12 days. Lane provisioning ran on every call and took about 90% of the database time those retries spent (pg_stat_statements for that role):

Statement Calls Total Mean Max
SELECT COALESCE(has_function_privilege(...)) FROM (SELECT pg_advisory_xact_lock(...)) AS lane_lock 766,047 6,387 s 8.3 ms 1,378 ms
SELECT {schema}.provision_lane($1, $2, $3) 766,047 240 s
SELECT {schema}.reserve_enqueue_seq(...) 766,047 183 s
INSERT INTO {schema}.ready_entries ... 747,915 106 s
DELETE FROM {schema}.dlq_entries WHERE job_id = $1 ... 766,045 38 s

Cause

Module-level admin functions build a new QueueStorage per call (active_queue_storage → QueueStorage::from_existing_schema). Its lane cache starts empty, so ensure_lane goes straight to ensure_lane_inserts, which runs five statements: the queue_lanes insert, the lane provisioning lock with a privilege probe, SAVEPOINT, provision_lane and RELEASE. A held store only checks that the lane's queue_enqueue_heads row is visible.

These paths pay the cost on every call:

  • dlq::retry_from_dlq and dlq::bulk_retry_from_dlq
  • admin::retry, bulk_retry, retry_failed_by_kind, retry_failed_by_queue, retry_external, and cancel of a deferred job
  • reschedule, once per job
  • batch set-priority and move-queue, once per job inside a batch

The lock is the lane's provisioning lock ({schema}:{queue}:{priority}:{shard}), not the in-lane enqueue ordering lock that reserve_enqueue_seq takes. Producers with a warm store never take it. The waits come from cache-missing calls queuing behind each other: each holds the provisioning lock while it waits behind producers for the ordering lock and then commits. A sequential drain shows a mean of 0.04–0.1 ms on the lane_lock statement. The 8.3 ms mean implies the drain ran in parallel.

Callers loop the single-job API because bulk_retry_from_dlq revives every matching row in one transaction and ignores ListDlqFilter::limit. The CLI (awa dlq retry-bulk) and the UI bulk-retry route have the same limitation.

Measured (0.6, PG 17)

200 single-job retries:

Path lane_lock calls provision_lane calls
dlq::retry_from_dlq 200 200
One held QueueStorage 1 1
Visibility check on a cache miss (fix 1) 0 0

2,000 retries beside 4 producers enqueueing batches of 10:

Build Drain tasks Retries/s Producer jobs/s
Current 1 ~58 ~2,380
Current 8 ~57 ~2,260
Fix 1 1 ~60 ~2,400
Fix 1 8 ~220 ~1,120

Fix 1 removes the provisioning cost, but the provisioning lock had been holding parallel drains to one at a time. Without it, parallel drains contend directly with producers on the ordering lock, and producer throughput halves with 8 drainers. Bounded batches (fix 2) are what make a large drain cheap.

Fix (0.6.19 and main)

  1. Check lane visibility on a cache miss. ensure_lane runs the queue_enqueue_heads visibility check before ensure_lane_inserts, and provisions only when the lane does not exist. Rust only, no schema change. In-lane commit order is unchanged: it comes from reserve_enqueue_seq, which also re-provisions a missing sequence.
  2. Bounded bulk retry. A new explicit batch function revives at most n matching DLQ rows in one transaction (oldest first, FOR UPDATE SKIP LOCKED) and returns the count. It is exposed as --batch-size (and an optional total --limit) on awa dlq retry-bulk, an optional limit on the UI bulk-retry route, and limit=None in Python. The existing bulk_retry_from_dlq keeps its behaviour, so callers who pass a list filter with a limit are unaffected. A unique conflict aborts its batch, so the CLI loop stops and names the job instead of retrying it forever.
  3. Docs. Long-running tooling should hold one QueueStorage and call its methods.

Workaround before 0.6.19

Hold one QueueStorage and call store.retry_from_dlq in a loop, one lane at a time. That runs provisioning once per lane, and a sequential drain is no slower than a parallel one on current releases.

Lingua principale
Rust
Stelle
37
Fork
8
Merge medio
14h 16m
PR unite (30g)
244

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hardbyte/awa

Tutte le issue di hardbyte/awa

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.