Bug 63361 - Provide a configuration option to disable MBean registration
Summary: Provide a configuration option to disable MBean registration
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Util (show other bugs)
Version: 9.0.x
Hardware: PC Mac OS X 10.1
: P2 enhancement (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2019-04-18 09:00 UTC by Andy Wilkinson
Modified: 2019-04-24 13:52 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Andy Wilkinson 2019-04-18 09:00:47 UTC
We use Tomcat as the default embedded Servlet container in Spring Boot. Some of our users make use of Tomcat's MBeans but, from what we've seen, the majority of them do not. That's led us to look at the cost of having the MBeans registered by default to see if we can reduce it for users who do not use them. 

One cost is in increased startup time. We've mitigated this by creating an MBeanFactory instance in a separate thread. This causes the MBean XML to be loaded in parallel to the rest of startup which significantly reduces the noticeable effect of the unwanted processing.

The other cost is in increased memory usage. We've tried to find a way to reduce this but have been unable to do so without resorting to reflection. In the reflection-based approach we replace the Registry instance held by org.apache.tomcat.util.modeler.Registry with a custom sub-class that no-ops all of its methods. This hack sees a ~2MB reduction in heap usage. An app that previously required -Xmx9M to start is able to start with -Xmx7M.

We'd greatly appreciate a configuration option in Tomcat that allowed MBean registration to be disabled programatically without resorting to reflective hacks. If the Tomcat community agree that this is a worthwhile enhancement, I would be happy to contribute something once an approach has been agreed upon.
Comment 1 Andy Wilkinson 2019-04-18 09:02:33 UTC
Here [1] is the Spring Boot issue tracking our investigation of disabling MBean registration and the benefits of doing so.

[1] https://github.com/spring-projects/spring-boot/issues/16498
Comment 2 Remy Maucherat 2019-04-18 09:17:22 UTC
Personally, I am (still) not convinced by creative hacks such as a parallel loading contraption or any delayed loading, so it would have to be the pluggable or configurable way.
Comment 3 Mark Thomas 2019-04-23 10:56:08 UTC
Fixed in:
- master for 9.0.20 onwards

Call Registry.disableRegistry() before the first Tomcat MBean is registered.
Comment 4 Remy Maucherat 2019-04-24 13:52:59 UTC
I have verified it seems to work for me without problems. I didn't expect it would be so simple.