Scaling your Node.js app using the "cluster" module

  Рет қаралды 48,250

Software Developer Diaries

Software Developer Diaries

Күн бұрын

Пікірлер
@AshrafulFerdousFariv
@AshrafulFerdousFariv 7 ай бұрын
from version 18.14.0, it is advised to use os.availableParallelism() instead of os.cpus().length
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 7 ай бұрын
Thanks for the hint!
@KinoPM2
@KinoPM2 5 ай бұрын
Are you looking for job in Crypto Project? MERN
@vivekbhatti
@vivekbhatti 4 ай бұрын
Yes i am ​@@KinoPM2
@moveonvillain1080
@moveonvillain1080 3 ай бұрын
​@@KinoPM2 Hire me 😅
@sergiobenitez1468
@sergiobenitez1468 3 ай бұрын
this playlist is a goldmine
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 3 ай бұрын
Thanks mate!
@samworldpk
@samworldpk 22 күн бұрын
using this in production with AWS LB and 2 ec2 instances of 4cores and the results are extremely impressive, now downtimes or performance issues in past 5 years.
@AlexanderWunschik
@AlexanderWunschik 3 ай бұрын
This is super exciting and promising. Thanks for the excellent introduction!
@AbdulHannan-or8ql
@AbdulHannan-or8ql 8 ай бұрын
Hi! Your approach by identifying a problem and then solving it is blazingly great 😃 But please make a video on Difference between Cluster and Multi threads? As both utilizing all cpu cores I am looking forward to hear from you
@kooshaforoughi8778
@kooshaforoughi8778 5 ай бұрын
Man i love your videos, you're a very good teacher, you teach advanced topics clearly and with ease. thank you for teaching me! keep going!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 5 ай бұрын
Glad to hear that! 🤓
@vardaanaashish6753
@vardaanaashish6753 3 ай бұрын
This was wonderfully explained!
@maximus4510
@maximus4510 Жыл бұрын
GOSH, I love this channel! And how your deliver the concept clearly and precisely. Thanks!!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Super happy to hear that you enjoy the content, my friend! ☺
@MelroyvandenBerg
@MelroyvandenBerg Жыл бұрын
Keep in mind cluster is not core-pinning.. It just run on whatever core/thread it would like. Also you can still combine the nodejs cluster feature with workers, which in bigger calculations might help to un-block the main thread. Since nodejs is semi-multithreaded by default.
@MelroyvandenBerg
@MelroyvandenBerg Жыл бұрын
also when running this cluster setup you can't share memory, it will just spawn new processes of NodeJS.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Great point!
@AViStudioMoldova
@AViStudioMoldova 5 ай бұрын
Very clean and good explanation! You're good! Keep going! Thanks!
@chafroudiyed9301
@chafroudiyed9301 Жыл бұрын
it is the best video of advanced nodejs i ever seen , keep going
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Will do, my friend!
@Ad9911io
@Ad9911io Жыл бұрын
My team lead explained me about clustering a few times and i didn't get shit, it sounded like a super complex thing when he talked about it. Your explanation was super easy to understand!! Thanks alot!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Really happy to hear that! Keep it up mate!
@renzcarlosalanga6077
@renzcarlosalanga6077 Жыл бұрын
why? clustering means exactly what it means in the dictionary LOL what's hard about that
@Ad9911io
@Ad9911io Жыл бұрын
@@renzcarlosalanga6077 So what you're doing here? Just check the dictionary.
@deepakkewalramani08
@deepakkewalramani08 Ай бұрын
Great explained 👏
@lautarogabrielgonzalezscho1177
@lautarogabrielgonzalezscho1177 3 ай бұрын
Amazing information, thanks for sharing!
@mowmiadrian8608
@mowmiadrian8608 Жыл бұрын
Bro, I love it when I find a gem like this. Thank you, I was looking for a quality this channel has to offer for very long time. I'm definitely going to subscribe!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Thanks for joining the channel, my friend! Happy to hear you like it! :)
@bryannsi
@bryannsi 3 ай бұрын
amazing video, and very well explanation
@wasankds777
@wasankds777 9 ай бұрын
Thanks a lot, This is what I looking for.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 ай бұрын
Glad I could help!
@hashcode01
@hashcode01 9 ай бұрын
Thank you for the clear explanation. One thing to note is that a single instance still utilizes multithreading for asynchronous operations with libuv. Cluster is advantageous for synchronous operations, as shown in your example.
@anton1492
@anton1492 Жыл бұрын
your videos are awesome man! i usually don't write comments but your channel is so undersubscribed!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
I appreciate that, my friend :)
@PaweGradziel
@PaweGradziel Жыл бұрын
Looks really great! Thanks for the video!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Thanks mate! 😉
@DudnikAndrey
@DudnikAndrey Жыл бұрын
Thank you! Very clear explanation
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Always welcome!
@lexNwimue
@lexNwimue Жыл бұрын
Great content man. Great channel
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Thanks mate!
@shinmini99
@shinmini99 Жыл бұрын
omg, bless you.
@aliadel1723
@aliadel1723 Ай бұрын
can you talk about batch processing in nodejs
@enogratechnologies1896
@enogratechnologies1896 9 ай бұрын
Great video
@ranadenish
@ranadenish 5 ай бұрын
Can we use cluster module for "SMPP Protocol" faster performance? SMPP is stateful connections, so I am not getting the full output using cluster, any hint?
@mrlectus
@mrlectus 7 ай бұрын
What is the difference between loadtest vs ab (apache bench) when i use loadtest The total errors was 500+ but with ab i didn't get any errors and i passed in the same metric as you did. This was an on code without cluster
@tryzack
@tryzack 5 ай бұрын
hi, i have a problem here, I've done everything like in the video but the workers wont work? the loadtest was arguably the same as the first time, so to check by myself i made another route without any load to check if i could make a get from that one while the heavy one was still loading and the answer was no, it waits for heavy get to complete before actually doing the main get, its like everything was going to the same worker instead of trying to use different workers, i have 12 cores so it should work...
@saurabhtalele1537
@saurabhtalele1537 7 ай бұрын
Thanks nice.... I just want to ask in one core there are multiple processes....or processes is equal to core. ??? Thanks
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 6 ай бұрын
By default - no, everything will run on a single core. But with the cluster mode - yes.
@labidyramzi4840
@labidyramzi4840 Жыл бұрын
Question: Can we achieve Node app horizontal scalability(running node on multiple CPU) with only docker and kuburnetes ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
In theory yes, but I wouldn't suggest combining them. If your application is relatively simple and you prioritize simplicity, Node.js cluster mode may be suitable. If you need advanced orchestration, infrastructure flexibility, and are planning for future growth, Kubernetes might be the better option. Ultimately, the decision depends on your specific use case, requirements, and the resources available to your team.
@fendipratama4792
@fendipratama4792 Жыл бұрын
thank you for your sharing master, I have a question 'if I have 3 servers, running index.js from each server, how to execute index.js from different server?' any response will be highly appreciated
@KaleesM-tm4lw
@KaleesM-tm4lw 2 ай бұрын
That's why he said once you start your node server by running the node index.js. the node master will distribute the request across multiple instances which you've already spawned... So NVM about which server you wanna to run...
@prokhorov_sergey_igorevich
@prokhorov_sergey_igorevich Жыл бұрын
If we have 8 cpu, the primary script use 1 cpu and remain 7 for the application? Conclusion, if we have 2 cpu - it's doesn't work?
@code_react
@code_react Жыл бұрын
Ok this is very awesome. I have been watching all of other videos on your channel and trust me your videos convinced me to subscribe to your channel. I can't wait to see more topics like this. And many many thanks for taking your time to make these videos.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Thanks for such nice words, my friend!
@KinoPM2
@KinoPM2 4 ай бұрын
Any way to not reconnect to MongoDB in each cluster ?
@sanjayms-so9wq
@sanjayms-so9wq 6 ай бұрын
helpful
@ArshRadhanpura
@ArshRadhanpura 2 ай бұрын
does it make sense to use this with docker and kubernetes?
@oliverhsu9465
@oliverhsu9465 2 ай бұрын
With containerization, you just add more replicas.
@carlosflores4179
@carlosflores4179 Жыл бұрын
How does pm2 know that it should run in cluster mode instead of fork mode?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
PM2 uses a configuration file called "ecosystem.config.js" (or "pm2.config.js") to specify exactly that
@vaibhavm1986
@vaibhavm1986 Жыл бұрын
Hi , Thanks I am looking something similar , just want to understand , making clustering this way , or having replica instances via docker , is there any difference between or better as compared to other what is the recommended way ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
That’s a great question. In theory both approaches allow the so called “horizontal scaling”. When going with Node.js clusters, you’re limited to one machine your cluster is running on. So it’s not optimal for complex apps with very heavy loads, since this machine will be the single point of failure. Node.js cluster is a good idea if you have obvious parallel processing scenarios. However, if you have a complex application that requires multiple machines deployed across multiple environments for example, then Docker can be a better choice. At the end of the day, you can actually try combining them. Run a Node.js cluser on multiple Docker instances.
@vaibhavm1986
@vaibhavm1986 Жыл бұрын
Thanks 🙂
@HelloWorld-ow1dh
@HelloWorld-ow1dh 7 ай бұрын
i'm getting about ~250 errors even after use of cluster , before it was around ~600, how are you achieving 0 ?
@internetexplorer7880
@internetexplorer7880 5 ай бұрын
Wait i thought pm2 spawns only 1 if you use that command
@aka.theos.
@aka.theos. Жыл бұрын
Is there any reason why to use this instead of docker and a load balancer ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Great question. I would use Node.js "cluster" mode when you have a simple application on a single server and want to scale it horizontally across CPU cores for improved performance. But choose Kubernetes with Docker and Load Balancing when dealing with complex, distributed applications that require container orchestration, horizontal scaling across multiple servers, and advanced features like automatic scaling, rolling updates, and service discovery. It's well-suited for cloud-native architectures.
@aka.theos.
@aka.theos. Жыл бұрын
@@SoftwareDeveloperDiaries Your content is really good I hope you continue to cover advanced topics because not many channels cover them in details like you do
@roonywalsh8183
@roonywalsh8183 10 ай бұрын
​@@SoftwareDeveloperDiaries would making a Nodejs cluster in each docker instance be a good idea. Wouldn't it lead to optimization of each server's usage
@DmitryHolubev
@DmitryHolubev Жыл бұрын
Hey! What service do you use to create such a good diagrams?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Excalidraw :)
@TuanPham-ph6lr
@TuanPham-ph6lr 10 ай бұрын
Execuse me, I am new with Nodejs so I have a question, the cpu count is the cpu of the server or cpu of user's computer ? Hope you response me soon.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 10 ай бұрын
Hello there! The answer is: the CPU count on the machine that the Node.js app is running on. You’ll be most likely deploying it on the server at the end of the day, so it’s the one that really counts.
@hakanangin
@hakanangin Жыл бұрын
Hi, thanks you explanation. I take an error when runing loadtest. What is problem? Error is = node:events:491 throw er; // Unhandled 'error' event ^ Error: read ENOTCONN
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Is there anything else that the error message says? Have you made sure that in package.json you "type": "module" like in the video? I've googled the error and it seems like it's mostly caused by another process running on the same port.
@mjprakash1780
@mjprakash1780 Жыл бұрын
@@SoftwareDeveloperDiaries facing same issue
@korkut31
@korkut31 Жыл бұрын
neden 2 Turk inglizce laf edersiniz, danisirsiniz ? neyse. node 16.19.1 versiyonu ile hata vermiyor. node 18.15.0 ile bende hata aldim .
@storylineteam
@storylineteam Жыл бұрын
Run the loadtest command in a new terminal window outside of vscode
@qureshiowais6951
@qureshiowais6951 Жыл бұрын
How Do we make rest API with cluster?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Same way you would make an ordinary Node.js API with Express, but in this case the entrypoint is primary.js, meaning it opens the port and serves the application.
@qureshiowais6951
@qureshiowais6951 Жыл бұрын
@@SoftwareDeveloperDiaries please create few video with lates teach and practice thanks
@mateuszfijak5293
@mateuszfijak5293 Жыл бұрын
how can I use __dirname in typescript?
@themaridv2000
@themaridv2000 5 ай бұрын
It comes by default
@marwanFX483
@marwanFX483 Жыл бұрын
does this create race condition problem ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Жыл бұрын
Totally. It all depends on the use case and code that you've written.
@cloudpg0788
@cloudpg0788 8 ай бұрын
what does this even mean ???
@internetexplorer7880
@internetexplorer7880 5 ай бұрын
Scenario: You go out for dinner in a new restaurant. 1st case: There's only one cook, so if the cook is busy making food for someone else you have to wait a long time for your order 2nd case: There are now multiple cooks, so if other people's food takes time, yours won't
When to use Node.js "cluster" vs "worker thread"? #Shorts
0:41
Software Developer Diaries
Рет қаралды 39 М.
How to use Multithreading with "worker threads" in Node.js?
19:34
Software Developer Diaries
Рет қаралды 72 М.
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 58 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 46 МЛН
Data transfer to/from Rackham using SCP
4:45
Richel J.C. Bilderbeek
Рет қаралды 3
API Gateway vs Load Balancer vs Reverse Proxy: when to use what?
9:06
Software Developer Diaries
Рет қаралды 25 М.
How to scale NodeJs applications using the cluster module.
13:37
Mafia Codes
Рет қаралды 51 М.
API Gateway Vs Load balancer - Simplified Explanation
15:26
TechWithShas
Рет қаралды 1,3 М.
Node.js Security Best Practices: JWT blacklisting, rate limiting, schema validation
12:02
Node.js Doesn’t Suck Anymore
16:59
Web Dev Simplified
Рет қаралды 128 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 290 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 659 М.
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24