node.js Event Loop Diagnostics

血红的双手。 提交于 2019-11-28 16:50:51

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/14870945/node-js-event-loop-diagnostics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!