我在5个线程中执行了超过30000个REST请求(每个线程6,000个),在SpringBoot中运行在Tomcat之上的Swagger,在运行35分钟后得到下一个错误:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 16384 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# JVM is running with Zero Based Compressed Oops mode in which the Java heap is
# placed in the first 32GB address space. The Java Heap base address is the
# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress
# to set the Java Heap base and to place the Java Heap above 32GB virtual address.
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2985), pid=24780, tid=58785
#
# JRE version: OpenJDK Runtime Environment (11.0.11+9) (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
# Java VM: OpenJDK 64-Bit Server VM (11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
Command Line: -Xverify:none -XX:TieredStopAtLevel=1 -Xms2g -Xmx10g com.CamelSpringBootApplication
Host: Common KVM processor, 16 cores, 28G, Ubuntu 20.04.2 LTS
Time: Mon May 31 15:40:22 2021 CEST elapsed time: 2122.252495 seconds (0d 0h 35m 22s)我遗漏了一些信息,也不知道原因。我在哪里犯了错?到底是什么占用了这么多内存,我如何在运行时释放内存?
只有在重新启动虚拟机后,内存才会恢复到64 VM。在我再次启动SpringBoot应用程序后,内存甚至在运行REST请求之前就开始下降。我需要支持尽可能多的REST请求,保留内存并防止SpringBoot应用程序崩溃。

更新:
这些是收集的堆转储的结果。我已经在heaphero.io中加载了heapdump.bin。我将感谢任何基于此结果的提示。

发布于 2021-06-01 12:04:52
这只是一个危险的猜测,在计算了大约30000个垃圾收集数量的四分之一之后,你可能超过了垃圾收集,调用System.gc();来通知垃圾收集。This i wrote位于内存中,需要一个小的垃圾管理检查和计数器。
发布于 2021-06-01 15:59:40
我希望你已经分配了足够的堆大小,即使你的Linux机器有64 GB的RAM,你也需要根据应用程序的传入流量从外部扩展它的默认容量。
您可以在pom.xml文件中增加spring boot应用程序的堆大小,如下所示:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Xmx4096m</jvmArguments>
</configuration>
</plugin>https://stackoverflow.com/questions/67775360
复制相似问题