有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在尝试使用CloudFoundry将一个简单的Spring+Spring启动应用程序部署到IBMCloud。我的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可用空间。但是,每次部署应用程序时,都会出现以下错误: Log 1

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

Log 2

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

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


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

现在,我删除了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

这怎么可能


共 (2) 个答案

  1. # 1 楼答案

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

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

    enter image description here

    1. 在舱单上。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. 我推送清单中的更改。yml到回购协议,开始新的部署。这一次,应用程序成功部署并顺利运行

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

  2. # 2 楼答案

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

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

    您需要停止任何未使用的Cloud Foundry应用程序,或者升级您的帐户

    在CloudFoundry中,您的显示。应用程序代码中的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.