Repository navigation
rendezvous: stream registry snapshot to disk (drop full-size save buffer) - #130
Merged
Merged
Conversation
flushSave previously encoded the full registry snapshot into a pooled in-memory bytes.Buffer, hashed it, spliced the checksum in, then handed the whole buffer to AtomicWrite for a second full copy. At fleet scale (~250k nodes / 8.3M trust pairs / ~191MB JSON) that buffer dominated the heap and drove GC pauses during saves. Stream the encode straight to the temp file: json.Encoder writes through a MultiWriter(file, sha256); a small trimTrailingNewlineWriter withholds the encoder's trailing newline so the hash matches load()'s newline-stripped recompute; the checksum is backfilled as a trailing JSON member via WriteAt. On-disk format, checksum semantics, and crash recovery (snapshot + WAL replay) are unchanged. Removes flushSaveBufPool and maxPooledSaveBuf. Verified on the live v0.2.6 base: identical snapshot bytes/checksum, crash-restart restores trust pairs from the snapshot, first save ~19s vs ~21s before. Does NOT change save cadence (5s tick and full-snapshot frequency are unchanged).
| return err | ||
| } | ||
| if err := fn(f); err != nil { | ||
| f.Close() |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
flushSaveused to encode the full registry snapshot into a pooled in-memorybytes.Buffer, hash it, splice in the checksum, then hand the entire buffer toAtomicWrite(a second full copy). At fleet scale — ~250k nodes / 8.3M trust pairs / ~191 MB JSON — that buffer dominated the heap and drove GC pauses during saves.This streams the encode directly to the temp file:
json.Encoderwrites through anio.MultiWriter(file, sha256).trimTrailingNewlineWriterwithholds the encoder's trailing\nso the hash covers exactly the bytesload()recomputes (it strips the newline too).WriteAt), preserving the on-disk format.atomicWriteStreamperforms the temp-file → fsync → rename → dir-fsync protocol (same durability asfsutil.AtomicWrite).Removes
flushSaveBufPool/maxPooledSaveBuf.No change to save cadence — 5 s tick and full-snapshot frequency are untouched. This is a memory/CPU optimization only.
Parity
go test ./...across the module is green.Verification (docker, amd64, against the live v0.2.6 base)
Pounded with a local load generator (register + signed heartbeat + signed trust):
v0.2.6 + this patch(no cadence change), deployed topilot-rendezvous-new; 252k nodes preserved, 0 save failures, 0 errors, overlay (directory) green; first post-load save ~19 s vs ~21 s before.Not included (follow-up)
A checkpoint-cadence reduction (snapshot less often; rely on the WAL between) was prototyped and deliberately dropped: the load test showed the WAL only logs
Register/Deregister/Network*/KeyRotation, so trust/hostname/tags/visibility are snapshot-only — lengthening the interval would lose them on crash. That needs the WAL to cover all persistent mutations first.