Тёмный

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

Software Developer Diaries
Подписаться 25 тыс.
Просмотров 33 тыс.
50% 1

In this tutorial for the "cluster" module of Node.js, we dive deep into the topic of multi-processing, load-balancing, and improved scalability of your applications. We'll explore the benefits of using the "cluster" module, how to implement the "cluster" module, how to use "fork" and some best practices.
📚 Resources:
Check out Stanley Ulili's article that this video is based on:
www.digitalocean.com/communit...
Worker Threads: • How to use Multithread...
======⚡⚡⚡======
Consider supporting the channel by clicking the "Thanks" button ❤️
👉 Get a 20% discount on Brilliant.org (to learn Science, Technology, Engineering, and Math): brilliant.sjv.io/kjVO2z
======⚡⚡⚡======
🙌 Become my Patreon and get exclusive perks: / softdevdiaries
💼 Follow me on LinkedIn and drop me a message if you'd like: / gusgadirov
💻 Also, let's connect on GitHub: github.com/gusgad
And don't forget to subscribe for more videos like this 😊

Наука

Опубликовано:

 

25 фев 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 67   
@AshrafulFerdousFariv
@AshrafulFerdousFariv Месяц назад
from version 18.14.0, it is advised to use os.availableParallelism() instead of os.cpus().length
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Месяц назад
Thanks for the hint!
@maximus4510
@maximus4510 10 месяцев назад
GOSH, I love this channel! And how your deliver the concept clearly and precisely. Thanks!!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 10 месяцев назад
Super happy to hear that you enjoy the content, my friend! ☺
@mowmiadrian8608
@mowmiadrian8608 11 месяцев назад
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 11 месяцев назад
Thanks for joining the channel, my friend! Happy to hear you like it! :)
@PaweGradziel
@PaweGradziel 7 месяцев назад
Looks really great! Thanks for the video!
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 7 месяцев назад
Thanks mate! 😉
@DudnikAndrey
@DudnikAndrey 11 месяцев назад
Thank you! Very clear explanation
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Always welcome!
@AbdulHannan-or8ql
@AbdulHannan-or8ql 2 месяца назад
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
@progressnwimuelekara2167
@progressnwimuelekara2167 8 месяцев назад
Great content man. Great channel
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 8 месяцев назад
Thanks mate!
@wasankds777
@wasankds777 3 месяца назад
Thanks a lot, This is what I looking for.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 3 месяца назад
Glad I could help!
@chafroudiyed9301
@chafroudiyed9301 9 месяцев назад
it is the best video of advanced nodejs i ever seen , keep going
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 месяцев назад
Will do, my friend!
@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!
@enogratechnologies1896
@enogratechnologies1896 3 месяца назад
Great video
@fendipratama4792
@fendipratama4792 10 месяцев назад
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
@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 :)
@shinmini99
@shinmini99 Год назад
omg, bless you.
@alphacentauri8035
@alphacentauri8035 11 месяцев назад
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 11 месяцев назад
Really happy to hear that! Keep it up mate!
@renzcarlosalanga6077
@renzcarlosalanga6077 8 месяцев назад
why? clustering means exactly what it means in the dictionary LOL what's hard about that
@alphacentauri8035
@alphacentauri8035 8 месяцев назад
@@renzcarlosalanga6077 So what you're doing here? Just check the dictionary.
@ranadenish
@ranadenish 6 часов назад
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?
@hashcode01
@hashcode01 3 месяца назад
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.
@remember387
@remember387 5 месяцев назад
Thank you , very nice - you love me !
@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 🙂
@MelroyvandenBerg
@MelroyvandenBerg 8 месяцев назад
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 8 месяцев назад
also when running this cluster setup you can't share memory, it will just spawn new processes of NodeJS.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 8 месяцев назад
Great point!
@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?
@saurabhtalele1537
@saurabhtalele1537 Месяц назад
Thanks nice.... I just want to ask in one core there are multiple processes....or processes is equal to core. ??? Thanks
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Месяц назад
By default - no, everything will run on a single core. But with the cluster mode - yes.
@mrlectus
@mrlectus Месяц назад
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
@sanjayms-so9wq
@sanjayms-so9wq 10 дней назад
helpful
@labidyramzi4840
@labidyramzi4840 6 месяцев назад
Question: Can we achieve Node app horizontal scalability(running node on multiple CPU) with only docker and kuburnetes ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 6 месяцев назад
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.
@mateuszfijak5293
@mateuszfijak5293 Год назад
how can I use __dirname in typescript?
@carlosflores4179
@carlosflores4179 10 месяцев назад
How does pm2 know that it should run in cluster mode instead of fork mode?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 месяцев назад
PM2 uses a configuration file called "ecosystem.config.js" (or "pm2.config.js") to specify exactly that
@TuanPham-ph6lr
@TuanPham-ph6lr 4 месяца назад
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 4 месяца назад
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
@user-cm7vu8ke3b
@user-cm7vu8ke3b Год назад
Hey! What service do you use to create such a good diagrams?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries Год назад
Excalidraw :)
@HelloWorld-ow1dh
@HelloWorld-ow1dh Месяц назад
i'm getting about ~250 errors even after use of cluster , before it was around ~600, how are you achieving 0 ?
@aka.theos.
@aka.theos. 6 месяцев назад
Is there any reason why to use this instead of docker and a load balancer ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 6 месяцев назад
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. 6 месяцев назад
@@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 4 месяца назад
​@@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
@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 10 месяцев назад
@@SoftwareDeveloperDiaries please create few video with lates teach and practice thanks
@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 2 месяца назад
what does this even mean ???
Далее
НЕБЛАГОДАРНЫЙ ВНУК #shorts
00:22
Просмотров 314 тыс.
Dancing makes everything better 🕺🏼
00:16
Просмотров 1,9 млн
How to handle Node.js errors like a Pro?
12:44
Просмотров 21 тыс.
Bugs, bugs and more bugs!!!
Просмотров 12
Concurrency vs Parallelism in Node.js
7:47
Просмотров 38 тыс.
Hardest Backend Node.js Concept to Master
11:20
Просмотров 64 тыс.
PROOF JavaScript is a Multi-Threaded language
8:21
Просмотров 260 тыс.
😱НОУТБУК СОСЕДКИ😱
0:30
Просмотров 2,6 млн
Избранное печатает....
0:11
Просмотров 50 тыс.
SAMSUNG S23 ULTRA🔥
0:47
Просмотров 145 тыс.