Search code examples
node.jshttpforkcluster-computinghttpserver

Clustering vs Forking in NodeJS HTTP Server


Is forking more efficient* as compared to clustering in NodeJS HTTP Server? More specifically I'm talking about using http module of NodeJS and child_process.fork and cluster module.



*The term efficient constitutes of memory usage and average throughput.


Solution

  • From NodeJS official docs

    The worker processes are spawned using the child_process.fork() method, so that they can communicate with the parent via IPC and pass server handles back and forth.

    The cluster module supports methods for distributing incoming connections, while forking requires you to handle the connections on your own.