9. Scaling Applications Using Multiple Processors in Node.js

In Chapter 4, “Using Events, Listeners, Timers, and Callbacks in Node.js,” you learned that Node.js applications run on a single thread rather than multiple threads. Using a single thread for application processing makes Node.js processes more efficient and faster. But most servers have multiple processors, and you can scale your Node.js applications by taking advantage of them. Node.js allows you to fork work from the main application to separate processes that can then be processed in parallel with each other and the main application.

To facilitate utilizing multiple processes, Node.js provides three specific modules. The process module provides access to the running processes. The child_process module enables you to create child processes and communicate with them. The cluster module provides the ability to implement clustered servers that share the same port, thus allowing multiple requests to be handled simultaneously.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.134.232