3

I am trying to run a java application inside a docker container, with -Xms4g and -Xmx4g. Ideally when the JVM starts it should have 4G heap pre-allocated.

But when i start the container, I see something like this with docker stats:

 CONTAINER         CPU %               MEM USAGE / LIMIT   
 xyz              73.91%              1.756 GB / 8.203 GB

I have not applied any memory limit to the container. Still the memory used is coming to less than 2GB? I have verified this with top command as well. Also, the Java that I am using is 64-Bit

Is there any docker run option where i can pre-allocate memory?

Vishalendu
  • 73
  • 2
  • 13

1 Answers1

0

pass it as part of the java process. I imagine you have a line like this:

CMD java -jar foo 

just pass them along with the CMD command

CMD java -jar foo -Xms4g -Xmx4g
Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
  • Let me explain the scenario. The single docker image contains more than one applications, so we have a controller script which is ran when the docker run command is invoked. Based on the arguments a certain application is started... Any ways, I can see the following in ps -ef| grep java: `root 18504 18474 54 13:51 pts/3 04:49:21 /opt/IBM/java/jre/bin/java -Duser.timezone=GMT -Xms4g -Xmx4g -XX:+HeapDumpOnOutOfMemoryError -verbose:sizes ...` So seems like the arguments are passed properly.. – Vishalendu May 24 '16 at 17:23
  • One more thing, I have noticed it earlier as well. After the application has been running on for some time, the memory allocation increases. Following is the output from docker stats right now for the above application: `CONTAINER CPU % MEM USAGE / LIMIT xyz 52.68% 2.031 GB / 8.203 GB` As you can see the allocation now is 2.031 GB. It is almost like -Xms4g is not working at all (hence no initial pre-allocation) and the JVM is resizing with -Xmx4g (this should not be when min max heap are same) – Vishalendu May 24 '16 at 18:04