Skip to content

Commit 57f94ca

Browse files
authored
Cache MBean Domain for performance (#918)
As with #917, we also call `ObjectName#getDomain()` once per-_attribute_, which is unnecessary and can be expensive when MBeans contain a large number of attributes. This is because `ObjectName#getDomain()` allocates a new String, copying the domain into it. Signed-off-by: Nick Telford <[email protected]>
1 parent c460ea3 commit 57f94ca

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

collector/src/main/java/io/prometheus/jmx/JmxScraper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mBeanName) {
213213
}
214214

215215
final String mBeanNameString = mBeanName.toString();
216+
final String mBeanDomain = mBeanName.getDomain();
216217

217218
for (Object object : attributes) {
218219
// The contents of an AttributeList should all be Attribute instances, but we'll verify
@@ -238,7 +239,7 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mBeanName) {
238239
LOGGER.log(FINE, "%s_%s process", mBeanName, mBeanAttributeInfo.getName());
239240
processBeanValue(
240241
mBeanName,
241-
mBeanName.getDomain(),
242+
mBeanDomain,
242243
jmxMBeanPropertyCache.getKeyPropertyList(mBeanName),
243244
new LinkedList<>(),
244245
mBeanAttributeInfo.getName(),

0 commit comments

Comments
 (0)