Compact recently-closed heap to prevent stale entry accumulation#134
Open
Isusami wants to merge 1 commit intomasterking32:mainfrom
Open
Compact recently-closed heap to prevent stale entry accumulation#134Isusami wants to merge 1 commit intomasterking32:mainfrom
Isusami wants to merge 1 commit intomasterking32:mainfrom
Conversation
When stream IDs are rapidly recycled, re-remembering pushes new heap entries while stale ones remain, causing the heap to grow up to ~1.9x the map size. Add compactRecentlyClosedHeapLocked to rebuild the heap from the authoritative map when it exceeds 1.5x, bounding peak memory. Includes regression test TestRecentlyClosedHeapStaleEntryGrowth.
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.
Summary
Add heap compaction to
pruneRecentlyClosedLockedto prevent unbounded growth of therecentlyClosedHeapwhen stream IDs are rapidly recycled.Changes
compactRecentlyClosedHeapLocked-- rebuilds the heap from the authoritative map when the heap exceeds 1.5x the map size (with a minimum floor ofmapLen + 4)pruneRecentlyClosedLockedcycleTestRecentlyClosedHeapStaleEntryGrowthregression test that simulates 10 cycles of 50 recycled stream IDsWhy
When a stream ID is re-remembered with a new expiration, a new entry is pushed onto the heap but the old (stale) entry remains. The lazy-deletion in
pruneRecentlyClosedLockedonly cleans up entries at the front of the heap. Under pathological stream ID recycling, the heap grew to ~1.9x the map size. With compaction, peak ratio is capped at ~1.5x.Test plan
go test -race ./internal/client/...-- all tests pass, race-cleanTestRecentlyClosedHeapStaleEntryGrowthconfirms heap stays within 1.5x bound