Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intern MBean names used in cache #1098

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

yana-ilieva
Copy link
Contributor

Hello,

I am opening this PR as per the discussion in the Prometheus Developers group.

Finding

The exporter's caching mechanism can use up a lot of heap memory and can cause frequent GC clean ups, leading to performance degradation of the main application. The exact reason is the MatchedRulesCache object which can grow excessively in size. For each rule with caching enabled, the object keeps all MBean name strings it was matched against. All rules are matched against the same set of JMX MBeans and as a result for each rule we have duplication of the same string values.

Suggested solution

Use string interning when creating the matchName object, which is used in the cache. This way, we utilize JVM's string pool and reduce the memory usage by String objects with identical content.

Observed improvement

In my local testing, there is improvement in both memory usage and request speed, as seen in the lower-right corner in the table.

image

Use string interning when creating the "matchName" used
in the caching data structure, in order to reuse
previously created String objects and to avoid
duplication of Strings with identical contents in memory.

Signed-off-by: Yana Ilieva <yana.ilieva987@gmail.com>
@yana-ilieva yana-ilieva force-pushed the intern-mbean-names-in-cache branch from b157a43 to d92d7aa Compare December 13, 2024 14:56
@dhoard dhoard self-assigned this Dec 13, 2024
@dhoard dhoard merged commit 4354210 into prometheus:main Dec 13, 2024
1 check passed
@dhoard
Copy link
Collaborator

dhoard commented Dec 13, 2024

@yana-ilieva Thanks for the PR!

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

Successfully merging this pull request may close these issues.

2 participants