Why does node.js scale? Libuv & epoll & fcntl

  Рет қаралды 9,416

Gabriel Zimmermann

Gabriel Zimmermann

Күн бұрын

Пікірлер: 54
@victormartinelli3422
@victormartinelli3422 4 жыл бұрын
I haven't seen a video this good about nodejs in a very long time. Really great content!
@Gabzim
@Gabzim 4 жыл бұрын
Thanks man, appreciate it a lot! When you’re just starting a channel this kind of support really helps you persevere.
@deepakkashyap6538
@deepakkashyap6538 11 ай бұрын
Gem video, explaining the event loop with example source code is something great. Love to watch your upcoming videos 🔥🔥🔥
@liquidmetal718
@liquidmetal718 3 жыл бұрын
10:22 boom boom boom boom boom .... epoll brings back sweet memories from my Network programming course. Nice content man.
@TheSalarKhan
@TheSalarKhan 3 жыл бұрын
This should be the standard goto video for understanding non-blocking IO. Amazing job. You just explained to me what I learned by watching and reading multiple sources. I wish this video was there in 2018.. Thanks!
@Gabzim
@Gabzim 3 жыл бұрын
Hey Muhammad, thank you so much for the kind words, if you can help me spreading this video with your friends I’ll be sure to make a follow up. I’m glad this was helpful
@akshatsethi6384
@akshatsethi6384 4 жыл бұрын
This video is reallllllly good, and please focus on which data structures are used in code, its helpful to understand the practical use cases of the data structures that one normally studies for interviews. P.s:-also personally i dont mind long videos from you , because the content was really interesting
@Gabzim
@Gabzim 4 жыл бұрын
Thanks so much! will keep them coming, hope you like them!
@ocodista
@ocodista Жыл бұрын
Oh man, thank you so much. I've been in this rabbit role trying to understand where does the async execution in node ends and I wasn't happy that all the previous content I consumed ended at the libuv. I knew that there was an Operating System calls being made but I wasn't sure how did they called the callbacks on libuv. Thank you for this video!
@ocodista
@ocodista Жыл бұрын
Hey Gabriel, is there a continuation for this video?
@deviantmanolo
@deviantmanolo 4 жыл бұрын
I think adding bonus video in links referencing a good material about the specific data structure would be a great addition!
@Gabzim
@Gabzim 4 жыл бұрын
I like it, will curate a list of good videos about them and link them. Thanks for the input, that’s a great addition I can make.
@inaccessiblecardinal9352
@inaccessiblecardinal9352 3 жыл бұрын
This is an excellent video. Thanks! Diving a bit into the minheap and r/b tries was very illuminating. Also, I'd never even heard an explanation of the role epoll plays. Really great work.
@asepulven2768
@asepulven2768 9 ай бұрын
Great work!
@sharthakghosh970
@sharthakghosh970 4 жыл бұрын
Absolutely yes, do specify data structures used in the various moving parts
@uoctaang9475
@uoctaang9475 3 жыл бұрын
You did very well job to explain event loop in NodeJS. Thanks you very much.
@bernardofarias8215
@bernardofarias8215 Жыл бұрын
Not a Node programmer, but came here to learn a little more about epoll for my thesis. And what a great video, you did an amazing job explaining non-blocking I/O and the epoll syscall, congrats man! Btw, are you Brazilian? I couldn't tell by the accent.
@Gabzim
@Gabzim Жыл бұрын
Argentinian living close to the border with Brazil
@papercraft4930
@papercraft4930 4 жыл бұрын
Thanks for cool video! I also appreciate your detailed explanation like datastructure
@kingshuk57
@kingshuk57 Жыл бұрын
really great content
@MuhammadBinZafar1
@MuhammadBinZafar1 3 жыл бұрын
2:30 Yeah I care about min heap. Thanks a ton for the info.
@husniddinqurbonboyev2634
@husniddinqurbonboyev2634 3 жыл бұрын
Great tutorial, thanks!
@ibrahimkoz1983
@ibrahimkoz1983 3 жыл бұрын
Thanks for the great content.
@pisense8882
@pisense8882 4 жыл бұрын
Man !! This is absolutely amazing. Keep going. and yes we do care about MinHeap too.
@BhuShu972
@BhuShu972 3 жыл бұрын
Really great job explaining event loop in such a detail. it would be good to get to read the tips and tricks that you skipped in the video somewhere.Have you written them down in your blog or at some other place?
@Gabzim
@Gabzim 3 жыл бұрын
I don't have them anywhere other than my notes. I'll get around to publishing them somewhere
@Gabzim
@Gabzim 3 жыл бұрын
If enough people want it I'll work on a part 2 for this video.
@BhuShu972
@BhuShu972 3 жыл бұрын
@@Gabzim I would be definitely interested in part 2 video :)
@AdityaKumar-xw2yx
@AdityaKumar-xw2yx 9 ай бұрын
👏👏👏👏❤️
@dannahari3918
@dannahari3918 3 жыл бұрын
Love it, a great video! I have a question, libuv docs explain how timeout has calculated the timeout which will be pass to uv__io_poll function (it is set by uv_backend_timeout function). for example "If there are any idle handles active, the timeout is 0." but there is one case I didn't understand and maybe you can assist me, inside uv__io_poll function (at epoll.c file) there is one condition that will override timeout we receive: "if (uv__get_internal_fields(loop)->flags & UV_METRICS_IDLE_TIME) { ... timeout = 0; " what do internal_fields stand for? what are the cases it will be set?
@Gabzim
@Gabzim 3 жыл бұрын
Hey @dan nahari, I need to revisit this since it's been a while since I last went through the source code, allow me some time to walk through it and I'll get back to you.
@dannahari3918
@dannahari3918 3 жыл бұрын
@@Gabzim Thank you, I appreciate it 🙂
@dannahari3918
@dannahari3918 3 жыл бұрын
@@Gabzim Hi, Did you have the chance to check it?
@sreyanchakravarty7694
@sreyanchakravarty7694 3 жыл бұрын
Please please make more videos about the node js event loop
@Gabzim
@Gabzim 3 жыл бұрын
I will. I was thinking about using some examples to illustrate this video
@berargumen2390
@berargumen2390 3 жыл бұрын
Awesomeeeeeeeeee
@bozhidaratanasov7800
@bozhidaratanasov7800 Жыл бұрын
I don't get the part with the timeout (where the argument 30000 is passed in the C example). Isn't Node supposed to go through the different event queues, implemented with the help of libuv, and check for new events? How does this timeout help in the bigger picture? If it has not expired when Node checks next, does it block or does it just see that it's not supposed to check the event yet? Summed up question: does the thread executing the epoll system call block while in waiting phase, or does it switch to do something else?
@Gabzim
@Gabzim Жыл бұрын
I’m not sure I understand 100% what you’re struggling to see, if I understand correctly, the thread does block waiting for io when polling for new available data from network. However, it calculates how long to block for depending on other things it has to do. If there’s no data from the network and you have absolutely nothing else to do except a timer in 5ms, it’ll block for AT MOST 5 ms (the network could come before)
@Gabzim
@Gabzim Жыл бұрын
Blocking is a good compromise if you don’t have other code that’s ready to run, you get to minimize syscalls to read data and your program is activated instantly when data is ready to be read while you’re blocked, however you don’t want to block for too long for obvious reasons.
@bozhidaratanasov7800
@bozhidaratanasov7800 Жыл бұрын
@@Gabzim I thought this was the traditional (poll) approach - checking from time to time to see what happened to the event. This looks like that, when I would expect epoll to actually signal to the calling thread when the event is done, so it doesn't have to block. I am probably missing the bigger picture here, will go over the video again some time in the future.
@-taz-
@-taz- 3 жыл бұрын
Just tell us whatever you care about and that's what we'll care about.
@piyushraj9561
@piyushraj9561 3 жыл бұрын
Very few people making this much of indepth content for node.
@muhammaddaka301
@muhammaddaka301 4 жыл бұрын
Many thanks for the informative video, great content! Can you list the name of the Linux book you mentioned in the video?
@Gabzim
@Gabzim 4 жыл бұрын
Absolutely! it's The Linux Programming Interface. www.amazon.com/Linux-Programming-Interface-System-Handbook/dp/1593272200
@knight024
@knight024 4 жыл бұрын
Liked the video! But understanding epoll is a tough thing to wrap my head around. How can a single threaded program have a function execute, that will take 2 minutes as an example, and not block the main thread? That hurts my brain to think about. Is there scenarios where epoll isn't useful? what happens if you operating on a file vs a networking socket, is there a difference in how it operates? Can you do a video explain epoll in detail?
@Gabzim
@Gabzim 4 жыл бұрын
I can make a video about epoll. So to answer your main question, you can add file descriptors to epoll and then ask the OS: *"is anything ready for me to read from?"* and in that same call you say *"I'd like to wait for x amount of milliseconds if nothing is"*. If anything *IS* ready for you to operate on, then you don't block at all, because epoll will return immediately, however *IF nothing is ready*, epoll will block for the given timeout you passed. So the 2 cases are: 1. Something is ready: you don't block at all. 2. Nothing is ready: you block for as long as you want. Obviously if you pass in a huge timeout then you WILL block the main thread for that huge timeout (or if you pass in -1, which means block until something is ready). So what libuv will do is: do I have anything left to do? pass in *0* so we don't block at all. If I don't, wait for a little bit (how that little bit is calculated is beyond this comment). So you DO block the main thread when you don't have any pending work, but you block for a bit so that it doesn't impact your application.
@Gabzim
@Gabzim 4 жыл бұрын
Nonblocking IO in linux is useful on sockets, not really to do nonblocking io on files... why? because files are always considered ready to read/write from, but the operations themselves are blocking (I don't want to go too in depth in a comment). As for your question: *How can a single threaded program have a function execute, that will take 2 minutes as an example, and not block the main thread?* If you are executing synchronous code (computing some value etc), for the whole 2 minutes, then you WILL block the main thread for 2 mins. Epoll helps you to do nonblocking IO, but if you're not doing IO, you will block.
@farbodshahinfar4246
@farbodshahinfar4246 4 жыл бұрын
I care that a min-heap has been used.
@Gabzim
@Gabzim 4 жыл бұрын
Noted, will continue to include these kinds of details then!
@Arillaxe
@Arillaxe 9 ай бұрын
I thought im tripping, but ur actually saying liv ub
@Gabzim
@Gabzim 9 ай бұрын
Hehe yes I am, it’s my Argentinian accent coming through 😅 and the fact that English is my second language. Hehe nice catch.
@surecom12
@surecom12 Жыл бұрын
You don't have to explain it to javascript developers, because javascript developers usually think you are trying to take their job if you even try to learn javascript as a C/C++ developer. Many javascript developers have said that i do not know javascript, but i was just trying to learn and that i should go back to my C/C++, so no you should not help javascript developers to learn.
@satorugojo7140
@satorugojo7140 13 күн бұрын
It works 90% times 😂
@mehtubbhai9709
@mehtubbhai9709 Жыл бұрын
i care that it's a min heap
Node JS Internal Architecture | Ignition, Turbofan, Libuv
26:13
Gabriel Zimmermann
Рет қаралды 13 М.
ECE 252 Lecture 26: Asynchronous I/O with select, poll
1:01:11
Jeff Zarnett
Рет қаралды 13 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
What if all the world's biggest problems have the same solution?
24:52
Event driven vs event sourcing
4:44
Gabriel Zimmermann
Рет қаралды 12 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 668 М.
Managing The Event Loop Phases ⭕️ | OPTIMIZING NODE JS
23:32
Bleeding Code (By John Jardin)
Рет қаралды 20 М.
What P vs NP is actually about
17:58
Polylog
Рет қаралды 149 М.
The Node.js Event Loop: Not So Single Threaded
31:54
node.js
Рет қаралды 168 М.
When is NodeJS Single-Threaded and when is it Multi-Threaded?
18:42
Hussein Nasser
Рет қаралды 75 М.
NodeConf EU |  A deep dive into libuv - Saul Ibarra Coretge
24:15