Skip to content

Compress t-digest to prevent memory leakage - #234

Merged
siimon merged 4 commits into
prometheus:masterfrom
atd-schubert:fix/142-compress-t-digest
Jun 27, 2019
Merged

siimon merged 4 commits into
prometheus:masterfrom
atd-schubert:fix/142-compress-t-digest

Conversation

@atd-schubert

Copy link
Copy Markdown
Contributor

As already described in #142 the Summary is leaking memory. This fix will call the compress method of t-digist. To prevent compressing a too small set of measurements and increasing performance, it will call the compress method every 1000 measurements by default. You can also specify another count with option compressCount in the Summary options.

@SimenB SimenB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove your package-lock changes (I've updated it on master), and add a changelog entry? 🙂

Comment thread lib/summary.js Resolved
@atd-schubert
atd-schubert force-pushed the fix/142-compress-t-digest branch from f4eaacb to 154ca9e Compare December 31, 2018 10:37
@atd-schubert
atd-schubert force-pushed the fix/142-compress-t-digest branch from 154ca9e to 7c9e119 Compare December 31, 2018 10:39
@atd-schubert

Copy link
Copy Markdown
Contributor Author

@SimenB of course, here is the updated version. Thanks for your work and have a happy new year 🎆🎉🎈!

@SimenB
SimenB requested review from siimon and zbjornson December 31, 2018 11:07
@siimon

siimon commented Dec 31, 2018

Copy link
Copy Markdown
Contributor

Thanks for your investigation and fixes! The PR looks good to me.. Just out of curiosity, why does this fix the leak?

@siimon

siimon commented Dec 31, 2018

Copy link
Copy Markdown
Contributor

Still missing the update in the changelog btw!

@kristok

kristok commented Apr 11, 2019

Copy link
Copy Markdown

@siimon could you merge if all is good?

@siimon

siimon commented May 14, 2019

Copy link
Copy Markdown
Contributor

Sorry for the slow updates, but I still want to know what implications this has and why it solves the leak.. Is it a known problem in the tdigest library or are we using it in a wrong way?

@firasdib

Copy link
Copy Markdown

@atd-schubert Do you care to inform us :-)?

@atd-schubert

Copy link
Copy Markdown
Contributor Author

@siimon @firasdib Sorry I was away the last two weeks...

During my research I found out that Summaries are leaking memory while Histograms don't. I wrote a leakage test for it (see: #142 (comment)).

While analyzing the heap dumps I recognized that t-digest add each value to an array. Of course this will end-up in a leaking behavior. In the description of the t-digest module is mentioned that you should compress the data especially after adding a big dataset. After compressing it will still have an accurate result, but don't have to keep all entries in the array.

In prom-client data is added continuously. Compressing on every entry will end up in a lot of processing and make the module quite slow. In addition, compressing of a small dataset will not have any effect. This is why I decide to compress every 1000 measurements as default.

After making these changes the above mentioned leakage test will not detect a leaking behavior anymore. As long as you add enough measurements, of course.

So in the end - and according to your question - it is a known issue of the t-digest library, but it works as designed and with the compression you are able to eliminate or at least reduce that issue. So maybe it is also some kind of using it the wrong way...

@nelsongomes

nelsongomes commented Jun 25, 2019 •

Copy link
Copy Markdown

@siimon or @SimenB can you make a deploy with this please?

@nelsongomes

Copy link
Copy Markdown

@siimon, @SimenB can you please merge this PR?

@siimon
siimon merged commit 26c65fe into prometheus:master Jun 27, 2019
@siimon

siimon commented Jun 27, 2019

Copy link
Copy Markdown
Contributor

Published in 11.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants