i wanna say something here, if your server doing io things instead high cpu jobs, you can set threadpool size something 256-512-1024, its because reading or writing file is blocking operation and not cpu insentetive which mean , you can handle more client but context change overhead which is ignorable for file operations
@@AkshayJaiswal It shouldn't. The Libuv Threadpool manages async IO tasks, where Worker Threads and, to my understanding, web workers, focus on userland code (i.e. your actual JS logic)
Hi, very well explained, thank you! I have a question about the v8-pool-size=num parameter. When it is good to increase the value of UV_THREADPOOL_SIZE according to the number of logical cores, what value should the parameter V8-POOL-SIZE be? Thanks in advance for the recommendation. I can't find a relevant, factually supported comment on this anywhere on the internet.
@@RoseMcSea Awesome. I’ve got some great stuff for Mongo. Need to get 2 more videos on NodeJS Performance Optimization out the way. I’ll then start diversifying. Stay tuned 😎
@@BleedingCode I am very interested in the topic of node optimization as well I am really looking forward to that, I am a bit confused on how to use clusters and redis cashing and pm2 how do we use them all together? can we use them all together? I hope your content will help, I am really looking forward to it :) thank you
@@BleedingCode thanks, however on k8s we have min cpu and max cpu config. For example, min cpu 1 core, max cpu 6 core, then what is the os.cpu.length ..
@@Dev_pig Hi there. I can't really answer that off the bat, but could you not add a console.log to your app to see what it's returning in terms of logical CPUs?
@@BleedingCode I found the answer. on k8s container, min cpu (requests.cpu) is used for choosing right node, and max cpu (limits.cpu) is what the application uses. So, if I use 8 as limits.cpu config, then application can use 8 cores from the beginning Thank u for letting me know many things :)
If you provide all of your availabile threads to nodejs, what about other proces that requires thread? Generally there are multiple process running which are hungry for threads.
Hi Dev. Thanks for commenting. Are you referring to other Node JS processes or just any process running on the VM or machine? Running of your Node app and the threads that are created happens automatically and is scheduled by the OS. It's still preferred to have access to all CPUs instead of just one, even if the other CPUs are busy. Remember it's the main thread we want to primarily keep active and performant.
Hi Anuj. Sorry for the late reply. Honestly I'm not too sure, because PM2 manages multiple instances of your Node application using either clustering or child processes. So in theory your primary Node instance is where you declare the libuv Threadpool size. Sorry, I don't use PM2 that much as I primarily run my apps in Kubernetes.
Hi There! Thanks for this video, I have a doubt! I want to use the dynamic way of using multithreading- I have dockerised my application- handled by Kubernetes, currently using VM's to manage the K8 node. Do you see any potential problem which could occur due to using dynamic way? I couldn't understand how to give it through env or CMD as using software on different VM and different Machine will require to understand core everytime so I was hoping to use the dynamic way! Your thoughts? :)
Hi there. Thanks for the feedback. There are no problems using the dynamic way. I also use Docker and deploy to k8s clusters. The most important is that the ENV is set as early as possible and not changed again 👍
Hi John, probably a silly question: you mentioned that increasing the thread pool size above the number of the logical CPU would not improve the results in the benchmark, but could it make it worse? If not wouldn't it make sense to just set the thread pool to 1024 so that all the logical cpus would be used by default?
Hi Matteo. Great question. The problem is that NodeJS will create 1024 threads, which will then be shared between all logical CPUs. It doesn't make sense, but it's what will happen. This is will have a negative effect on the logical CPUs.
Hi John, I have implemented Nodejs clustering logic in my application. in my machine there are 16 Logical cores, 8 physical cores, that means there will be 16 servers of my application, what would be the best, in this case, should I set thread pool size to 1 or 16? If we set it to 16 it's then each node server will have 16 thread pool size as I am having 16 servers and each server will have 16 thread pool size so there are gonna be 256 threads. As you said it should be equal to the Logical CPU, Could you please tell me what should be the number of thread pool if there is clustering implemented?
Hi Udit. Great question and you are absolutely right. Because you are running 16 nodejs runtimes, it's going to count to 256 threadpools, which won't make any sense. Have you seen my video on managing multiple threads using 1 runtime? Is this an option for you?
If I have to do simple writes to a NoSQL DB like Cassandra/MongoDB, then is Node js faster than Java? The number of requests per second are around 1.4 million. Thanks!
Hi Siddharth. Thanks for the comment. Unfortunately this is not a simple answer and depends greatly on infrastructure, optimization of the statements/queries, size of the tables/collections and indexes, and a number of other factors 😳
@@BleedingCode do you think I can start with node js? I am not using nosql anymore as it's relational data. So going to decide on AWS Kinesis or similar solution.
Hi There ! Thanks for the video 🤟🏼 I have a doubt. In my Nodejs application (connected to DB) .... Requests is processed and returned within 100ms but in UI it shows it took 600ms - 1.5sec, what can be the reason for this ? I am getting around 100 requests per second apart from that request... Is there any way I can debug it?
Hi there. You're very welcome for the video. Regarding the UI response being different, is it not including the download time of the response data? Postman is a great tool to check exactly where the time is going in the real world.
Thank you very much Ramsai. Tell me, do you mean installing libuv by itself? Because it comes with NodeJS. It doesn't need to be installed separately unless you want to develop apps outside the scope of NodeJS but using libuv.
@@BleedingCode thanks i think I found with the help of your video after testing with autocannon and work pool then realize if pm2 start -i max then cluster run so worker-poll and pm2cluster , nodejs with cluster master salve are same right?
@@lakshmankashyap4690 Cluster and Child Processes are actually the same...cluster just uses child processes differently. WorkerPool is different, as it uses Worker Threads and doesn't spawn child processes. This is what makes Worker Threads awesome.
Hey man, first of all thx for the video. I have a question about that topic: I am currently using the cluster module for running a processes on each cpu(in paralell), can I still use the thread pool management in addition ?
You are very welcome. Yes you can still use thread-pool management and manage how many threads will spawn instead of the default 4. However, these will be duplicated per process, because child processes or clustering (which uses child processes), does not share memory, hence it will be difficult for one libuv threadpool to interact with multiple node processes. Make sense?
@@sakshamsrivastava6280 Hey, it's up to you. But you can use it without a problem, at least I got no errors. So you can run multiple threads per process.
Hi coders 👋. I'm curious...who of you knew about this Libuv Thread Pool setting? Cheers 😎
Not enough
WOW
Please keep doing this kind of content. I am tired of beginner stuff already
Thanks for the comment. That's definitely my intention for many of my videos to come 👍.
wonderful, very clean easy, and well-structured explanation. thank you sir
Glad it was helpful :)
I subscribed in a heartbeat.
Many thanks Raphael 🙏
Brilliant ! Subscribed ! Keep going ! :)
Thank you 🙏
I do have enjoyed the video, thank you!!!
I am just starting in the nodejs path, and this video is really helpful
Thank you Rea. Glad you enjoyed it 👍👍
i wanna say something here, if your server doing io things instead high cpu jobs, you can set threadpool size something 256-512-1024, its because reading or writing file is blocking operation and not cpu insentetive which mean , you can handle more client but context change overhead which is ignorable for file operations
This is exactly i was looking for. Thank you so much this turorial was very helpfull.
You're very welcome :)
@@BleedingCode I had one question. If i use web worker in my node project will that effect thread pool?
@@AkshayJaiswal It shouldn't. The Libuv Threadpool manages async IO tasks, where Worker Threads and, to my understanding, web workers, focus on userland code (i.e. your actual JS logic)
You deserve more subscribers, keep it up 🍻
Thank you Jovert for this awesome comment 🙏
just got subscribed for this video ❤️❤️❤️❤️❤️
Thank you very much 🙏
Wow, that is amazing information and a great tutorial! Thanks so much!!
Glad you enjoyed it 👏
Hi, very well explained, thank you! I have a question about the v8-pool-size=num parameter. When it is good to increase the value of UV_THREADPOOL_SIZE according to the number of logical cores, what value should the parameter V8-POOL-SIZE be? Thanks in advance for the recommendation. I can't find a relevant, factually supported comment on this anywhere on the internet.
does dynamic configuration work as intended on a docker image?
Yes it does. I use docker containers for most of my NodeJS Apps 👍.
This is really really good stuff!
Many thanks 👍
Amazing tutorial 🤩
Thank you Ali. I really appreciate it 👍
Thank you very much, very clear explanation great content, I hope you make a video about query optimization as well :)
Thank you very much Julia. Regarding Query Optimization, are you referring to MongoDB queries, or something else? Cheers
MongoDB :)
@@RoseMcSea Awesome. I’ve got some great stuff for Mongo. Need to get 2 more videos on NodeJS Performance Optimization out the way. I’ll then start diversifying. Stay tuned 😎
@@BleedingCode I am very interested in the topic of node optimization as well I am really looking forward to that, I am a bit confused on how to use clusters and redis cashing and pm2 how do we use them all together? can we use them all together? I hope your content will help, I am really looking forward to it :) thank you
i download your code exacly but there is no effect on avarage request count by changing UV_THREADPOOL_SIZE ; what im doing wrong ?
Hmm. Seems to be the same issue to what you're having with the worker threads? Again, can you confirm your machine specs?
What if i run the application on k8s as a container?
It will work just fine. Remember, the container runs against the underlying resources that have been assigned to K8S.
@@BleedingCode thanks, however on k8s we have min cpu and max cpu config. For example, min cpu 1 core, max cpu 6 core, then what is the os.cpu.length ..
@@Dev_pig Hi there. I can't really answer that off the bat, but could you not add a console.log to your app to see what it's returning in terms of logical CPUs?
@@BleedingCode
I found the answer. on k8s container, min cpu (requests.cpu) is used for choosing right node, and max cpu (limits.cpu) is what the application uses. So, if I use 8 as limits.cpu config, then application can use 8 cores from the beginning
Thank u for letting me know many things :)
@@Dev_pig Brilliant...good catch 👏
If you provide all of your availabile threads to nodejs, what about other proces that requires thread? Generally there are multiple process running which are hungry for threads.
Hi Dev. Thanks for commenting. Are you referring to other Node JS processes or just any process running on the VM or machine? Running of your Node app and the threads that are created happens automatically and is scheduled by the OS. It's still preferred to have access to all CPUs instead of just one, even if the other CPUs are busy. Remember it's the main thread we want to primarily keep active and performant.
Will pm2 do the same stuff?
Hi Anuj. Sorry for the late reply. Honestly I'm not too sure, because PM2 manages multiple instances of your Node application using either clustering or child processes. So in theory your primary Node instance is where you declare the libuv Threadpool size. Sorry, I don't use PM2 that much as I primarily run my apps in Kubernetes.
Hi There! Thanks for this video, I have a doubt! I want to use the dynamic way of using multithreading- I have dockerised my application- handled by Kubernetes, currently using VM's to manage the K8 node. Do you see any potential problem which could occur due to using dynamic way? I couldn't understand how to give it through env or CMD as using software on different VM and different Machine will require to understand core everytime so I was hoping to use the dynamic way! Your thoughts? :)
Hi there. Thanks for the feedback. There are no problems using the dynamic way. I also use Docker and deploy to k8s clusters. The most important is that the ENV is set as early as possible and not changed again 👍
@@BleedingCode Thanks ❤️
Hi John, probably a silly question: you mentioned that increasing the thread pool size above the number of the logical CPU would not improve the results in the benchmark, but could it make it worse? If not wouldn't it make sense to just set the thread pool to 1024 so that all the logical cpus would be used by default?
Hi Matteo. Great question. The problem is that NodeJS will create 1024 threads, which will then be shared between all logical CPUs. It doesn't make sense, but it's what will happen. This is will have a negative effect on the logical CPUs.
Hi John, I have implemented Nodejs clustering logic in my application. in my machine there are 16 Logical cores, 8 physical cores, that means there will be 16 servers of my application, what would be the best, in this case, should I set thread pool size to 1 or 16?
If we set it to 16 it's then each node server will have 16 thread pool size as I am having 16 servers and each server will have 16 thread pool size so there are gonna be 256 threads.
As you said it should be equal to the Logical CPU,
Could you please tell me what should be the number of thread pool if there is clustering implemented?
Hi Udit. Great question and you are absolutely right. Because you are running 16 nodejs runtimes, it's going to count to 256 threadpools, which won't make any sense. Have you seen my video on managing multiple threads using 1 runtime? Is this an option for you?
Pretty sur @BleedingCodes CPU also has more logical cores than he states in the video.
Ah... it comes a minute later...
If I have to do simple writes to a NoSQL DB like Cassandra/MongoDB, then is Node js faster than Java? The number of requests per second are around 1.4 million. Thanks!
Hi Siddharth. Thanks for the comment. Unfortunately this is not a simple answer and depends greatly on infrastructure, optimization of the statements/queries, size of the tables/collections and indexes, and a number of other factors 😳
@@BleedingCode do you think I can start with node js? I am not using nosql anymore as it's relational data. So going to decide on AWS Kinesis or similar solution.
@@TheSiddhaartha Yes you can absolutely. NodeJS is powerful enough to do the job, but again...many many factors at play :)
Hi There ! Thanks for the video 🤟🏼
I have a doubt.
In my Nodejs application (connected to DB) .... Requests is processed and returned within 100ms but in UI it shows it took 600ms - 1.5sec, what can be the reason for this ? I am getting around 100 requests per second apart from that request... Is there any way I can debug it?
Hi there. You're very welcome for the video. Regarding the UI response being different, is it not including the download time of the response data? Postman is a great tool to check exactly where the time is going in the real world.
Subscribed Loved the video and also can you please please make a video on how to install Libuv and how to use it in production ?
Thank you very much Ramsai. Tell me, do you mean installing libuv by itself? Because it comes with NodeJS. It doesn't need to be installed separately unless you want to develop apps outside the scope of NodeJS but using libuv.
@@BleedingCode Thanks you so much I don't know it comes with Nodejs . So now I can use Libuv in nodejs itself how you instructed in the video ?
If I using pm2 on server so is it necessary to implement workthread in high performance task in nodejs
Hi there. It depends on how you've set up clustering using PM2. If you already have clustering running for your runtime, then leave it be.
@@BleedingCode thanks i think I found with the help of your video after testing with autocannon and work pool then realize if pm2 start -i max then cluster run
so worker-poll and pm2cluster , nodejs with cluster master salve are same
right?
@@lakshmankashyap4690 Cluster and Child Processes are actually the same...cluster just uses child processes differently. WorkerPool is different, as it uses Worker Threads and doesn't spawn child processes. This is what makes Worker Threads awesome.
Hey man, first of all thx for the video.
I have a question about that topic: I am currently using the cluster module for running a processes on each cpu(in paralell), can I still use the thread pool management in addition ?
You are very welcome. Yes you can still use thread-pool management and manage how many threads will spawn instead of the default 4. However, these will be duplicated per process, because child processes or clustering (which uses child processes), does not share memory, hence it will be difficult for one libuv threadpool to interact with multiple node processes.
Make sense?
@@BleedingCode I do understand, thank you very much.
@@MrBrainStarX Hey, can you please help me out with the explaination if you understood ? should we use it with it or not
@@sakshamsrivastava6280 Hey, it's up to you. But you can use it without a problem, at least I got no errors. So you can run multiple threads per process.
Font size too small
Sorry about that. Didn't realize it at the time, but my future videos will support mobile much better, which will resolve the font size 👍