Node.js · interactive
Don't block the event loop
Node runs all your JavaScript on one main thread. That's fast while each request does a little work and waits on I/O. One request that crunches numbers for 200 ms stops every other request until it's done.
What each thread is doing, 0–240 ms
Main thread (your JavaScript)
Worker thread
Response time per request
- #1 /fast2 ms
- #11 /report200 ms
- #2 /fast197 ms
- #3 /fast179 ms
- #4 /fast161 ms
- #5 /fast143 ms
- #6 /fast125 ms
- #7 /fast107 ms
- #8 /fast89 ms
- #9 /fast71 ms
- #10 /fast53 ms
The 200 ms report holds the only main thread. The quick requests behind it wait up to 197 ms for a 2 ms job.
Where the report runs
quick requests: avg 113 ms · worst 197 ms
1 2 JavaScript runs to completion. While the report computes, the event loop can't pick up anything else: not requests, not timers, not I/O callbacks.
Quick requests queue up behind it and wait up to 197 ms.
3 4
In production
Tools and technologies
Every single-threaded runtime has this rule: keep long CPU work off the thread that serves requests.
Not tied to one language — use these names when you search docs or design a system.
- worker_threadsPlatform
Run JavaScript on another thread and message results back.
Official site ↗ - PiscinaSoftware
A worker thread pool for Node.js.
GitHub ↗ - perf_hooks.monitorEventLoopDelayPlatform
Measure how long the event loop is blocked.
Official site ↗ - Clinic.jsSoftware
Find what is blocking the event loop in a running app.
GitHub ↗