Processes and Clustering

Processes, Threads and Clustering

Your JavaScript runs on one thread. Timers, sockets and file reads stay cheap because libuv does the waiting, but a 200 ms computation makes every other request wait 200 ms too, and async does not help: it schedules work rather than parallelizing it.

Node's three escapes differ in one respect: what the new execution context shares. A worker thread lives in the same process and can share raw memory, but gets its own V8 86,723 isolate, so objects still copy across. A child process is a separate program with its own address space, reached over pipes or an IPC channel. A cluster worker is a child process that is a copy of your server, on the same port.

One Node process, its threads, and a second process alongside it
One Node process, its threads, and a second process alongside it

Subsections