Differences between Node.js Thread Pool and Clustering Node.js
NickName:rouzbehsbz Ask DateTime:2022-08-26T21:43:41

Differences between Node.js Thread Pool and Clustering Node.js

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

More about “Differences between Node.js Thread Pool and Clustering Node.js” related questions

Differences between Node.js Thread Pool and Clustering Node.js

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

Show Detail

Node.js thread pool vs worker_thread

thread pool size can be determined with UV_THREADPOOL_SIZE. Worker_thread can create threads dynamically in runtime. Is this a only difference between thread pool and worker thread? Recently, I'm...

Show Detail

Confusion on Node.js thread pool

Doesn't the fact that Node.js uses a thread-pool to queue system calls defeat its overall purpose? My understanding is that Node.js provides for purely event-based code via an event loop, however, if

Show Detail

Node.js single thread VS Tranditonal webserver thread pool

I am a newbie to node.js. I am currently reading the book called 'Beignning Node.js' by Basarat Ali Syed. Here is an excerpt from it which states the disadvantage of thread pool of traditional web

Show Detail

Node.js thread pool and core usage

I've read tons of articles and stackoverflow questions, and I saw a lot of information about thread pool, but no one talks about physical CPU core usage. I believe this question is not duplicated.

Show Detail

Is the task of Web API in browser same as the task of thread pool in Node.Js?

For Javascript in Browser and node.js, I am trying to understand the difference between the thread pool and Web API. Both the thread pool, and Web API, enable Javascript to handle asynchronous beha...

Show Detail

Does node.js use threads/thread pool internally?

I've decided to familiarize myself with node.js and have read a several articles on the subject. What remained unclear to me is if node.js creates new threads and/or schedules tasks on threads from a

Show Detail

Node.js clustering vs multiple Docker containers

From what I understand, Docker containers use multiple threads, and Node.js applications use only a single thread. By running something like pm2, which handles Node.js clustering, I could utilize all

Show Detail

What are the differences between node.js and node?

I've installed node.js in my machine (linux mint 15), when I run node example.js, it says: The program 'node' can be found in the following packages: * node * nodejs-legacy Try: sudo apt-get ins...

Show Detail

Node.js Multi Server Clustering

I'm working on a project with Node.js that involves a server (for the sake of simplicity let's imagine this server as a chat server which have to forward messages from certain clients to other clie...

Show Detail