Тёмный

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

Gabriel Zimmermann
Подписаться 3,7 тыс.
Просмотров 8 тыс.
50% 1

Hey folks! Today we’re diving a little deeper in the nodejs event loop (libuv) and looking at a bit of its Linux implementation. We’re also focusing on asynchronous IO using non blocking operations. We mention select vs poll vs epoll, libuv and the event loop phases.
Sources:
www.scottklement.com/rpg/sock...
suchprogramming.com/epoll-in-...
unix.stackexchange.com/questi...
idndx.com/2014/09/01/the-impl...
Chapters
00:00 Introduction
00:50 Overview of the flow
04:52 Threads concurrency model
06:34 Nonblocking IO
09:00 Select, poll, epoll
12:24 epoll c code example
15:16 libuv source code one more time
16:09 outro

Наука

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

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 54   
@akshatsethi6384
@akshatsethi6384 3 года назад
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 3 года назад
Thanks so much! will keep them coming, hope you like them!
@victormartinelli3422
@victormartinelli3422 3 года назад
I haven't seen a video this good about nodejs in a very long time. Really great content!
@Gabzim
@Gabzim 3 года назад
Thanks man, appreciate it a lot! When you’re just starting a channel this kind of support really helps you persevere.
@deepakkashyap6538
@deepakkashyap6538 4 месяца назад
Gem video, explaining the event loop with example source code is something great. Love to watch your upcoming videos 🔥🔥🔥
@TheSalarKhan
@TheSalarKhan 2 года назад
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 2 года назад
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
@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.
@sharthakghosh970
@sharthakghosh970 3 года назад
Absolutely yes, do specify data structures used in the various moving parts
@bernardofarias8215
@bernardofarias8215 8 месяцев назад
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 8 месяцев назад
Argentinian living close to the border with Brazil
@asepulven2768
@asepulven2768 Месяц назад
Great work!
@deviantmanolo
@deviantmanolo 3 года назад
I think adding bonus video in links referencing a good material about the specific data structure would be a great addition!
@Gabzim
@Gabzim 3 года назад
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.
@uoctaang9475
@uoctaang9475 3 года назад
You did very well job to explain event loop in NodeJS. Thanks you very much.
@papercraft4930
@papercraft4930 3 года назад
Thanks for cool video! I also appreciate your detailed explanation like datastructure
@ocodista
@ocodista 10 месяцев назад
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 10 месяцев назад
Hey Gabriel, is there a continuation for this video?
@husniddinqurbonboyev2634
@husniddinqurbonboyev2634 3 года назад
Great tutorial, thanks!
@liquidmetal718
@liquidmetal718 2 года назад
10:22 boom boom boom boom boom .... epoll brings back sweet memories from my Network programming course. Nice content man.
@pisense8882
@pisense8882 3 года назад
Man !! This is absolutely amazing. Keep going. and yes we do care about MinHeap too.
@kingshuk57
@kingshuk57 Год назад
really great content
@ibrahimkoz1983
@ibrahimkoz1983 2 года назад
Thanks for the great content.
@MuhammadBinZafar1
@MuhammadBinZafar1 2 года назад
2:30 Yeah I care about min heap. Thanks a ton for the info.
@AdityaKumar-xw2yx
@AdityaKumar-xw2yx 2 месяца назад
👏👏👏👏❤️
@berargumen2390
@berargumen2390 3 года назад
Awesomeeeeeeeeee
@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 :)
@muhammaddaka301
@muhammaddaka301 3 года назад
Many thanks for the informative video, great content! Can you list the name of the Linux book you mentioned in the video?
@Gabzim
@Gabzim 3 года назад
Absolutely! it's The Linux Programming Interface. www.amazon.com/Linux-Programming-Interface-System-Handbook/dp/1593272200
@dannahari3918
@dannahari3918 2 года назад
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 2 года назад
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 2 года назад
@@Gabzim Thank you, I appreciate it 🙂
@dannahari3918
@dannahari3918 2 года назад
@@Gabzim Hi, Did you have the chance to check it?
@piyushraj9561
@piyushraj9561 2 года назад
Very few people making this much of indepth content for node.
@sreyanchakravarty7694
@sreyanchakravarty7694 2 года назад
Please please make more videos about the node js event loop
@Gabzim
@Gabzim 2 года назад
I will. I was thinking about using some examples to illustrate this video
@-taz-
@-taz- 2 года назад
Just tell us whatever you care about and that's what we'll care about.
@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.
@knight024
@knight024 3 года назад
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 3 года назад
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 3 года назад
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.
@Arillaxe
@Arillaxe 2 месяца назад
I thought im tripping, but ur actually saying liv ub
@Gabzim
@Gabzim 2 месяца назад
Hehe yes I am, it’s my Argentinian accent coming through 😅 and the fact that English is my second language. Hehe nice catch.
@farbodshahinfar4246
@farbodshahinfar4246 3 года назад
I care that a min-heap has been used.
@Gabzim
@Gabzim 3 года назад
Noted, will continue to include these kinds of details then!
@mehtubbhai9709
@mehtubbhai9709 9 месяцев назад
i care that it's a min heap
@surecom12
@surecom12 9 месяцев назад
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.
@gackerman99
@gackerman99 Год назад
i care that its a minheap
Далее
ECE 252 Lecture 26: Asynchronous I/O with select, poll
1:01:11
Event driven vs event sourcing
4:44
Просмотров 11 тыс.
Erdős-Woods Numbers - Numberphile
14:12
Просмотров 78 тыс.
All About Epoll - Scalable I/O Syscalls in Linux!
19:22
Has Generative AI Already Peaked? - Computerphile
12:48
You Don't Know Node - ForwardJS San Francisco
35:25
Просмотров 28 тыс.