0

I'm using Wildfly 11 and Java 8. I'm running into OutOfMemory errors due to lack of MetaSpace so I'm looking for ways to optimize my class loading. I have several WAR files that run on the same app server. Most contain the same types of classes

$WILDFLY_HOME/myapp.war/WEB-INF/lib/spring-context-4.3.8.RELEASE.jar
$WILDFLY_HOME/myapp.war/WEB-INF/lib/spring-context-support-4.3.8.RELEASE.jar
...

I'm wondering if this is a problem (e.g. Wildfly attempts to load the same class twice for different applications) and if so, what options are available to me for cutting down my memory footprint due to class loading?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • it can't load same class twice, the first one that is found wins, I doubt this is the root of your problem. And also meta space in java-8 has no limit really, so you might want to explain and provide logs for what is going on – Eugene Feb 06 '18 at 08:25
  • You should create a module for your spring jars, thus they would be loaded only once per the module classloader instead of being loaded for each application (since java EE mandates a child first classloading) – ehsavoie Feb 06 '18 at 09:19
  • @ehsavole, If I packaged my WAR files in an EAR and deployed the EAR instead, would that cut down on loading the same class for each application? – Dave Feb 06 '18 at 16:38
  • @Eugene, Regarding "meta space in java-8 has no limit", then why can that be specified as a parameter when starting your Java process (e.g. "-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m")? If there were no limit, it seems to be these wouldn't even be options. – Dave Feb 06 '18 at 16:40
  • @Dave `-XX:MetaspaceSize=size` *Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used*. And `-XX:MaxMetaspaceSize=size` *Sets the maximum amount of native memory that can be allocated for class metadata. By default, the size is not limited. The amount of metadata for an application depends on the application itself, other running applications, and the amount of memory available on the system* – Eugene Feb 06 '18 at 19:25
  • @Dave so the first one does not do what you might think it does and the second indeed species a max, but, *by default* there is no max, as much memory as you have – Eugene Feb 06 '18 at 19:26
  • @Eugene, so what you are saying is that if we dno't specify "-XX:MaxMetaspaceSize=512m" (which we currently are), the JVM will just use as much memory as is available. Unfrotunately we don't have that much memory on our system, which is why I'm trying to be judicious about cutting down on class loading. – Dave Feb 06 '18 at 20:21
  • exactly. your desire is understood and it makes perfect sense, `512MB` in Meta might be too much, but I don't know your application, you might be really consuming that much space, you could play with `MaxMetaspaceFreeRatio` and `MinMetaspaceFreeRatio`, probably even enable GC logs to get a better picture a good resource here : https://stackoverflow.com/questions/25251388/what-is-the-metadata-gc-threshold-and-how-do-i-tune-it – Eugene Feb 06 '18 at 20:39

0 Answers0