|Summary:||Provide a configuration option to disable MBean registration|
|Product:||Tomcat 9||Reporter:||Andy Wilkinson <awilkinson>|
|Component:||Util||Assignee:||Tomcat Developers Mailing List <dev>|
|OS:||Mac OS X 10.1|
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  is the Spring Boot issue tracking our investigation of disabling MBean registration and the benefits of doing so.  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.