0
0
Node.jsframework~5 mins

Forking workers per CPU core in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Acluster
Bhttp
Cfs
Devents
How do you find the number of CPU cores in Node.js?
Aos.cpus().length
Bos.cpuCount()
Cprocess.cpuCount
Dos.cores()
What is the role of the master process in a cluster?
AHandles all HTTP requests alone
BRuns the database
CForks worker processes and manages them
DManages file system operations
If a worker process crashes, what should the master process do?
ALog the error and stop all workers
BRestart the entire server
CDo nothing
DFork a new worker to replace it
Why can't worker processes share memory directly?
ABecause Node.js forbids it
BBecause they run in separate processes
CBecause of network restrictions
DBecause of file system locks
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.