仅获得通过 app.yaml 分配的内存的四分之一

Only getting quarter of the memory allocated via app.yaml

我们在 appengine flex 上 运行 java8/jetty9 设置。在app.yaml我们分配了30G的RAM。但是在服务器中,当我们调用 Runtime.getRuntime().maxMemory() 时,返回的数字是 ~7G。如果我将 RAM 增加到 60G,这个数字会增加到 ~15G。似乎 JVM 只获得我们在 app.yaml.

中分配的 RAM 的四分之一

我也试过 运行 带有 -Xmx30g 的服务器

但是服务器上传失败并出现错误

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 7158235136 bytes for committing reserved memory.

确认我们在 Runtime.getRuntime().maxMemory 中看到的错误,当我们分配了 30G 的 RAM 时,有 ~7G 的限制。 剩下的 75% 分配到哪里去了?

这是 Dockerfile


    FROM gcr.io/google-appengine/jetty9
    RUN apt-get -q update && \
        apt-get -y -q --no-install-recommends -t jessie-backports install 
    openjdk-8-jdk && \
        apt-get -y -q --no-install-recommends install ssh sshpass && \
        apt-get clean && \
        rm /var/lib/apt/lists/*_*
    ADD backend.war $JETTY_BASE/webapps/root.war
    WORKDIR $JETTY_BASE
    RUN java -jar -Xmx30g -Xms20g $JETTY_HOME/start.jar --approve-all-licenses \
       --add-to-startd=jmx,stats,hawtio,requestlog \
       -Djava.util.logging.config.file=src/main/appengine/logging.properties \
       && chown -R jetty:jetty $JETTY_BASE

这里是app.yaml


    runtime: custom
    threadsafe: true
    env: flex

    handlers:
    - url: /.*
      script: this field is required, but ignored
      secure: always

    health_check:
      enable_health_check: True
      check_interval_sec: 5
      timeout_sec: 4
      unhealthy_threshold: 2
      healthy_threshold: 2

    resources:
      cpu: 6
      memory_gb: 30
      disk_size_gb: 20
    automatic_scaling:
      min_num_instances: 1
      max_num_instances: 3
      cool_down_period_sec: 120
      cpu_utilization:
        target_utilization: 0.5


 env_variables:
  JAVA_OPTS: "-Xmx16g"

将以上内容添加到 app.yaml 就成功了...