Cancelling jobs by ID on queue storage costs ~9 ms a job, mostly re-planning

オープン
#802 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
53/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
postgresql, rust

調査の方向性

Start by reading cancel_job_tx and lock_claim_heads_of_jobs_tx, then inspect the ready-row lookup and ready-reference statements described in the issue. Compare set-based cancellation with force_generic_plan using pg_stat_statements on 20k and 200k lanes. Done means lower per-job cancellation cost with measured claim-ring prune outcomes during a large cancel.

索引モデルが issue の本文から書いたものです。

説明

Cancelling jobs by ID on queue storage costs about 9 ms a job, so cancelling a large lane takes long transactions and holds ring partitions and claim heads for seconds per chunk. This body is the current state.

Observed

  • Soak on 839120ce: cancelling a 200,000-job lane through admin::bulk_cancel in 1,000-ID calls took 1,550 s (about 7.7 s per call). The claim ring stopped advancing for 495 s, with 65 claim-ring prunes blocked.
  • Measured with pg_stat_statements (track_planning = on) on PostgreSQL 18, release build, 250-job chunks:
    • about 9 ms a job wall time, the same at the head, middle and tail of the lane and on a 20,000-job lane, so it is not a lane-wide scan;
    • about 15 statements a job, executing in about 1.6 ms in total;
    • about 5.4 ms a job of planning: the ready-row lookup in cancel_job_tx (WITH target AS (SELECT ready.* FROM ready_entries JOIN queue_claim_heads ...)) is re-planned on almost every call at about 5.4 ms a plan, the ready-reference statement (WITH refs ... unnest) at about 1 ms, and lock_claim_heads_of_jobs_tx at about 0.85 ms. They read the partitioned ring tables, and PostgreSQL keeps choosing custom plans;
    • the rest is per-statement round trips.
  • #799's lane-visibility change does not affect it.

#801 shrinks queue-storage cancel-by-ID chunks to 250 IDs with a 100 ms pause between them, which bounds each transaction to about 2.2 s but leaves the per-job cost.

Proposal (0.6.x and main)

  1. Cancel a chunk with set-based statements: look up the chunk's ready rows, claim heads and references once per chunk instead of once per job.
  2. Or, as a smaller step, run the cancel transaction with SET LOCAL plan_cache_mode = force_generic_plan and measure the plans it gets.
  3. Measure before and after on 20k and 200k lanes, including claim-ring prune outcomes during a large cancel.

Rust only; no schema change. Related: #798, #799, #801, #721.

主要言語
Rust
スター
37
フォーク
8
平均マージ
14時間 16分
マージ済み PR(30日)
244

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hardbyte/awa のほかの issue

hardbyte/awa の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。