question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event loop lag should be a summary, not a gauge

See original GitHub issue

Hi, as stated in the title, I believe the event loop lag metric should be a summary, not a gauge. The reason is that event loop lag can fluctuate quite substantially in a very short time. Think of a web server: when a web server handles a request, and we take a lag sample at exactly that moment then the lag value is is probably high. If we take a sample in idle state on the other hand, lag should be close to zero. Now when we plot the gauge metric in a line chart we can see seemingly random lag spikes. The spike might be there or not depending on whether a sample was taken during a request or during idle time. A summary would produce much more meaningful results as it records not only a single point in time but also considers all previous samples.

Have a look at the official docs: monitorEventLoopDelay also uses a histogram.

I can open a PR if you want, otherwise #278 would be a good opportunity to make this change.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
sam-githubcommented, Feb 3, 2020

Histograms have fixed buckets, with counts in them, so its possible to sum the histograms across all the instances (pods for example). Summaries the data is analyzed on the fly, each pod has different values for the percentiles, and they can’t be summed. If you google around you’ll find a bunch of info on this. Summaries look great until someone tries to aggregate into a dashboard, then it goes badly.

There is a case to be made that the user should be able to provide either a histogram or summary object to be used for the observation of the values (go does this with some metrics it collects), but I haven’t seen the Node.js client do this, so if there is only one, it should be histogram.

0reactions
zbjornsoncommented, Sep 19, 2021

The reason is that event loop lag can fluctuate quite substantially in a very short time. Think of a web server: when a web server handles a request, and we take a lag sample at exactly that moment then the lag value is is probably high. If we take a sample in idle state on the other hand, lag should be close to zero.

The advanced event loop monitoring added in v12.0.0 (#278) directly exposes the underlying histogram from Node.js v11.10.0+, which fixes this specific problem.

As far as the metric type, I don’t think we can convert this into a Prometheus Histogram because the data we get from Node.js is the “processed histogram” – i.e. “lag at Nth percentile” whereas we’d need “counts in bin LE=0.05”. I think @dhet is correct to suggest a Summary for that reason, but @sam-github is correct about Summaries being a pain to work with and aggregate.

I’m inclined to leave this as-is unless someone suggests otherwise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nodejs Event Loop Lag. Why does it matter? - Medium
Event loop lag is one of the important performance metrics but we don't talk much about it. In this post, I will explain...
Read more >
Monitoring Node.js: Watch Your Event Loop Lag! - David Hettler
Event loop lag is an essential, but often overlooked performance metric for Node.js applications. What is it and why does it matter?
Read more >
Node.js Performance Monitoring - Part 3 - NodeSource
An event loop without lag (we'll consider "healthy") will show that no task has been queued to wait for the completion of another...
Read more >
Node.js Event Loop and its Metrics: All you need to know
The event loop continuously traverses a FIFO of asynchronous tasks and executes the callback when a task is completed. Reality. While there are ......
Read more >
An Exploration of Runtime Metrics: Node's Event Loop
As the workload of an application grows, some increase in event loop lag is expected. While “normal” lag for the event loop is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found