Skip to content
Optimal Lab

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

0120 ms240 ms

Response time per request

  1. #1 /fast2 ms
  2. #11 /report200 ms
  3. #2 /fast197 ms
  4. #3 /fast179 ms
  5. #4 /fast161 ms
  6. #5 /fast143 ms
  7. #6 /fast125 ms
  8. #7 /fast107 ms
  9. #8 /fast89 ms
  10. #9 /fast71 ms
  11. #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. 1

  2. 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. 3

  4. 4