siimon / prom-client

Prometheus client for node.js
Apache License 2.0
3.15k stars 377 forks source link

perf: improve the memory usage of histogram #606

Closed xsbchen closed 10 months ago

xsbchen commented 10 months ago

We have a use case where it generates a huge amount of histograms, each has more than 10 labels, we found the memory usage is quite high, under this scenario, we did an experiment and found that removing bucketExemplars field from histograms could save about 27% memory usage for each histogram instance, hope the maintainers could review and consider it SeaTalk_IMG_20240111_195229

SimenB commented 10 months ago

Should we do this for the other metric types as well?

xsbchen commented 10 months ago

Should we do this for the other metric types as well?

I checked only Counter and Histogram support the enableExemplars option, and Counter already handled this case.

SimenB commented 10 months ago

@voltbit thoughts on this? Seems reasonable to me, but I have to admit I'm a bit unsure how this code works 😅

voltbit commented 10 months ago

Looks good to me. The data struct being there when exemplars are disabled was an overlook on my side I think.

xsbchen commented 10 months ago

@zbjornson @siimon master, plz help to review it if you are free, thanks.

SimenB commented 8 months ago

https://github.com/siimon/prom-client/releases/tag/v15.1.1