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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top