gpt4 book ai didi

java - spring boot maven插件-jvm参数-直接内存大小设置

转载 作者:行者123 更新时间:2023-12-02 18:59:52 26 4
gpt4 key购买 nike

我正在使用 spring-boot-maven-plugin 通过以下命令从我的应用构建 docker 镜像:

spring-boot::build-image

我需要使用这个 jvm 参数更改 jvm 直接内存的默认大小(默认为 10m):

-XX:MaxDirectMemorySize=64M

这是我在应用程序的 pom.xml 中尝试的所有尝试:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<jvmArguments>-XX:MaxDirectMemorySize=64M</jvmArguments>
<environmentVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</environmentVariables>
<systemPropertyVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</systemPropertyVariables>
</configuration>
</execution>
</executions>

<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
</image>

<excludeDevtools>true</excludeDevtools>

<systemPropertyVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</systemPropertyVariables>
<environmentVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</environmentVariables>
<jvmArguments>-XX:MaxDirectMemorySize=64M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</jvmArguments>
</configuration>
</plugin>

但是直接内存仍然设置为 10M :(当应用程序启动时,我可以在日志文件中看到:

Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx11521920K -XX:MaxMetaspaceSize=144375K -XX:ReservedCodeCacheSize=240M -Xss1M -Dorg.springframework.cloud.bindings.boot.enable=true

谁能告诉我我做错了什么?

注意事项:

Spring Boot:2.3.7.RELEASE

当我使用 -e 手动运行 docker image 时,jvm 参数的更改正在起作用:

docker run -e JAVA_TOOL_OPTIONS=-XX:MaxDirectMemorySize=64M  docker.io/example/app-name:0.0.1

这个 mvn 插件使用 Buildpack 创建 docker 镜像:

https://paketo.io/docs/buildpacks/language-family-buildpacks/java/#about-the-jvm

更新:

根据文档,这应该是可行的解决方案,但它不是:

            <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
<env>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>

最佳答案

这是一个关于如何使运行时环境“有粘性”的工作解决方案:

....
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
<env>
<BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</BPE_APPEND_JAVA_TOOL_OPTIONS>
<BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
</env>
</image>
...

spring-boot-maven-plugin 使用 paketo 构建包:

文档: https://github.com/paketo-buildpacks/environment-variables

关于java - spring boot maven插件-jvm参数-直接内存大小设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65709080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com