18

Is it possible to peek at the event loop for diagnostics?

I would like to know how many events are currently waiting for execution (excluding setTimeout/interval).

Update: I'd like to do this from inside the running node process.

5
  • interesting question, I'll stick around to find out if anyone has any clues, short of looking into node's code. Commented Feb 14, 2013 at 8:54
  • Would dtrace help? I know it's used to profile node. Commented Feb 14, 2013 at 9:14
  • blog.nodejs.org/2012/04/25/profiling-node-js Commented Feb 14, 2013 at 9:27
  • I'd prefer a solution that I can use from within node.js with a low performance overhead. Commented Feb 14, 2013 at 9:29
  • @TheBronx the flame graph looks interesting though it's a bit more than what I need. Commented Feb 14, 2013 at 9:46

2 Answers 2

11
+50

Updated for nodejs 0.10 with setImmediate()

While I wasn't able to find the number of waiting events in the queue I found another health metric that might be useful:

var ts=Date.now();
setImmediate(function()
{
  var delay=Date.now()-ts;
});

delay will contain the milliseconds it took from queuing the event to executing it.

This also takes cpu intensive events into account (which would not be possible by just looking at the # of events).

The measurement itself will affect the event queue as well but this should have a much lower overhead than a full profiler.

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

1 Comment

would be great if we could actually 'see' the event que... I suppose you never found a way to do this?
0

NodeFly's agent monitors overall Node.js performance including the Event Loop. You can read a couple of blog entries taling about this functionality:

http://blog.nodefly.com/post/41119237822/monitoring-the-event-loop-in-node-js

http://blog.nodefly.com/post/41201793716/just-another-friday-night-chat-scaling-node-js-and

You can find and try out the agent here:

http://www.nodefly.com

1 Comment

It appears to do something similar to what I was describing previously: "The NodeFly agent patches the nextTick function to get timing data for the event loop."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.