Bird
0
0

You want to create a Node.js cluster that uses all CPU cores and restarts any worker that crashes. Which approach correctly implements this?

hard📝 Application Q15 of 15
Node.js - Cluster Module
You want to create a Node.js cluster that uses all CPU cores and restarts any worker that crashes. Which approach correctly implements this?
ACreate workers manually without cluster module and restart them with setInterval
BUse cluster.fork() once and rely on master to restart automatically
CUse cluster.fork() for each CPU core and listen to 'exit' event to fork a new worker
DUse cluster.isWorker to fork new workers inside each worker process
Step-by-Step Solution
Solution:
  1. Step 1: Use all CPU cores with cluster.fork()

    Fork one worker per CPU core by looping over the number of CPUs.
  2. Step 2: Restart crashed workers by listening to 'exit'

    Listen to the 'exit' event on cluster to detect worker crashes and fork a new worker to replace it.
  3. Final Answer:

    Use cluster.fork() for each CPU core and listen to 'exit' event to fork a new worker -> Option C
  4. Quick Check:

    Fork per CPU + restart on exit [OK]
Quick Trick: Fork per CPU and restart on 'exit' event [OK]
Common Mistakes:
  • Forking only once and expecting auto-restart
  • Restarting workers inside workers themselves
  • Not handling worker crashes properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes