Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.