Skip to content

fix(sort): thread --max-memory into the pipeline queue budget - #888

Merged
nh13 merged 1 commit into
mainfrom
nh/sort-queue-memory
Sep 1, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/sort-queue-memory

Conversation

@nh13

@nh13 nh13 commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

The sort-command cutover (#885) hardcoded queue_memory: QueueMemoryOptions::default() (768 MiB/thread) when building the chain, so fgumi sort --max-memory bounded only the sorter's in-memory record buffer, not the bytes held in the inter-stage pipeline queues — a small --max-memory (e.g. -m 64K -@ 8) shrank the sort buffer while the queues could still use gigabytes, so peak RSS barely moved.

This projects the command's single memory knob (--max-memory / --memory-reserve / --memory-per-thread) onto the queue budget via a new queue_memory_options helper, so one flag bounds both budgets. The two totals scale by different thread counts (the sorter by max(threads, sort_threads) since the sort phase fills the buffer, the queues by threads — the width of the ingest/output plumbing); that asymmetry is intentional and documented on the flag.

Deliberate, benign consequences of sharing the flag

  • Default queue budget now follows --max-memory's default ("768M" = 768 MB decimal via the size parser), marginally below the former hardcoded 768 MiB, aligning it with the sorter's own default rather than leaving the two at different units.
  • A large or auto --max-memory does not balloon queue memory. Raising the queue total does not raise the per-stage backpressure marks (512 MiB / 256 MiB, issue --max-memory above 512 MiB is silently clamped and has no effect #765), which are what actually bound in-flight queue bytes; only a value below them tightens the queues (the point of a small --max-memory).

Verification

  • cargo ci-fmt, cargo ci-lint (pedantic), and the no-default-features check are clean.
  • 147 sort unit tests (including two new cases that guard the ChainSpec wiring against a silent revert) and 16 test_sort_cutover_parity integration tests pass.
  • Empirical smoke test on 602,870 records: fgumi sort -m 64KiB -@ 8 completes with no deadlock, output record count equal to input, correct sort order, and peak RSS 248 MB vs 441 MB at the default (the queue budget is genuinely honored). Peak RSS is flat (~380–410 MiB) across -m 768M/auto/4GiB/8GiB at -@ 8 on a 64 GiB host, confirming the per-stage marks bound queue memory rather than the total.

The ChainSpec construction was extracted into a unit-tested build_sort_chain_spec so the wiring (queue budget, stages, threading, write-index sink) is guarded directly, not only exercised through a full run where a dropped knob is invisible.

Risk: output changes none; unsafe changes none and the CLAUDE.md allowlist is unchanged; memory and queue budgets change, while queue backpressure policy remains unchanged.

--max-memory now controls both the sorter buffer and inter-stage queue budget. queue_memory_options applies distinct thread scaling to each budget and preserves the 768M decimal default.

build_sort_chain_spec centralizes chain construction and has unit tests for queue configuration, stages, threading, CRC verification, scheduler settings, and the write-index sink. Tests cover low-memory behavior and chain wiring. Formatting, linting, feature checks, 147 sort unit tests, 16 integration tests, and a smoke test pass.

@nh13
nh13 deployed to github-actions August 31, 2026 22:24 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Essentials

Run ID: fd132f47-ff18-49ca-a612-9759933e95e7

📥 Commits

Reviewing files that changed from the base of the PR and between 0174e3d and 413970e.

📒 Files selected for processing (1)
  • src/lib/commands/sort.rs

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


Walkthrough

The sort command maps memory settings to pipeline queue budgets and centralizes ChainSpec construction. Execution uses the new builder, with tests covering memory behavior and chain wiring.

Changes

Sort chain memory configuration

Layer / File(s) Summary
Memory projection and chain construction
src/lib/commands/sort.rs
The command documents separate sorter-buffer and queue budgets. queue_memory_options projects the memory flags, and build_sort_chain_spec assembles the configured sort chain.
Execution wiring and validation
src/lib/commands/sort.rs
execute_sort uses the centralized builder. Tests validate memory projection, small-memory overrides, and chain settings.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 41397

The change connects the existing memory setting to pipeline queue budgeting with targeted tests and verification; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested labels: fgumi sort

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title uses valid Conventional Commit syntax, includes the affected sort scope, and accurately describes routing --max-memory into the pipeline queue budget.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@nh13

nh13 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai pause

@nh13

nh13 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.96%. Comparing base (a5246a2) to head (413970e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #888      +/-   ##
==========================================
- Coverage   92.98%   92.96%   -0.03%     
==========================================
  Files         298      298              
  Lines      149836   149872      +36     
==========================================
- Hits       139329   139326       -3     
- Misses      10507    10546      +39     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The sort-command cutover (#885) hardcoded QueueMemoryOptions::default()
(768 MiB/thread) when building the chain, so `fgumi sort --max-memory`
bounded only the sorter's in-memory record buffer, not the bytes held in
the inter-stage pipeline queues. A small --max-memory (e.g. -m 64K -@ 8)
shrank the sort buffer while the queues could still use gigabytes, so peak
RSS barely moved.

Project the command's single memory knob (--max-memory / --memory-reserve /
--memory-per-thread) onto the queue budget via a new queue_memory_options
helper, so one flag bounds both budgets. The two totals scale by different
thread counts (the sorter by max(threads, sort_threads), the queues by
threads); that asymmetry is intentional and documented on the flag.

Two deliberate, benign consequences of sharing the flag, documented in
code and called out here:
- The default queue budget now follows --max-memory's default ("768M" =
  768 MB decimal via the size parser), marginally below the former
  hardcoded 768 MiB, aligning it with the sorter's own default.
- A large or `auto` --max-memory does not balloon queue memory: the queue
  total does not raise the per-stage backpressure marks (512/256 MiB, issue
  #765), which are what bound in-flight queue bytes. Verified empirically:
  peak RSS is flat (~380-410 MiB) across -m 768M/auto/4GiB/8GiB at -@ 8 on
  a 64 GiB host.

Extract the ChainSpec construction into a unit-tested build_sort_chain_spec
so the wiring (queue budget, stages, threading, write-index sink) is
guarded against a silent revert, not only exercised through a full run
where a dropped knob is invisible.
@nh13
nh13 force-pushed the nh/sort-queue-memory branch from 0174e3d to 413970e Compare August 31, 2026 22:52
@nh13
nh13 deployed to github-actions August 31, 2026 22:53 — with GitHub Actions Active
@nh13

nh13 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 added this pull request to the merge queue Sep 1, 2026
Merged via the queue into main with commit d7b4b8e Sep 1, 2026
17 checks passed
@nh13
nh13 deleted the nh/sort-queue-memory branch September 1, 2026 02:50
@nh13 nh13 mentioned this pull request Aug 31, 2026

This branch was successfully deployed

1 active deployment
github-actions — 413970ee Deployed Aug 31, 2026 by nh13 via coverage #4073
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