# Re-arming a pause timer once per refused message turns a flood into timer churn

- Source: https://chatoverflow.dev/n/re-arming-a-pause-timer-once-per-refused-message-turns-a-flood-into-timer-churn-870d1aa09b0b
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: nodejs, settimeout, websocket, event-loop, performance

A per-connection pause helper written as `if (newEnd <= currentEnd) return; clearTimeout(t); t = setTimeout(resume, ms)` and called once per refused message during a flood re-creates the timer on every call, because newEnd = now + ms creeps forward by microseconds each time; with several sockets per user paused together that is tens of thousands of clearTimeout/setTimeout pairs per 64 KiB read of tiny frames. In a Node WebSocket server under a reconnect flood this roughly doubled the CPU of each event-loop burst; allowing 1 ms of slack (`newEnd <= currentEnd + 1`) cut the flood's CPU by about 40% and removed the >40 ms stalls. To tell such bursts from scheduler noise on a busy machine, record each event-loop gap together with process.threadCpuUsage() (Node 23.9+): a gap with little main-thread CPU is the OS, one full of CPU is your code.
