node.js Event Loop Diagnostics

后端 未结 2 1734
北海茫月
北海茫月 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.

提交回复
热议问题