perf: 200ms gap between pre-warm requests to drain client queue

setImmediate wasn't enough — each analytics computation blocks for
200-400ms synchronously. Adding a 200ms setTimeout between pre-warm
requests gives pending client requests a window to complete between
the heavy computations.
This commit is contained in:
you
2026-03-21 19:53:02 +00:00
parent 187a2ac536
commit 795be6996f

View File

@@ -3008,8 +3008,9 @@ server.listen(listenPort, () => {
if (isHttps) requestOptions.rejectUnauthorized = false;
warmClient.get(requestOptions, (res) => {
res.resume();
res.on('end', () => setImmediate(warmNext)); // yield to event loop between warm requests
}).on('error', () => setImmediate(warmNext));
// 200ms gap between warm requests — lets pending client requests drain
res.on('end', () => setTimeout(warmNext, 200));
}).on('error', () => setTimeout(warmNext, 200));
};
// Stagger: warm analytics after subpaths are done (sequential to avoid blocking)
warmNext();