Martynas,
On 11/11/20 10:20, Martynas Jusevičius wrote:
I am attempting to make my webapps that run in Tomcat to take
advantage of the Docker container-specific JVM options such as
-XX:MaxRAMPercentage:
https://www.eclipse.org/openj9/docs/xxinitialrampercentage/
TL;DR It allows specifying JVM heap as % of the container memory limit
rather than using the default 25%.
Running tomcat:9.0.39-jdk11, what I did is specify
CATALINA_OPTS=-XX:MaxRAMPercentage=75
which should use 75% of the container memory limit which is 3.702GiB
in this case.
This is probably going to be a problem for you. The heap you are
specifying is the Java heap only. There are all kinds of other memory
spaces the JVM needs in order to run. You may find that 75% of the
available RAM is so large that you can't do other things.
So I login into the container and execute ps aux to see Tomcat's
command arguments:
/usr/local/openjdk-11/bin/java
-Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djdk.tls.ephemeralDHKeySize=2048
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
-Dorg.apache.catalina.security.SecurityListener.UMASK=0027
-XX:MaxRAMPercentage=75.0 -Duser.timezone=Europe/Copenhagen
-Dignore.endorsed.dirs= -classpath
/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
-Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat
-Djava.io.tmpdir=/usr/local/tomcat/temp
org.apache.catalina.startup.Bootstrap start
If I replace "org.apache.catalina.startup.Bootstrap start" with
"-XshowSettings:vm -version" and run, this is what I get:
Max. Heap Size (Estimated): 2.78G
Using VM: OpenJDK 64-Bit Server VM
Where 2.78G is 75% of 3.7GiB -- so far so good, the MaxRAMPercentage
setting seems to have worked here.
But I'm still getting "Cannot allocate memory" exceptions that kill
the container when importing large datasets. So I attached a profiler.
What I see in the profiler is Max Heap Size 310378496 B, which is only 0.28 GiB.
This is probably the maximum size of the /used/ heap. Can you confirm that?
So how much max heap does my webapp have access to -- is it 2.78G or
0.28G? If it's 0.28, why? How do I enforce the 75% RAM setting for the
webapp?
It's probably the 2.78G. You are likely getting "Cannot allocate memory"
errors because the JVM is trying to allocate non-heap memory.
Try running your application without *any* memory parameters and run it
through a reasonable exercise. Then look at everything with your
profiles *and also* make sure you look at the OS's report of the
allocated memory for the process. That will give you a sense for how
much "native memory" versus heap memory your application actually needs.
You may find that the native memory requirements are roughly the same
size as the Java heap requirements. That means you can't even reasonably
approach a 50% heap size because you still need to be about to run the
OS which takes a bit of memory.
Hope that helps,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org