It's generally hard to inspect the event loop info in node.js itself. 
Node.js internally uses libuv to implement the event queue. libuv in turn 
uses epoll (if you are on Linux) to implement events, etc. Both node.js and 
libuv hide a lot of details of epoll. So if you want to really understand 
the event loop of node.js, you need to understand epoll.

Just a quick tour. in src/node.cc, 'uv_run(env->event_loop(), UV_RUN_ONCE)' 
is called. uv_run is the main event loop of libuv, and is implemented 
in deps/uv/src/unix/core.c. If you look at uv_run()'s implementation, the 
most important part is 'uv__io_poll(loop, timeout);'. uv__io_poll is what 
actually listens to I/O events. It is implemented 
in deps/uv/src/unix/linux-core.c. Basically uv__io_poll is using the epoll 
system call to listen to events. (For more understanding of epoll, this 
<http://kovyrin.net/2006/04/13/epoll-asynchronous-network-programming/> 
post might help. For a thorough understanding of epoll, I recommend the 
book 'The Linux Programming Interface').

Eventually uv__io_poll calls 'nfds = uv__epoll_wait(loop->backend_fd, 
events, ARRAY_SIZE(events), timeout);'. The return value nfds indicates how 
many file descriptors (could be file I/O or socket, etc.) have events 
triggered and therefore are ready to execute their corresponding event 
handlers. That value is *roughly* how many events that are queued in the 
event queue. Again, a good understanding of epoll is required.




On Monday, June 17, 2013 at 10:20:50 AM UTC-5, Chaoran Yang wrote:
>
> Dear all,
>
> Is there any way in node.js I can query the length of event loop queue? I 
> assume the event loop has a queue of callbacks. Checking the queue length 
> can be useful to know whether a server is busy or not at a certain time.
>
> -Chaoran
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/5bd19758-7a1d-49d0-be6c-c053f28588a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to