简体   繁体   English

如果Java堆内存限制与kubernetes中的pod资源限制不同,会发生什么?

[英]what happens if the java heap memory limits is different than the pod resource limits in kubernetes?

I'm running a spring boot inside a pod with the below configurations. 我正在使用以下配置在吊舱内运行弹簧靴。

Pod limits: Pod限制:

resources:
    limits:
      cpu: "1"
      memory: 2500Mi
    requests:
      cpu: "1"
      memory: 2500Mi

command args: 命令args:

spec:
containers:
- args:
  - -c
  - ln -sf /dev/stdout /var/log/access.log;java -Dcom.sun.management.jmxremote
    -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false -Djava.security.egd=file:/dev/./urandom
    -Xms1600m -Xmx1600m -XX:NewSize=420m -XX............
  1. What happens if the java process has reached its max heap limit (ie 1600m (Xmx1600m)) 如果java进程达到其最大堆限制(即1600m(Xmx1600m))会发生什么
  2. If Xmx has no effect on the java process inside a pod, it can go up to pod limit right (ie memory: 2500Mi of limits section) 如果Xmx对pod内的java进程没有影响,它可以直接进入pod限制(即内存:2500Mi的限制部分)
  3. If the above configurations are correct, then we are wasting 900Mi of memory right (2500-1600=900) 如果上面的配置是正确的,那么我们正在浪费900Mi的内存(2500-1600 = 900)

The -Xmx flag only controls Java heap memory, which is space available for your own Java objects when running your code. -Xmx标志仅控制Java堆内存,这是运行代码时可用于自己的Java对象的空间。 If you run out, JVM will do garbage collection to make space. 如果你用完了,JVM会做垃圾收集来腾出空间。 If you still ran out, you get an OutOfMemoryException thrown. 如果仍然用完,则会抛出OutOfMemoryException。

Java JVM also uses a bunch of other memory internally for stuff like loading classes, JIT compilation etc... Therefore you need to allow more memory in Kubernetes than just -Xmx value. Java JVM还在内部使用了一堆其他内存来加载类,JIT编译等...因此,您需要在Kubernetes中允许更多内存而不仅仅是-Xmx值。 If you exceed the Kubernetes limit value, then probably Java will crash. 如果超过Kubernetes限制值,那么Java可能会崩溃。

The config you posted above looks fine. 您在上面发布的配置看起来很好。 Normally I come to find these values by looking at the Kubernetes memory usage graph after running for some time without limits. 通常我会在运行一段时间后无限制地查看Kubernetes内存使用情况图来找到这些值。

If running a JVM in docker, rather than set the -Xmx , -Xms option manually, it's better to use -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap to tell JVM to respect the container's limit. 如果在docker中运行JVM,而不是手动设置-Xmx-Xms选项,最好使用-XX:+ UnlockExperimentalVMOptions -XX:+ UseCGroupMemoryLimitForHeap告诉JVM遵守容器的限制。

see https://hub.docker.com/_/openjdk/ Make JVM respect CPU and RAM limits for more information. 请参阅https://hub.docker.com/_/openjdk/ 使JVM尊重CPU和RAM限制以获取更多信息。

If the java process has reached its max heap limit, then the jvm will throw outofmemory error if it cannot regain heap memory after GC. 如果java进程已达到其最大堆限制,那么如果在GC之后它无法重新获得堆内存,那么jvm将抛出outofmemory错误。 In this case, the pods will be running but the java process is in error. 在这种情况下,pod将运行但java进程出错。

Xmx has effect on the jvm heap inside the POD and the jvm heap cannot exceed that. Xmx对POD内的jvm堆有影响,jvm堆不能超过它。 In your case the jvm heap can likely be increased, since the memory to the pod is comparatively high. 在你的情况下,jvm堆可能会增加,因为pod的内存相对较高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM