Recall & Review
beginner
What is the purpose of forking workers per CPU core in Node.js?
Forking workers per CPU core allows Node.js to create multiple child processes, each running on a separate CPU core. This helps to utilize all CPU cores efficiently and improves the performance of CPU-bound tasks.
Click to reveal answer
beginner
Which Node.js module is commonly used to fork workers for each CPU core?
The 'cluster' module is used to fork workers in Node.js. It helps create child processes that share the same server port, enabling load balancing across CPU cores.
Click to reveal answer
beginner
How do you determine the number of CPU cores available in a Node.js application?
You can use the 'os' module's 'cpus()' method, which returns an array of CPU core info. The length of this array indicates the number of CPU cores available.
Click to reveal answer
intermediate
What happens if a worker process crashes in a cluster setup?
If a worker crashes, the master process can listen for the 'exit' event and fork a new worker to replace it. This ensures the application remains available and resilient.
Click to reveal answer
intermediate
Why should you avoid sharing state directly between worker processes?
Each worker runs in its own process with separate memory. Sharing state directly is not possible and can cause bugs. Instead, use inter-process communication or external stores like databases.
Click to reveal answer
Which Node.js module helps you create worker processes for each CPU core?
✗ Incorrect
The 'cluster' module is designed to fork worker processes to utilize multiple CPU cores.
How do you find the number of CPU cores in Node.js?
✗ Incorrect
The 'os.cpus()' method returns an array of CPU cores, so its length gives the number of cores.
What is the role of the master process in a cluster?
✗ Incorrect
The master process forks and manages worker processes in a cluster setup.
If a worker process crashes, what should the master process do?
✗ Incorrect
The master process should fork a new worker to keep the application running smoothly.
Why can't worker processes share memory directly?
✗ Incorrect
Worker processes run in separate memory spaces, so direct memory sharing is not possible.
Explain how to use the cluster module to fork workers per CPU core in Node.js.
Think about how the master process manages workers and uses CPU info.
You got /5 concepts.
Describe why forking workers per CPU core improves Node.js application performance.
Consider how multiple CPU cores can be used to do more work at the same time.
You got /5 concepts.