3

I have this simple code in NodeJs

const { eventLoopUtilization } = require('perf_hooks').performance;
const { monitorEventLoopDelay } = require('perf_hooks');

const h = monitorEventLoopDelay({ resolution: 10 });
let lastELU = eventLoopUtilization();

setInterval(() => {
  console.log('Start', new Date())

  const tmp = eventLoopUtilization();
  console.log(eventLoopUtilization(tmp, lastELU));
  lastELU = tmp;

  console.log(h.min);
  console.log(h.max);
  console.log(h.mean);
  console.log(`End ${new Date()} \n\n`)
}, 1);

h.enable();

When I execute this I have this output:


...

Start 2024-07-18T14:20:49.400Z
{
  idle: 14.759,
  active: 0.2114000018537041,
  utilization: 0.01412119928843101
}
15417344
16138239
15742566.4
End Thu Jul 18 2024 16:20:49 GMT+0200 (Central European Summer Time) 


Start 2024-07-18T14:20:49.415Z
{
  idle: 15.022599999999997,
  active: 0.29309999828934963,
  utilization: 0.019137225090729564
}
15171584
16138239
15648085.333333334
End Thu Jul 18 2024 16:20:49 GMT+0200 (Central European Summer Time) 

...

As you can see, every loop of the event loop is taking ~15ms to complete.
That's causing every callback to "lag" 15ms on average.

The event loop utilization show that almost all 15ms of the time is idle.
I cannot understand why.

Someone has an explanation?
Thanks

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.