Skip to content

Remove unnecessary fsync during ResumeActor - #1883

Merged
Benjamin Elder (BenTheElder) merged 2 commits into
agent-substrate:mainfrom
msau42:pause-perf
Sep 26, 2026
Merged

Benjamin Elder (BenTheElder) merged 2 commits into
agent-substrate:mainfrom
msau42:pause-perf

Conversation

@msau42

@msau42 Michelle Au (msau42) commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

While benchmarking pause actor I ran into multiple bottlenecks.

I'm currently importing #935 into my branch but #1876 is another alternative to solve the first bottleneck.

The 2nd bottleneck (primary target of this PR) is due to fsyncs being called in writeFileAtomic() for sandbox-assets.json and SystemInfoVolume files. Because these are new files that require ext4 filesystem metadata updates, and we have ext4 mounted in ordered mode, calling fsync on the file + directory causes all other pending writes (such as other checkpoints) to be flushed. So the file creation ends up being blocked behind other actor's checkpoint syncs.

These files do not actually need to be flushed to disk. SystemInfo is recreatable. sandbox-assets.json is written during Run/Resume(), and read during Checkpoint(). But once the checkpoint is finished, the manifest is saved with the snapshot. If the node crashes between Run/Resume and Checkpoint, the actor is crashed anyway.

Single-Node Pause/Resume Benchmark Summary

Configuration: 17 workers, 15 actors, glutton (512 MiB RAM capacity, 32 MiB churn per cycle), 120s run, 1.0s wait, 100% pause (0% suspend)

Metric Baseline (upstream/main) + Commit 1 (os.Link local checkpoint) + Commit 2 (remove fsync on ephemeral volumes)
Completed Cycles (120s) 106.5 (112 pauses / 101 resumes) 160.0 (165 pauses / 155 resumes) 212.5 (214 pauses / 211 resumes)
Cycle Throughput 53.3 cycles/min (0.89/s) 80.0 cycles/min (1.33/s, +50.2%) 106.3 cycles/min (1.77/s, 2.00x)
ResumeActor p50 6,000 ms 4,100 ms 210 ms (28.6x faster)
ResumeActor avg 7,023 ms 4,867 ms 246 ms (28.5x faster)
ResumeActor p90 / p99 15,000 ms / 19,000 ms 9,400 ms / 20,000 ms 350 ms / 590 ms
  • Tests pass
  • Appropriate changes to documentation are included in the PR

Stage local checkpoint files into the restore staging directory via os.Link (with EXDEV fallback to sparsefile.CopyFile) instead of copying the full working set, and guard MergeDeltaIntoBase (Nlink > 1) and rewriteSnapshotSocketPaths (temp file + rename) against mutating shared inodes.
Remove f.Sync() and dir.Sync() from writeFileAtomic and writeFileAtomicRoot while keeping CreateTemp + Rename for read atomicity, avoiding ext4 data=ordered writeback stalls on the ResumeActor critical path.
@chw120

Copy link
Copy Markdown
Collaborator

commit 2 looks good to me. Thanks Michelle.

@BenTheElder
Benjamin Elder (BenTheElder) added this pull request to the merge queue Sep 25, 2026
@BenTheElder
Benjamin Elder (BenTheElder) removed this pull request from the merge queue due to a manual request Sep 25, 2026
@BenTheElder

Copy link
Copy Markdown
Collaborator

BTW for the first commit ... For micro-VM restores from a local snapshot, the copy doesn't go away, it moves. It used to happen on resume; now the next suspend pays a full sparse copy of the working set, because the merge guard sees the shared inode.

I'm not actually sure if that's the right tradeoff. let me look at the other PR.

The second commit is an obvious win, if you want to just ship that one for now.

@BenTheElder

Copy link
Copy Markdown
Collaborator

eh, let's merge and iterate, this is a huge performance win.

@BenTheElder
Benjamin Elder (BenTheElder) added this pull request to the merge queue Sep 25, 2026
Merged via the queue into agent-substrate:main with commit d3aec58 Sep 26, 2026
11 checks passed
@bowei Bowei Du (bowei) added area/microVM area/node area/storage kind/cleanup Small fixes that are not bugs, for example a typo in a code comment labels Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/microVM area/node area/storage kind/cleanup Small fixes that are not bugs, for example a typo in a code comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants