服务器错误,状态代码:400,错误代码:100005,消息:您已超出组织的内存限制

Server error, status code: 400, error code: 100005, message: You have exceeded your organization's memory limit

我正在尝试使用 Cloud Foundry 将一个简单的 Spring + Spring 启动应用程序部署到 IBM Cloud。我的 Docker 文件如下所示:

# IBM Java SDK UBI is not available on public docker yet. Use regular
# base as builder until this is ready. For reference:
# https://github.com/ibmruntimes/ci.docker/tree/master/ibmjava/8/sdk/ubi-min

FROM ibmjava:8-sdk AS builder
LABEL maintainer="IBM Java Engineering at IBM Cloud"

WORKDIR /app
RUN apt-get update && apt-get install -y maven

COPY pom.xml .
RUN mvn -N io.takari:maven:wrapper -Dmaven=3.5.0

COPY . /app
RUN ./mvnw install

ARG bx_dev_user=root
ARG bx_dev_userid=1000
RUN BX_DEV_USER=$bx_dev_user
RUN BX_DEV_USERID=$bx_dev_userid
RUN if [ $bx_dev_user != "root" ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

# Multi-stage build. New build stage that uses the UBI as the base image.

# In the short term, we are using the OpenJDK for UBI. Long term, we will use
# the IBM Java Small Footprint JVM (SFJ) for UBI, but that is not in public
# Docker at the moment.
# (https://github.com/ibmruntimes/ci.docker/tree/master/ibmjava/8/sfj/ubi-min)

FROM adoptopenjdk/openjdk8:ubi-jre

# Copy over app from builder image into the runtime image.
RUN mkdir /opt/app
COPY --from=builder /app/target/javaspringapp-1.0-SNAPSHOT.jar /opt/app/app.jar

ENTRYPOINT [ "sh", "-c", "java -jar -XX:MaxRAM=10m /opt/app/app.jar" ]

如您所见,我已将我的应用限制为最多使用 10MB,而我的实例有 256MB 可用。但是,每次部署应用程序时,都会出现以下错误:

此外,当我 运行 ps 命令检查 运行ning 进程时,没有任何东西会消耗我所有的内存。

我在本地 运行 相同的应用程序,它最多只需要 25MB,所以我的实例的 256MB 应该足够了。关于如何解决这个问题有什么想法吗?

注意:很遗憾,目前不允许我增加实例的容量。


[更新] 所以我决定从头开始,在 IBM Cloud 中创建一个新的 Java Spring 应用程序。 IBM 自动将其设置为以 this template 开头,它已克隆到您的存储库中。应用部署正常,可以访问

现在,我在 HTML 中删除了 一行代码 并尝试再次部署。令我惊讶的是,我得到了:

FAILED
Error restarting application: Server error, status code: 400, error code: 100005, message: You have exceeded your organization's memory limit: app requested more memory than available

这怎么可能?!

对于 Lite 帐户,为一个帐户部署的所有应用程序的内存限制为 256 MB:

https://cloud.ibm.com/docs/account?topic=account-noruntimemem

您需要停止所有未使用的 Cloud Foundry 应用程序或升级您的帐户。

在 Cloud Foundry 中,您在应用程序代码中的 manifest.yml 将指定内存。

Note: If you are using a Toolchain, the deployment will create a new application and switch routes on every redeployment in the pipeline, so temporarily you will have two applications running to avoid downtime. This is another scenario where you could potentially run into this memory problem (i.e. your application specifies 256MB of memory but temporarily there is 512MB of usage while both applications are running). To fix this, either manually stop the CF application that's running before running the pipeline (will incur downtime while stopped) or upgrade your account.

我找到了解决办法;这是相当出乎意料和违反直觉的。这是我所做的:

  1. 我将应用程序实例的内存减少到 64MB。

  1. 在manifest.yml中,我将应用程序的内存设置为192M。我的清单如下所示:

applications:
- instances: 1
  timeout: 180
  name: appname
  buildpack: java_buildpack
  path: ./target/appname-1.0-SNAPSHOT.jar
  disk_quota: 1G
  memory: 192M
  domain: eu-gb.mybluemix.net
  host: appHost
  env:
    JAVA_OPTS: '-XX:ReservedCodeCacheSize=32M -XX:MaxDirectMemorySize=32M'
    JBP_CONFIG_OPEN_JDK_JRE: '[memory_calculator: {stack_threads: 2}]'
  1. 我将 manifest.yml 中的更改推送到存储库,开始新的部署。这次应用部署成功,运行顺利

注意:部署后,实例的内存被覆盖,分配了192MB。为了在代码中执行任何进一步的更改,我需要在推送更改和部署应用程序之前将内存设置回 64MB。