fix: competitive/ranked setupStats memory leak (unbounded row arrays) - #2929
Open
vinxp97 wants to merge 1 commit into
Open
fix: competitive/ranked setupStats memory leak (unbounded row arrays)#2929vinxp97 wants to merge 1 commit into
vinxp97 wants to merge 1 commit into
Conversation
Competitive/ranked games pushed per-game alignmentRows, roleRows, and gameLengthRows onto SetupVersion.setupStats. Heavy competitive setups grew multi-MB docs that were fully loaded on every game end for fortune payouts and on setup page views, driving process memory growth. Switch writes to fixed-size aggregates (alignmentAgg/roleAgg/lengthAgg), read aggregates with legacy row fallback (merged during transition), clear game EventEmitter listeners on postgame cleanup, and add migrations/compactSetupStatsRows.js to fold existing rows into aggregates and drop the arrays in production.
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
Competitive seasons (and ranked) were pushing unbounded per-game stats onto
SetupVersion.setupStats:alignmentRows— one row per faction per finished clean gameroleRows— one row per player role per gamegameLengthRows— one row per gamePopular competitive setups concentrate thousands of games onto a few setup versions, creating multi-MB documents. Every competitive/ranked game end then loads the full
setupStatsinto memory for fortune calculation (adjustSkillRatings→alignmentRowsToWinRateMap), and setup pages do the same for granular winrate UI. That matches reports of growing process memory under competitive play.Fix
$pushing rows:setupStats.alignmentAgg[faction][gameType] = { wins, games }setupStats.roleAgg[roleKey][gameType] = { wins, games }setupStats.lengthAgg[gameType] = { sumMs, count }*Rowsduring transition so history is not lost before migration.events.removeAllListeners()so role/card listeners cannot retain finished games after they leave the processgamesmap.migrations/compactSetupStatsRows.jsfolds existing row arrays into aggregates and clears them (run on prod after deploy).Deploy notes
After merging, run once against production Mongo:
Optional:
--min-rows 100to only touch large docs first.Test plan