docker jvm 内存限制

docker 容器提供了相关的内存限制。具体使用方式如:

-m 512m
## 完整例子
docker run –rm -m 512m -e JAVA_OPTS=’-Xmx512m’ tomcat:8

通过-m 进行限制,但是在实际应用重,会出现jvm内存一直到内存满也没有执行gc。


但是在openjdk 还是没有生效。
OpenJDK and Containers
找到。可以使用 -XX:MaxRam=500m。



JVM Argument

-XX:+UseSerialGC Uses only 1 GC thread. This both limits the cpu instruction count for garbage collection, but also results in the minimal memory footprint.
-XX:MaxRAM=n Sets the maximum amount of memory used by the JVM to n, where n may be expressed in terms of megabytes 100m or gigabytes 2g.
-XX:+UseCGroupMemoryLimitForHeap This flag present in the more recent builds of JDK8 tells the JVM to use the information in /sys/fs/cgroup/memory/memory.limit_in_bytes to calculate memory defaults.
-XX:ParallelGCThreads=n Set the number of parallel GC threads to n. This is helpful if you are trying to limit the cpu usage of your container, or if you are running with a JVM that doesn’t include the patch to calculate GC threads based on processors available to the cgroup.
Turns off the optimizing compiler. This can sometimes decrease the footprint of your running JVM.
These parameters tell the heap to shrink aggressively and to grow conservatively.  Thereby optimizing the amount of memory available to the operating system.
These parameters are necessary when running parallel GC if you want to use the Min and Max Heap Free ratios.
These options will print out the non-heap memory usage of your JVM.
-Xss228k This will decrease the size of your Java Stacks.


电子邮件地址不会被公开。 必填项已用*标注