Node's Event Loop From the Inside Out by Sam Roberts, IBM

node.js · 99K views · 2016 · 23:02

Open on YouTube

Web developmentPython, Ruby & scripting languagesSoftware performance & optimizationtalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about what libuv, epoll and the thread pool actually do for Node's network I/O and event loop.

Recommended by 4 people across 4 different months, 2018 to 2021.

What it is

A 23-minute conference talk by Sam Roberts of IBM that explains how Node.js's event loop really works, including the libuv layer, epoll, and the thread pool, and corrects common misconceptions about event emitters and asynchronous I/O. It includes some C code walkthrough and notes on possible changes to how Node uses libuv.

What people said

Recommends Vladyslav Usenko · 2019-05 · Stack Overflow · on “Express/Node.js.. Am I blocking the event loop?”

You've met the default limits of Node's async I/O! Long story short, for fs module Node.js makes use of libuv thread pool , which size is equal to 4 by default. For some things Node delegates its job to the underlying operating system async handlers (epoll, kqueue, etc.), but for stuff like DNS, crypto or, in our case, file system, it uses libuv. Most likely the amount of files you want to write to disk is bigger than 4. Most likely it becomes even bigger when a parallel request comes in. At the end of the day you're simply running out of libuv threads and then Node simply has nothing to do, bu to wait until at least one thread is free to use. It really depends on the amount of files, theref

Recommends SecretIndividual · 2019-10 · Stack Overflow · on “Relationship between event loop,libuv and v8 engine”

This is actually not as simple as given in the post selected as the answer. I hope my remarks will be a bit more exact. Hopefully I understood Sam Roberts (IBM) correctly in his talk on the Node event loop. To view the talk yourself you can go here: [this video] This is an addon to the answer given by @jmrk Libuv delegates tasks to the underlying operating system. The operating system then becomes responsible for sending a notification when an event occurs you are listening to. It does this for a lot of the operations you perform in Node. Like: sockets (net/dgram/http/tls/https/child_process pipes, stdin, out, err), timeouts and intervals. However not everything can be delagated like this to the

Recommends Prakitidev Verma · 2021-04 · Stack Overflow · on “question regarding epoll: where exactly is stored? can it be accessed? how? what happens if a socket drops?”

It would be great if you could explain more on your scenario. I belive you are working on a very high demanding server. In the mean time take a look at this, let me know if it is on any help [this video] Understanding libuv / epoll / non-blocking network IO [LINK]

Recommends Tarun Prakash Singh · 2021-07 · Stack Overflow · on “Node accepted new socket connection even when main thread is blocked #3473”

but the video i pasted that guy said that in event loop code it is written that its a semiinfinte loop waiting on epoll and when it has some connection u accept it and a new socket is created, so after first cul u accept the connection and new socket is created and then theres just while loop for 50 seconds so i was guessing only after 50 s seconds , u get new connection from epoll on second event loop iteration, can u check this video in middle [this video] from 10 minute mark please

Cites Aritra Chakraborty · 2018-08 · Stack Overflow · on “Does Node Js use libuv Thread Pool for Network I/O”

I recently got hooked into NodeJS internals and V8 and D8 and libuv those kind of things. So, one of the really weird thing is network i/o is handled by the event loop. But dns.lookup() is handled by the libuv threadpool. So, http.get/http.post is handled by the event loop only if you provide IP as the url. Not hostname. If hostname is provided then it will internally use dns.lookup which will in turn make the operation handled by thread pool. Refer: Node's Event Loop From the Inside Out by Sam Roberts, IBM [this video] Note: I am still learning this, so any and every edits are welcome.

Cites Aritra Chakraborty · 2018-08 · Stack Overflow · on “Does Node Js use libuv Thread Pool for Network I/O”

`dns.lookup` and `getaddrinfo` is handled by the thread pool. also crypto and http get post if hostname is provided. refer: [this video]

Cites Tarun Prakash Singh · 2021-07 · Stack Overflow · on “Node accepted new socket connection even when main thread is blocked #3473”

Okay, but node event loop use epoll and blocks until it accepts a connection on listening socket, which creates a new socket, but the other 2 new socket has already been created after first curl, then who accepted the incoming connection, im coming from this video [this video] and what do you mean app is calling accept , you mean listening socket accepting the connection and giving it a new dedicated socket, another question is tcp handshake already been done for other 2 sockets after first curl