Skip to content

Conversation

@parsonsmatt
Copy link

No description provided.

parsonsmatt and others added 3 commits June 10, 2025 12:19
Co-authored-by: Mary Paskhaver <mary.paskhaver@gmail.com>
Co-authored-by: mattkahrs <mattkahrs@gmail.com>
…metheus-haskell into mattp/memory-performance

We're running into problems with unexpectedly high memory use in `prometheus-client`, so I've been investigating improving the behavior.

Specifically, we're notificing a significant increase in the amount of time and memory allocated while calling `exportMetricsToText`.

Choose a reason for hiding this comment

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

Suggested change
Specifically, we're notificing a significant increase in the amount of time and memory allocated while calling `exportMetricsToText`.
Specifically, we're noticing a significant increase in the amount of time and memory allocated while calling `exportMetricsToText`.

## `MetricImpl`

A `Metric` had a field `construct :: IO (s, IO [SampleGroup])`.
To avoid tuple, we introduce `MetricImpl s` which uses bang patterns on the fields.

Choose a reason for hiding this comment

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

Suggested change
To avoid tuple, we introduce `MetricImpl s` which uses bang patterns on the fields.
To avoid the tuple, we introduce `MetricImpl s` which uses bang patterns on the fields.

This means that, should anything write to the `TVar`, all of the computation will be retried.
This is *probably* bad - we want to capture the state of the metrics *now*, and then return the `SampleGroup`, rather than allowing the computation to be aborted and retried multiple times.

The first two problems are based on the sizeof the histogram, so the number of buckets.

Choose a reason for hiding this comment

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

Suggested change
The first two problems are based on the sizeof the histogram, so the number of buckets.
The first two problems are based on the size of the histogram, so the number of buckets.


The first two problems are based on the sizeof the histogram, so the number of buckets.
Every additional bucket causes another float to be rendered into a string, and another list cons cell to be held on to.
Since number of buckets is likely small, this is probably not a big deal.

Choose a reason for hiding this comment

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

Suggested change
Since number of buckets is likely small, this is probably not a big deal.
Since the number of buckets is likely small, this is probably not a big deal.

@@ -0,0 +1,91 @@
# Investigating Memory Use in `prometheus-client`
Copy link
Owner

Choose a reason for hiding this comment

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

This feels like an odd file to check into main. I think this would be more appropriate as the PR description.

@fimad
Copy link
Owner

fimad commented Aug 2, 2025

Do these changes resolve the memory issues are seeing?

There are several changes described in memory-use.md and it is not clear to me if each of those changes improves memory or if they are speculative and ended up being neutral. Could you comment on the effectiveness of each change?

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.

4 participants