NodeJS : How to debug “EventEmitter memory leak detected. 11 listeners added”

前端 未结 8 547
攒了一身酷
攒了一身酷 2020-11-28 20:23

How can I debug my application which throw this error:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxList         


        
8条回答
  •  执笔经年
    2020-11-28 21:06

    For me it's looks like your event loop is blocked. This can happen if you are doing cpu intensive tasks in node.js event loop. You can use child process to do intensive task.

    You can check what is blocking node.js using following methods:

    1. Measure computation time of each call. Log if time is high so you know app is misbehaving.
    2. Set up a log schedule so you know when something blocking loop
      function timeTick() {
          var startTime = (new Date().getTime());
          function onTick() {
              var interval = (new Date().getTime()) - startTime;
              if(interval > 5)
                  console.log('timeTick(): WARNING: interval = ' + interval);
          }
         process.nextTick(onTick);
      }
      setInterval(timeTick, 1000);
    3. Use profile.
    4. Use this for logging and profiling. It's library used in Nodejitsu.

提交回复
热议问题