Processes and Clustering
Node applications run on a single thread, but they can start new processes and communicate with them to form a distributed system. We will look at several use cases for doing something like this, and study how the Actor Concurrency Model helps keep inter-process communication simple and cheap.
Processes and ClusteringChild Process
Sometimes we need to run a shell command and observe its output. We’ll study the various functions available in the
child_processNode module in detail, focusing on things like:
- Passing arguments
- Monitoring output
- Detecting successful execution
Processes and ClusteringEXERCISE: Running shell commands
Build a class that can retrieve information about the hardware your program is running on. These are typically not available to a Node application and involve running OS-specific shell commands.
Processes and ClusteringApp as a Cluster
In a production environment, running an app on a single threads is dangerous! All it takes is one rogue function to leak, and you have put everything you program can do in jeopardy. We’ll look at how a single script can be “forked” onto multiple processes to form a cluster, leaving the master process available to take on the next task.
Processes and ClusteringEXERCISE: Clustered HTTP server
Upgrade our HTTP server exercise to be run on a pool of worker processes (one per CPU core on your machine), to increase the maximum amount of traffic your program can potentially handle.
Processes and ClusteringLunch
Break for lunch