Increase Node JS Performance With Thread Pool Management 📊 | OPTIMIZING NODE JS

  Рет қаралды 15,882

Bleeding Code (By John Jardin)

Bleeding Code (By John Jardin)

Күн бұрын

Пікірлер: 89
@BleedingCode
@BleedingCode 4 жыл бұрын
Hi coders 👋. I'm curious...who of you knew about this Libuv Thread Pool setting? Cheers 😎
@LawZist
@LawZist 3 жыл бұрын
Not enough
@Omer23007
@Omer23007 2 жыл бұрын
WOW
@juraev0056
@juraev0056 3 жыл бұрын
Please keep doing this kind of content. I am tired of beginner stuff already
@BleedingCode
@BleedingCode 3 жыл бұрын
Thanks for the comment. That's definitely my intention for many of my videos to come 👍.
@aminazgol3918
@aminazgol3918 10 ай бұрын
wonderful, very clean easy, and well-structured explanation. thank you sir
@BleedingCode
@BleedingCode 9 ай бұрын
Glad it was helpful :)
@grijjly6091
@grijjly6091 Жыл бұрын
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
@reanibutani9555
@reanibutani9555 3 жыл бұрын
I do have enjoyed the video, thank you!!! I am just starting in the nodejs path, and this video is really helpful
@BleedingCode
@BleedingCode 3 жыл бұрын
Thank you Rea. Glad you enjoyed it 👍👍
@DR-ee4wv
@DR-ee4wv 2 жыл бұрын
just got subscribed for this video ❤️❤️❤️❤️❤️
@BleedingCode
@BleedingCode 2 жыл бұрын
Thank you very much 🙏
@kid_kulafu_1727
@kid_kulafu_1727 4 жыл бұрын
I subscribed in a heartbeat.
@BleedingCode
@BleedingCode 4 жыл бұрын
Many thanks Raphael 🙏
@AkshayJaiswal
@AkshayJaiswal 2 жыл бұрын
This is exactly i was looking for. Thank you so much this turorial was very helpfull.
@BleedingCode
@BleedingCode 2 жыл бұрын
You're very welcome :)
@AkshayJaiswal
@AkshayJaiswal 2 жыл бұрын
@@BleedingCode I had one question. If i use web worker in my node project will that effect thread pool?
@BleedingCode
@BleedingCode 2 жыл бұрын
@@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)
@jovert2445
@jovert2445 4 жыл бұрын
You deserve more subscribers, keep it up 🍻
@BleedingCode
@BleedingCode 4 жыл бұрын
Thank you Jovert for this awesome comment 🙏
@arunavachakraborty5557
@arunavachakraborty5557 3 жыл бұрын
Brilliant ! Subscribed ! Keep going ! :)
@BleedingCode
@BleedingCode 3 жыл бұрын
Thank you 🙏
@snoblik69
@snoblik69 9 ай бұрын
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.
@markmiller8571
@markmiller8571 3 жыл бұрын
Wow, that is amazing information and a great tutorial! Thanks so much!!
@BleedingCode
@BleedingCode 3 жыл бұрын
Glad you enjoyed it 👏
@matthew78uk
@matthew78uk 2 жыл бұрын
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?
@BleedingCode
@BleedingCode 2 жыл бұрын
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.
@ahlambeyoud1709
@ahlambeyoud1709 3 жыл бұрын
Thank you very much, very clear explanation great content, I hope you make a video about query optimization as well :)
@BleedingCode
@BleedingCode 3 жыл бұрын
Thank you very much Julia. Regarding Query Optimization, are you referring to MongoDB queries, or something else? Cheers
@ahlambeyoud1709
@ahlambeyoud1709 3 жыл бұрын
MongoDB :)
@BleedingCode
@BleedingCode 3 жыл бұрын
@@ahlambeyoud1709 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 😎
@ahlambeyoud1709
@ahlambeyoud1709 3 жыл бұрын
@@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
@aminazgol3918
@aminazgol3918 10 ай бұрын
does dynamic configuration work as intended on a docker image?
@BleedingCode
@BleedingCode 9 ай бұрын
Yes it does. I use docker containers for most of my NodeJS Apps 👍.
@AndrosAndWindows
@AndrosAndWindows 3 жыл бұрын
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 ?
@BleedingCode
@BleedingCode 3 жыл бұрын
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.
@AndrosAndWindows
@AndrosAndWindows 3 жыл бұрын
@@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 ?
@LawZist
@LawZist 3 жыл бұрын
This is really really good stuff!
@BleedingCode
@BleedingCode 3 жыл бұрын
Many thanks 👍
@inclinedscorpio
@inclinedscorpio 2 жыл бұрын
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? :)
@BleedingCode
@BleedingCode 2 жыл бұрын
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 👍
@inclinedscorpio
@inclinedscorpio 2 жыл бұрын
@@BleedingCode Thanks ❤️
@aliarslanansari
@aliarslanansari 3 жыл бұрын
Amazing tutorial 🤩
@BleedingCode
@BleedingCode 3 жыл бұрын
Thank you Ali. I really appreciate it 👍
@blameItleaveit
@blameItleaveit 3 жыл бұрын
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.
@BleedingCode
@BleedingCode 3 жыл бұрын
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.
@ashutoshtiwari4258
@ashutoshtiwari4258 2 жыл бұрын
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?
@BleedingCode
@BleedingCode 2 жыл бұрын
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.
@all_top_5_features
@all_top_5_features 3 жыл бұрын
Will pm2 do the same stuff?
@BleedingCode
@BleedingCode 3 жыл бұрын
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.
@MrBrainStarX
@MrBrainStarX 3 жыл бұрын
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 ?
@BleedingCode
@BleedingCode 3 жыл бұрын
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?
@MrBrainStarX
@MrBrainStarX 3 жыл бұрын
@@BleedingCode I do understand, thank you very much.
@sakshamsrivastava6280
@sakshamsrivastava6280 3 жыл бұрын
@@MrBrainStarX Hey, can you please help me out with the explaination if you understood ? should we use it with it or not
@MrBrainStarX
@MrBrainStarX 3 жыл бұрын
@@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.
@TheSiddhaartha
@TheSiddhaartha 3 жыл бұрын
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!
@BleedingCode
@BleedingCode 3 жыл бұрын
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 😳
@TheSiddhaartha
@TheSiddhaartha 3 жыл бұрын
@@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.
@BleedingCode
@BleedingCode 3 жыл бұрын
@@TheSiddhaartha Yes you can absolutely. NodeJS is powerful enough to do the job, but again...many many factors at play :)
@uditsoni24
@uditsoni24 2 жыл бұрын
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?
@BleedingCode
@BleedingCode 2 жыл бұрын
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?
@habutf
@habutf Жыл бұрын
Pretty sur @BleedingCodes CPU also has more logical cores than he states in the video.
@habutf
@habutf Жыл бұрын
Ah... it comes a minute later...
@rage128
@rage128 2 жыл бұрын
i download your code exacly but there is no effect on avarage request count by changing UV_THREADPOOL_SIZE ; what im doing wrong ?
@BleedingCode
@BleedingCode 2 жыл бұрын
Hmm. Seems to be the same issue to what you're having with the worker threads? Again, can you confirm your machine specs?
@Dev_pig
@Dev_pig 2 жыл бұрын
What if i run the application on k8s as a container?
@BleedingCode
@BleedingCode 2 жыл бұрын
It will work just fine. Remember, the container runs against the underlying resources that have been assigned to K8S.
@Dev_pig
@Dev_pig 2 жыл бұрын
@@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 ..
@BleedingCode
@BleedingCode 2 жыл бұрын
@@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?
@Dev_pig
@Dev_pig 2 жыл бұрын
@@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 :)
@BleedingCode
@BleedingCode 2 жыл бұрын
@@Dev_pig Brilliant...good catch 👏
@lakshmankashyap4690
@lakshmankashyap4690 3 жыл бұрын
If I using pm2 on server so is it necessary to implement workthread in high performance task in nodejs
@BleedingCode
@BleedingCode 3 жыл бұрын
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.
@lakshmankashyap4690
@lakshmankashyap4690 3 жыл бұрын
@@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?
@BleedingCode
@BleedingCode 3 жыл бұрын
@@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.
@ngneerin
@ngneerin 3 жыл бұрын
Font size too small
@BleedingCode
@BleedingCode 2 жыл бұрын
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 👍
Managing Multiple Threads In Node JS 🧵 | OPTIMIZING NODE JS
9:32
Bleeding Code (By John Jardin)
Рет қаралды 23 М.
How To Determine Application Baseline Performance In Node JS 🔬 | OPTIMIZING NODE JS
18:41
Bleeding Code (By John Jardin)
Рет қаралды 4,3 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 17 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 20 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 107 МЛН
Deadpool family by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 7 МЛН
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 661 М.
Managing The Event Loop Phases ⭕️ | OPTIMIZING NODE JS
23:32
Bleeding Code (By John Jardin)
Рет қаралды 19 М.
How To Test Your API Server Availability 🚀 | OPTIMIZING NODE JS
10:29
Bleeding Code (By John Jardin)
Рет қаралды 4 М.
When is NodeJS Single-Threaded and when is it Multi-Threaded?
18:42
Hussein Nasser
Рет қаралды 74 М.
Skyrocket Your API Performance with These Techniques
8:06
Daily Code Buffer
Рет қаралды 15 М.
Mastering Memory Management in Node.js: Tips and Tricks for Better Performance
16:06
Software Developer Diaries
Рет қаралды 39 М.
Testing For Async Functions In NodeJS 💻  | OPTIMIZING NODE JS
21:10
Bleeding Code (By John Jardin)
Рет қаралды 4,6 М.
How to make your Node.js API 5x faster!
16:39
Adventures in Nodeland - Matteo Collina
Рет қаралды 11 М.
How to use "Streams" to improve performance in Node.js?
12:22
Software Developer Diaries
Рет қаралды 25 М.
Go vs Rust vs Bun vs Node | Prime Reacts
18:07
ThePrimeTime
Рет қаралды 176 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 17 МЛН