Bird
0
0

You have a Node.js server that handles many HTTP requests and also performs heavy image processing. How should you design your app using workers and cluster for best performance?

hard📝 Application Q15 of 15
Node.js - Worker Threads
You have a Node.js server that handles many HTTP requests and also performs heavy image processing. How should you design your app using workers and cluster for best performance?
AUse only workers to run multiple server instances and process images
BUse cluster to run multiple server processes and workers inside each process for image processing
CUse only cluster to handle requests and do image processing in the main thread
DUse a single process with no workers or cluster for simplicity
Step-by-Step Solution
Solution:
  1. Step 1: Understand cluster for scaling servers

    Cluster creates multiple processes to handle many HTTP requests efficiently by using multiple CPU cores.
  2. Step 2: Use workers for CPU-heavy tasks

    Heavy image processing should run in worker threads to avoid blocking the event loop in each server process.
  3. Step 3: Combine cluster and workers

    Run cluster to scale server processes, and inside each process, use workers for heavy computation tasks.
  4. Final Answer:

    Use cluster to run multiple server processes and workers inside each process for image processing -> Option B
  5. Quick Check:

    Cluster for scaling + workers for CPU tasks [OK]
Quick Trick: Cluster scales servers; workers handle heavy tasks inside each process [OK]
Common Mistakes:
  • Doing heavy tasks in main thread blocking requests
  • Using only workers without clustering for many requests
  • Ignoring multi-core CPU benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes