NodeJS Architecture - I/O

  Рет қаралды 46,718

Hussein Nasser

Hussein Nasser

Күн бұрын

Node is a non-blocking Javascript runtime. You can concurrently run an HTTP Server, read files from disk, send UDP datagrams, accept TCP connections from clients and still have room to execute Javascript code operations without blocking. Most of these operations are known as I/O, you send an input to a device, file or a socket and it replies back with an output. Node achieves non-blocking I/O with mostly a single thread executed asynchronously using a library called lib_uv.
The exception being DNS queries, which use a thread pool. This means when you use fetch or axios to make an HTTP request to a domain, the DNS resolution for that domain will most probably go through the thread pool, while the actual request itself will be sent asynchronously on the main thread.
In this episode of the backend engineering show I go through an article I wrote discussing NodeJS Asynchronous I/O.
/ when-nodejs-i-o-blocks
Learn the fundamentals of network engineering, get my udemy course
network.husseinnasser.com
0:00 Intro
3:00 Part 1 Socket/IO
9:48 Part 2 File I/O
12:42 Part 3 DNS
16:22 Part 4 NodeJS Single Threaded
19:10 Part 5 NodeJS Thread Pool
21:23 Part 6 DNS lookup bottleneck in Node
Fundamentals of Networking for Effective Backends udemy course (link redirects to udemy with coupon)
network.husseinnasser.com
Fundamentals of Database Engineering udemy course (link redirects to udemy with coupon)
database.husseinnasser.com
Introduction to NGINX (link redirects to udemy with coupon)
nginx.husseinnasser.com
Python on the Backend (link redirects to udemy with coupon)
python.husseinnasser.com
Become a Member on KZfaq
/ @hnasr
Buy me a coffee if you liked this
www.buymeacoffee.com/hnasr
Arabic Software Engineering Channel
/ @husseinnasser
🔥 Members Only Content
• Members-only videos
🏭 Backend Engineering Videos in Order
backend.husseinnasser.com
💾 Database Engineering Videos
• Database Engineering
🎙️Listen to the Backend Engineering Podcast
husseinnasser.com/podcast
Gears and tools used on the Channel (affiliates)
🖼️ Slides and Thumbnail Design
Canva
partner.canva.com/c/2766475/6...
Stay Awesome,
Hussein

Пікірлер: 29
@dog4ik
@dog4ik Жыл бұрын
I was always wondering how single threaded js backends can accept so many concurrent connections. Great article!
@333ruka
@333ruka Жыл бұрын
remember event loop ?
@Forest_Abby
@Forest_Abby Ай бұрын
Hi mate, nice video! It makes things clearer and reveals the magic behind the scenes.
@sandeepparmar3113
@sandeepparmar3113 Жыл бұрын
Really Intringing , Changed my perspective of NodeJS. And as alwyas great content.
@nadaquever5161
@nadaquever5161 Жыл бұрын
tyvm mr. nasser. kickass content
@timibolu
@timibolu Жыл бұрын
Thank you very much. This is very valuable information.
@IgorRoztr
@IgorRoztr Жыл бұрын
Love these deeep dives ;)
@mahedihassanshawon4821
@mahedihassanshawon4821 Жыл бұрын
Thanks! for these contents
@juhairahamed5342
@juhairahamed5342 5 ай бұрын
Thanks. I taken your udemy course. Excellent discussion on database.. Now onward u you are a role model related to software area
@biplobmanna
@biplobmanna Жыл бұрын
Very informative, but now I have more questions about how the underlying syscalls work. Time to dive into the rabbit hole.
@toritsejuFO
@toritsejuFO 5 ай бұрын
Good stuff.
@juhairahamed5342
@juhairahamed5342 5 ай бұрын
good explanation
@wrlee
@wrlee Жыл бұрын
The definition of "blocking" is not simply semantics, it's a matter of stratifying the kinds of blocking you are talking about. Simply stated, blocking is when the application's execution is waiting for something to happen. Waiting for the kernel to transfer a buffer to app/user space is quite different than waiting for data to appear on a socket, but both are "blocking," at different _layers_-the former is more local while the later is dependent on external activity. We might even describe the wait for a CPU instruction to complete to be blocking-a hyper-local form of blocking. So we can analyze blocking by looking at the system architecture and what the application is waiting on: user, internet network (and other non-deterministic external systems), infrastructure architecture (e.g., external storage vs internal storage), operating system, bus architecture, CPU. The solution for mitigating blocking effects on applications depends on the solutions to circumventing delays between and within those layers.
@shivraj1459
@shivraj1459 Жыл бұрын
super helpful following you since I discovered you .Can you please make a video about auth server and resource server relating to your recent linkedIn post?
@isurucumaranathunga
@isurucumaranathunga Жыл бұрын
Really Really Really appreciate your effort and thank you so much for this valuable content Hussein. I love you content so much. Hussein what about the Vert.x library in JAVA. It is also using this asynchronous processing using a concept called verticles and event bus. I highly appreciate if you could do a content on that also. Looking forward for another great content like this. Thanks
@abbasramees4238
@abbasramees4238 Жыл бұрын
I read that async operations like network request and async file reading are executed once the stack is empty, so, until then, where are these async operations stored? did Node use any queue data structure for that
@elakstein
@elakstein Жыл бұрын
If you are doing cpu intensive task then it will block other tasks as everything is running on a single thread. Let's say you do a math heavy calculation and it takes 3 seconds to complete. Then your application will be blocked for those 3 seconds and it won't be able to do anything else. In cases like this, multi threaded application will do better, as these type of computation you can do in a separate thread.
@coderkashif
@coderkashif 5 ай бұрын
Great
@tenthlegionstudios1343
@tenthlegionstudios1343 Жыл бұрын
Great video. A more in depth video on this I found useful was by Kprotty about Zig's IO. He goes super deep into all of this, and does an iceberg on concurrent models and IO. Very cool. ScyllaDB is at the bottom of this iceberg. It also goes in depth into rust tokio and GOs IO model. And it expands a lot on IOuring. Also Bun (competitor to node) basically just uses KProttys implementation of IO to greatly outperform node. Bun uses zig under the hood and is basically rewriting the parts of node that interact with the OS kernel. Link Here: kzfaq.info/get/bejne/i9JogrJl27exhKs.html
@biplobmanna
@biplobmanna Жыл бұрын
Can you share the link?
@tenthlegionstudios1343
@tenthlegionstudios1343 Жыл бұрын
@@biplobmanna kzfaq.info/get/bejne/i9JogrJl27exhKs.html&ab_channel=ZigSHOWTIME
@aadhinana
@aadhinana Жыл бұрын
kzfaq.info/get/bejne/i9JogrJl27exhKs.html
@eldhoabraham8716
@eldhoabraham8716 Жыл бұрын
Please share link
@CamaradaArdi
@CamaradaArdi Жыл бұрын
Where do the quotes come from? I've done a google search and I got no results aside from your post
@muhammedkadirtan3469
@muhammedkadirtan3469 Жыл бұрын
they are meant to emphasize that paragraph contains additional information
@aliadel1723
@aliadel1723 9 ай бұрын
Node can be multithreaded with the worker thread. or am I wrong?
@yusufmirkar6508
@yusufmirkar6508 6 ай бұрын
for very simple compute, it is single-threaded. for async io / dns etc mentioned in this video, nodejs is multi threaded
The Node.js Event Loop: Not So Single Threaded
31:54
node.js
Рет қаралды 165 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 87 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 29 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 7 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
How Discord Stores Trillions of Messages | Deep Dive
1:08:33
Hussein Nasser
Рет қаралды 174 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
When is NodeJS Single-Threaded and when is it Multi-Threaded?
18:42
Hussein Nasser
Рет қаралды 71 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 271 М.
WebTransport is a Game Changer Protocol
14:23
Hussein Nasser
Рет қаралды 53 М.
Threads and Connections | The Backend Engineering Show
49:30
Hussein Nasser
Рет қаралды 63 М.
The problem with software engineering
13:58
Hussein Nasser
Рет қаралды 64 М.
What is a Protocol? (Deepdive)
18:14
LiveOverflow
Рет қаралды 162 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 10 МЛН
iPhone 15 Pro Max vs IPhone Xs Max  troll face speed test
0:33
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 211 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 63 МЛН
Проверил, как вам?
0:58
Коннор
Рет қаралды 80 М.