node.js Event Loop Diagnostics

后端 未结 2 1712
北海茫月
北海茫月 2020-12-23 15:28

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).

相关标签:
2条回答
  • 2020-12-23 15:49

    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.

    0 讨论(0)
  • 2020-12-23 15:52

    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

    0 讨论(0)
提交回复
热议问题