When is NodeJS Single-Threaded and when is it Multi-Threaded?

preview_player
Показать описание
Node JS Is single threaded asynchronous non-blocking javascript runtime, but its not always single threaded there are occasions where nodejs uses multi-threading, so the questions we will try to answer in this video, when is nodejs single threaded and when does it use multi-threading and how will that affect my app?

* Event main Loop 0:00 single thread, that really just loops for callbacks
* Threading in Node jS (libuv) 4:00
* used for
* IO/intensive
* DNS queries
* file system reads
* CPU intensive
* crypto
* compression

Examples 8:00
Cluster Nodejs 16:00

Example 1
Http server return 1
Http server while 1
Http server with file system read async
Http server with file system read sync
Http server with fetch call to server (dns)

Resources

🎙️Listen to the Backend Engineering Podcast

🏭 Backend Engineering Videos

💾 Database Engineering Videos

🏰 Load Balancing and Proxies Videos

🏛️ Software Archtiecture Videos

📩 Messaging Systems

Become a Member

Support me on PayPal


Stay Awesome,
Hussein
Рекомендации по теме
Комментарии
Автор

The lagging in the first 2 minutes is part of the demonstration of single threaded model and totally not because I had docker running on the background with 10 large postgres instances. 😝

hnasr
Автор

I wanna add one thing.
Event loop is not the one that executes functions on the call stack. That is done by javascript engine. Event loop monitors the call stack and event queue. when the call stack is empty it looks for the event in event queue, if found executes the associated callback which will be added to the call stack.

tezzbhandari
Автор

Am I the only one for whom the video feels choppy, like a lot

EDIT: Just for the first 2 minutes

jaidewani
Автор

Great content man! The clusterization part is very interesting for me, and the clarification about the UV lib is gonna be of very much help! Keep doing great videos as such.

rafaelcascalho
Автор

This was the best video I watched on youtube regarding Nodejs and threading. Thank you so much!

haeunkang
Автор

goddamn this is the clearest and most concise explanation of nodeJs event loop and scaling

jamessaballegue
Автор

Amazing content Hussein ! Learning so much from this one single video !

AdarshMenon
Автор

very detailed explanations, really hard to find these days. Keep making these kind of videos. Really appreciate it

rishavkumar
Автор

Hussein, your camera seems to be running on single thread, video is little choppy 😄
But still, great content as usual

Edit - Just the first 2 minutes

RM-baba
Автор

Can you make video discussing node event loop and each of it's phases.

muhammadsami
Автор

With great content coming one after another, I was expecting some kind of illustrations that you do via the presentation of gliffy. That clears out the real deal with the event loop. Great content as always. 👍🙌

akkimahajan
Автор

Nice vid, though forgot to mention another major use case where node uses it's threadpool - submitting new requests into the event queue (as callbacks). Not executing it, just submitting it becauss the main thread can be busy.

mtnrabi
Автор

Which one should we use for scaling nodejs app cluster module or worker thread?

sankalpsinha
Автор

first 2 minutes of choppiness is due to i/o blocking of matrix

animatedzombie
Автор

Thanks Naseer, for clarifying doubt on thread

praveenkubasad
Автор

Can you please these quick questions and clear the confusion?

1. Is Event Loop single threaded or due to one call stack, Node.js is threaded?
2. Isn't the purpose of Event Loop just to check whether the call stack is empty or not and bring instructions from queues to call stack? Or there is more to it?
3. Is event loop implemented in a different way in browser and node.js?
4. When we send network request or use setTimeout, does the Web API container spawns new threads for these operations? For e.g. there is an API call in the code. The call gets out of Call stack and goes to Web API container. When it completes, it comes to Callback/Priority Queue and from there it comes back to Call Stack when Call Stack is empty.
But what happens in Web API container? Does it spawns a new thread for network request and setTimeout? What happens there exactly?

Atif
Автор

16:00 Love the Clustering Nodejs part, I need to learn more about scaling Node.js

pieter
Автор

Learned a lot. Please don't stop making awesome content.

ashiqsultanmohamed
Автор

Thanks for the video man! Always putting out good content!

josemfcheo
Автор

Hey Hussein big fan of yours, I request you to please order the content in each of your playlist so a novice like me can know where to start from and what's the sequence

ahmadsaeed