Skip to content

backup-helper: parallelise prepare hashing + curio import-pieces --result compatibility - #7

Closed
TippyFlitsUK wants to merge 2 commits into
BravoNatalie:mainfrom
TippyFlitsUK:feat/parallel-prepare-and-import-result
Closed

backup-helper: parallelise prepare hashing + curio import-pieces --result compatibility#7
TippyFlitsUK wants to merge 2 commits into
BravoNatalie:mainfrom
TippyFlitsUK:feat/parallel-prepare-and-import-result

Conversation

@TippyFlitsUK

Copy link
Copy Markdown

Summary

Two independent changes to backup-helper, kept as separate commits so they can be reviewed (or split) independently:

1. prepare — parallel CommP hashing (perf)

prepare computes a piece CID for every shard missing one, via the pure-JS @filoz/synapse-core/piece hash. That hash is CPU-bound and single-threaded, so on a multi-core node prepare pins one core and leaves the rest idle.

This moves the hashing into a worker_threads pool sized to --concurrency. Each worker calls the same calculateFromIterable, so output piece CIDs are byte-identical to the single-thread path — only throughput changes. DB writes and shard→piece renames stay on the main thread (sqlite isn't shared with workers).

Measured on a 64-core machine, single dataset (~10 MB average CARs):

--concurrency throughput
8 ~20 MB/s
24 ~69 MB/s
32 ~84 MB/s

Knee around 32 on that box (the per-core JS hash is the ceiling); scales with available cores. Piece-CID output verified identical to the pre-change path.

2. commit — adapt to curio import-pieces --result (fix)

curio toolbox import-pieces moved its JSON result off stdout into a file passed via a now-required --result <path> flag, and writes that file even on non-zero exit. Against a curio build with that change, runParkingBinary fails with ERROR: result is required.

This passes --result <dir>/.parking-result.json, reads the JSON from there on both success and failure (surfacing curio's structured error field), and cleans the file up afterward.

Tracks filecoin-project/curio#1264 (commit 7c8297ca, "always write in json file").

⚠️ Note: curio#1264 is currently a draft. If its flag contract shifts before it merges, this commit will need a follow-up. Happy to drop it from this PR and land it separately if you'd prefer to wait on the curio side.

Testing

  • prepare: run end-to-end on a real customer dataset — failed=0, piece CIDs match the single-thread output.
  • commit: parking step succeeds against a curio build carrying #1264; structured errors propagate on failure.

Notes

  • No change to default concurrency or any existing flag/behaviour.
  • Requires Node.js 24+ (unchanged).

TippyFlits added 2 commits June 4, 2026 20:14
prepare computes a piece CID for every shard missing one via the pure-JS
@filoz/synapse-core/piece hash. That hash is CPU-bound and single-threaded,
so on a multi-core node prepare pins one core and leaves the rest idle.

Move the hashing into a worker_threads pool sized to --concurrency. Each
worker calls the same calculateFromIterable, so output piece CIDs are
byte-identical to the single-thread path; only throughput changes. DB
writes and shard->piece renames stay on the main thread (sqlite is not
shared with workers).

Measured on a 64-core machine (~10 MB avg CARs): ~20 MB/s at -c 8,
~69 MB/s at -c 24, ~84 MB/s at -c 32 (knee ~32 on that box). No change to
default concurrency or any existing flag.
curio toolbox import-pieces moved its JSON result off stdout into a file
passed via a now-required --result <path> flag, and writes that file even
on non-zero exit. Against a curio build with that change, runParkingBinary
fails with 'ERROR: result is required'.

Pass --result <dir>/.parking-result.json, read the JSON from there on both
success and failure (surfacing curio's structured error field), and remove
the file afterward.

Tracks filecoin-project/curio#1264 (commit 7c8297ca). Note that #1264 is
currently a draft; if the flag contract shifts before it merges this will
need a follow-up.
@BravoNatalie

Copy link
Copy Markdown
Owner

Closing this, since the the worker_threads commit was added to the PR #8

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.

2 participants