Repository navigation
improve(backup): compress backup archives on several CPU cores - #199367
Conversation
Backup archives were compressed by one gzip stream, so archive writing used one core regardless of host size. Split the tar stream into 4 MiB blocks and compress up to four at a time on the libuv pool, writing them as consecutive gzip members. The output is still a standard .tar.gz that existing verify, restore, and stock tar read unchanged. Refs #183094
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR compresses backup tar data in ordered 4 MiB gzip members using up to four concurrent compression jobs. Example: The contributor's 336 MiB synthetic backup workload on an 18-core Mac.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored draft addresses a measured bottleneck still present on main, and inspection found no concrete introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe backup writer receives tar payload bytes and a finalized manifest, compresses them, and publishes a .tar.gz archive consumed by verification and restore. flowchart LR
A[Backup CLI] --> B[Capture source state]
B --> C[Tar payload and manifest]
C --> D[Ordered parallel gzip]
D --> E[Published archive]
E --> F[Verify and restore]
Technical reviewBest possible solution: Keep compression within the existing backup pipeline, preserving ordered bytes, bounded concurrency, archive compatibility, and existing cleanup ownership. Do we have a high-confidence way to reproduce the issue? Current source confirms serial gzip compression, and the linked discussion supplies phase measurements consistent with that bottleneck; no target code was executed during this read-only review. Is this the best way to solve the issue? Ordered gzip members are a focused approach that preserves the existing compression level and readers; simplification review found no unnecessary parallel owner or scaffolding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b8cd8c10e501. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +66, Tests +34. Total +100 across 3 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 14, 2026, 8:48 PM ET / November 15, 2026, 01:48 UTC. |
Feed the archive file from a byte-mode stream so a slow disk holds a few blocks instead of a queue of members. Cover a multi-member archive through real create and restore, plus read-ahead and failed-block behavior. Refs #183094
|
Merged via squash.
|
…law#199367) * improve(backup): compress archives on several threads Backup archives were compressed by one gzip stream, so archive writing used one core regardless of host size. Split the tar stream into 4 MiB blocks and compress up to four at a time on the libuv pool, writing them as consecutive gzip members. The output is still a standard .tar.gz that existing verify, restore, and stock tar read unchanged. Refs openclaw#183094 * improve(backup): bound parallel gzip read-ahead and prove the round trip Feed the archive file from a byte-mode stream so a slow disk holds a few blocks instead of a queue of members. Cover a multi-member archive through real create and restore, plus read-ahead and failed-block behavior. Refs openclaw#183094
Related: #183094
What Problem This Solves
openclaw backup createcompresses the whole archive on one CPU core, so large installs spend most of the command waiting on gzip while the other cores are idle. On one 16-core host a scheduledbackup create --verifyof about 18 GB ran past 60 minutes, more than 40 of them in archive writing at about 6 MB/s of compressed output.User Impact
User impact: backup archives are written about three times faster on hosts with four or more cores (synthetic measurement below), with the same
.tar.gzformat. Archives are under 0.1% larger. Existing archives,backup verify,backup restore, and stocktar/gunzipare unaffected.Why This Change Was Made
The tar stream is cut into 4 MiB blocks. Up to four blocks compress at once on the libuv thread pool, and they are written in order as consecutive gzip members. A gzip file is defined as a series of members (RFC 1952), so every reader sees one ordinary stream. The compression level is unchanged.
Limits and tradeoffs:
Evidence
Synthetic payload, 336 MiB raw: 120 MiB random, 120 MiB JSON-like text, 80 MiB repetitive logs, 4,000 small files. Each variant pipes the same node-tar (7.5.22) stream through the compressor into a file. Three interleaved rounds, Node 26.7.0, darwin/arm64, 18 cores, on a host that was running other work.
createGzip()createGzip({ level: 1 })Median wall time falls from 7.84 s to 2.71 s (2.9x) for the same CPU time. Level 1 alone saves about 18% and grows the archive 2%, so the level stays as it is.
Compatibility of the new 85-member archive, checked in the same run:
createGunzipoutput is byte-identical to the single-stream archive (354,068,992 bytes).tar.twithgzip: true,strict: true, andmaxDecompressionRatio: 1100(the options verify uses) lists the same 4,179 entries, also with 4,099-byte reads so member boundaries fall inside and between chunks.tar.xand systemtar -xzfboth extract a tree identical to the source (diff -r);gzip -tpasses.A second run on the final head, with the host busier, gave 11.05 / 14.66 / 12.90 s before and 3.89 / 5.47 / 2.39 s after.
Tests in this PR:
src/commands/backup-restore.test.tsround trip: realcreateBackupArchiveover a state directory holding 9 MiB of random bytes, then realbackup restore(verify plus extraction). It asserts the archive holds more than one gzip member and the restored file is byte-identical.src/infra/backup-gzip.test.ts: member order with uneven chunks, empty input, read-ahead bounded by the width under a slow consumer, and a failed block surfacing in order while the source is closed.An independent read-only review of the diff found nothing blocking. Its two real findings are fixed here: the stalled-disk bound (about 130 MiB with the first version, now about 21 MiB) and an option that measured no benefit.
Not verified:
openclaw backup create --verifywas timed, and nothing was measured on the 16-core host. The gain there depends on how much of its archive time is gzip.Benchmark script