Nodejs Event Loop

0 votes

Are there internally two event loops in nodejs architecture?

  • libev/libuv
  • v8 javascript event loop

On an I/O request does node queue the request to libeio which in turn notifies the availability of data via events using libev and finally those events are handled by v8 event loop using callbacks?

Basically, How are libev and libeio integrated in nodejs architecture?

Are there any documentation available to give a clear picture of nodejs internal architecture?

Jun 9, 2022 in Node-js by Vaani
• 7,070 points
579 views

1 answer to this question.

0 votes

I've been reading the source code for node.js and v8 on my own.

When I tried to learn the architecture of Node.js in order to develop native modules, I ran into a similar issue as you.

What I'm writing here is my interpretation of node.js, which may or may not be correct.

Libev is the event loop that node.js uses internally to do simple event loop tasks. It was designed with *nix systems in mind. For the process to execute on, Libev provides a basic yet efficient event loop. More information on libev may be found here.

LibEio is a library for asynchronous input and output. It manages file descriptors, data handlers, and sockets, among other things. You may learn more about it by clicking here.

LibUv is a layer that sits on top of libeio, libev, c-ares (for DNS), and iocp (for windows asynchronous-io). All of the io and events in the event pool are performed, maintained, and managed by LibUv. (in libeio threadpool's example). 

Basically, inside node.js, the v8 loop runs and handles all javascript and C++ modules [when they're running in a main thread (node.js is single threaded, according to the official documentation)]. libev and libeio manage it in the thread pool when it's not on the main thread, and libev handles the interaction with the main loop. So, as far as I can tell, node.js only has one persistent event loop: the v8 event loop. It uses a threadpool [through libeio & libev] to handle C++ async jobs.

For example:

eio_custom(Task,FLAG,AfterTask,Eio_REQUEST);

Calling the Task function in the threadpool is something that exists in all modules. When it's finished, it invokes the main thread's AfterTask method. The request handler, on the other hand, is a structure or object whose purpose is to provide communication between the threadpool and the main thread.

To know more about Node JS, It's recommended to join Node JS Certification Course today.

answered Jun 10, 2022 by Neha
• 9,020 points

Related Questions In Node-js

0 votes
1 answer

How do I “include” functions from my other files in nodejs?

Hello @kartik, You require any js file,so you just ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
3,424 views
0 votes
1 answer

Error: listen EADDRINUSE while using nodejs?

Hello @kartik, EADDRINUSE means that the port number which listen() tries ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
6,552 views
0 votes
1 answer

Error:npm WARN unmet dependency in nodejs

Hii @kartik, Following are the possible solution : Manually ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,840 points
6,291 views
0 votes
1 answer

How nodejs get file name from absolute path?

Hello @kartik, Use the basename method of the path module: path.basename('/foo/bar/baz/asdf/quux.html') // returns 'quux.html' If you ...READ MORE

answered Jul 14, 2020 in Node-js by Niroj
• 82,840 points
3,425 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

Start script missing error when running npm start

It seems that there is an undefined ...READ MORE

answered Feb 10, 2022 in Java by Soham
• 9,710 points
4,439 views
0 votes
1 answer

Nodejs instagram-web can't save login session locally

There are several things you can do: Dictionary ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
1,035 views
0 votes
1 answer

NodeJS - Upload ~36MB file to VirusTotal failing

The VirusTotal file/scan API request has a ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
861 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP