14

A variation of this question was already asked here on SO (node.js Event Loop Diagnostics), however that thread is over a year old and stale.

Specifically, I want to be able to peek at the node.js Event Loop at runtime, from within the node.js process, to determine the number of events pending execution.

edit: The results of the previous question pointed to external diagnostic tools and/or internal facilities that gave insight into the length of time it took the event queue to tick.

Currently, I'm checking through the node.js doc's and libuv docs but nothing seems to be popping up. Was hoping there was an undocumented facility I could leverage..

5
  • is the downvote because it's been asked(ish)? Commented Jun 9, 2014 at 23:48
  • It might have gotten down-voted because you didn't say why the old answer won't work for you (except it is old, which is not a definitive reason) and that you didn't put anything you tried yourself on your post. Commented Jun 9, 2014 at 23:55
  • @DrCord good point, thanks. I have edited to reflect this! Commented Jun 9, 2014 at 23:58
  • This could be very very difficult thing to do, if not done already. See here. The event loop implementation is not simple as a single queue, which you can read all events from. The problem is its not homogeneous meaning you process nextTick, I/O events and the rest differently. Hopefully there is something in v0.12 for this. But for now it cannot be answered. Commented Jun 10, 2014 at 5:35
  • @user568109 I was worried of this. Thanks for the response! Commented Jun 10, 2014 at 15:29

1 Answer 1

12

There are a couple of undocumented functions that return a list of open requests and open handles:

  • process._getActiveRequests()
  • process._getActiveHandles()

There is also an experimental AsyncListener API in node v0.11.12+ that allows you to add hooks for asynchronous events.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the response @mscdex. Ya I've seen those, but I read somewhere (trying to find where), where the author says they don't work as one would expect, and that they may be removed in the future
I haven't heard anything about unreliability. Obviously though as they're undocumented, they could be removed at any given time. However they're really the only available solutions at the moment.
Have you had any experience using these? Do they seem reliable?
I've used them a few times before, but not regularly. They have been accurate those times I have used them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.