perf: server memory leak audit
Add periodic cleanup of fightReactions Map (clears when >100 entries). Add RSS/heap logging every 10 fights in fight-loop for memory monitoring. Set --max-old-space-size=256 in Docker CMD as safety net. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
c8e4fa7a95
commit
e3a4299dae
+1
-1
@@ -40,4 +40,4 @@ ENV NODE_ENV=production
|
|||||||
ENV PORT=9100
|
ENV PORT=9100
|
||||||
EXPOSE 9100
|
EXPOSE 9100
|
||||||
|
|
||||||
CMD ["node", "server/dist/index.js"]
|
CMD ["node", "--max-old-space-size=256", "server/dist/index.js"]
|
||||||
|
|||||||
@@ -132,6 +132,12 @@ export async function startFightLoop(options: FightLoopOptions = {}): Promise<vo
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log memory usage every 10 fights
|
||||||
|
if (fightCount % 10 === 0) {
|
||||||
|
const mem = process.memoryUsage()
|
||||||
|
console.log(`[fight-loop] memory #${fightCount}: rss=${Math.round(mem.rss / 1024 / 1024)}MB heap=${Math.round(mem.heapUsed / 1024 / 1024)}/${Math.round(mem.heapTotal / 1024 / 1024)}MB`)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait before next fight
|
// Wait before next fight
|
||||||
if (fightCount < maxFights) {
|
if (fightCount < maxFights) {
|
||||||
await sleep(intervalMs + Math.floor(Math.random() * intervalMs * 0.5))
|
await sleep(intervalMs + Math.floor(Math.random() * intervalMs * 0.5))
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ let activeSSECount = 0
|
|||||||
const ssePerIp = new Map<string, number>()
|
const ssePerIp = new Map<string, number>()
|
||||||
const MAX_SSE_PER_IP = 5
|
const MAX_SSE_PER_IP = 5
|
||||||
|
|
||||||
|
// Periodic cleanup of stale reaction data (every 10 minutes)
|
||||||
|
setInterval(() => {
|
||||||
|
if (fightReactions.size > 100) {
|
||||||
|
fightReactions.clear()
|
||||||
|
}
|
||||||
|
}, 10 * 60_000)
|
||||||
|
|
||||||
export function getActiveSSECount(): number {
|
export function getActiveSSECount(): number {
|
||||||
return activeSSECount
|
return activeSSECount
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user