Это видео недоступно.
Сожалеем об этом.
Why does node.js scale? Libuv & epoll & fcntl
HTML-код
- Опубликовано: 17 авг 2024
- 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.scottkleme...
suchprogrammin...
unix.stackexch...
idndx.com/2014...
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
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
Thanks so much! will keep them coming, hope you like them!
I haven't seen a video this good about nodejs in a very long time. Really great content!
Thanks man, appreciate it a lot! When you’re just starting a channel this kind of support really helps you persevere.
Gem video, explaining the event loop with example source code is something great. Love to watch your upcoming videos 🔥🔥🔥
Absolutely yes, do specify data structures used in the various moving parts
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!
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
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!
Hey Gabriel, is there a continuation for this video?
Great work!
I think adding bonus video in links referencing a good material about the specific data structure would be a great addition!
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.
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.
Argentinian living close to the border with Brazil
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.
10:22 boom boom boom boom boom ....
epoll brings back sweet memories from my Network programming course.
Nice content man.
You did very well job to explain event loop in NodeJS. Thanks you very much.
really great content
2:30 Yeah I care about min heap. Thanks a ton for the info.
Man !! This is absolutely amazing. Keep going. and yes we do care about MinHeap too.
Thanks for cool video! I also appreciate your detailed explanation like datastructure
Great tutorial, thanks!
👏👏👏👏❤️
Thanks for the great content.
Just tell us whatever you care about and that's what we'll care about.
Very few people making this much of indepth content for node.
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?
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.
@@Gabzim Thank you, I appreciate it 🙂
@@Gabzim Hi, Did you have the chance to check it?
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?
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)
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.
@@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.
Please please make more videos about the node js event loop
I will. I was thinking about using some examples to illustrate this video
Awesomeeeeeeeeee
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?
I don't have them anywhere other than my notes. I'll get around to publishing them somewhere
If enough people want it I'll work on a part 2 for this video.
@@Gabzim I would be definitely interested in part 2 video :)
Many thanks for the informative video, great content!
Can you list the name of the Linux book you mentioned in the video?
Absolutely! it's The Linux Programming Interface. www.amazon.com/Linux-Programming-Interface-System-Handbook/dp/1593272200
I care that a min-heap has been used.
Noted, will continue to include these kinds of details then!
I thought im tripping, but ur actually saying liv ub
Hehe yes I am, it’s my Argentinian accent coming through 😅 and the fact that English is my second language. Hehe nice catch.
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?
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.
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.
i care that it's a min heap
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.
i care that its a minheap