Recently I've been researching about Node.js core architecture, but still I don't understand some concepts.
So assume that I have 6 core CPU and it's an Intel CPU, so actually I have 12 logical processors for threads for any execution in my computer that needs CPU, on the other hand Node.js and all of it's core components such as libuv and V8 engine are all running in a single thread.
Now for I/O tasks that consumes resources like disk for example, or other inner C/C++ node.js modules, the libuv have thread pool with maximum size of 4, This means that libuv can request OS for do 4 tasks in parallel (exactly at same time). Now in this situation OS do the work of context switching for node.js threads because they have higher priority and complete its tasks.
This is what I learned about Node.js event loop.
Now I want to know how clustering node.js app (forking and run multiple processers) is going to improve the entire application performance.
If I run 12 clusters from my node app (cause I have 12 logical CPU processors) and each node.js process have 4 running I/O async jobs, that means that we have 48 threads but only 12 of them can run at the time and the other tasks must wait.
So is it not better to just increase libuv thread pool size to 11 (and 1 for node.js main thread) and just have one node.js process ? instead of clustering them ?
What I'm missing here ? can someone explain how clustering can increase performance ?
and what about clustering and increase libuv thread pool size together ?
Copyright Notice:Content Author:「rouzbehsbz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73501982/differences-between-node-js-thread-pool-and-clustering-node-js