micrometer-metrics / micrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
https://micrometer.io
Apache License 2.0
4.45k stars 981 forks source link

Performance Issue: Heap is getting full slowly as using unique tag for each new entry of the. Looks like objects are not garbage collected. #5232

Closed viandervi closed 2 months ago

viandervi commented 3 months ago

Describe the bug Using micrometer in the code having version 1.6.x for pegging the metrics mainly using gauge and facing heap memory issue, as heap is slowly getting full. Checked the heap dump objects related to micrometer is continuously increasing. Even tried with latest version of micrometer-core 1.13.1, results were little better but not satisfactory.

Screenshot 2024-06-25 at 12 00 26 PM

Environment

Expected behavior Objects related to micrometer which are not referenced should be garbage collected.

shakuzen commented 3 months ago

Thanks for reporting the issue. It's not entirely clear to me the situation being described. If you keep registering more meters with unique tags, that's a high cardinality scenario and the memory will continually increase. There is no expiry for meters currently so unless they are removed from the registry, they will remain registered and take up memory.

Gauge meters take a backing object and by default Micrometer maintains a weak reference to it so Micrometer does not prevent the backing object from being garbage collected when it is no longer strongly referenced. The gauge itself will still remain registered, however.

One of the purposes of Micrometer's MeterRegistry is to maintain references to meters to be looked up. Micrometer does not require users maintain references to a Meter registered with a MeterRegistry. Are you expecting that Gauges will be removed from the MeterRegistry when the backing object is garbage collected? Or am I otherwise missing something?

github-actions[bot] commented 2 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

github-actions[bot] commented 2 months ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open.