IGNITE-28848 ZooKeeper discovery: stream marshalZip through DeflaterOutputStream to cut allocations and peak memory#13319
Open
anton-vinogradov wants to merge 1 commit into
Conversation
…utputStream to cut allocations and peak memory Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
JIRA: IGNITE-28848 (follow-up to IGNITE-28835)
Why this matters.
marshalZip()sits on the two busiest control-plane paths of ZooKeeper discovery: the coordinator re-marshals the wholeZkDiscoveryEventsDataon every discovery event (node joins/failures and every custom message — cache create/destroy, exchange, services, snapshots, ...), and join data / data-for-joined is megabytes in clusters with hundreds of caches (split across znodes byjute.maxbuffer). The current code materializes the uncompressed form before compressing: ~6x the uncompressed size in garbage and ~3x at peak per call — so a mass join, client reconnect storm or rolling restart hits the coordinator with GC pressure and heap spikes exactly when it is busiest, and the pauses land on the discovery critical path (events are processed sequentially, the whole cluster sees slower event propagation).Deflater.end()is never called either, so zlib native memory waits for the Cleaner.Change: stream marshalling straight through
BufferedOutputStream -> DeflaterOutputStream: the uncompressed form is never materialized, peak memory is bounded by the compressed output, and the deflater is released deterministically on close. TheBufferedOutputStreamis essential —ObjectOutputStreamwrites ~1 KB blocks, and unbuffered per-block JNI deflate calls cost +14–20% time. The privatezip()helper is removed (marshalZipwas its only caller);unzip()stays (still used forATTR_SECURITY_SUBJECT_V2); the read side (unmarshalZip) already streams. Same pattern asDiscoveryMessageParser.marshalZipin the same package.Compatibility: zlib format is unchanged (default
Deflatersettings in both versions) — old nodes inflate the bytes as is, rolling upgrade safe.JMH (avgt, JDK 17,
-prof gc), old vs new:Allocations drop 73–82% on realistic payloads; per-call time is on par or better. The small-payload trade-off (+15% B/op — bounded fixed overhead of the 8 KB buffer, break-even ~3 KB) is analyzed in the JIRA description.
🤖 Generated with Claude Code