Spring boot eureka服务器占用过多CPU和RAM
我正在为我的 Eureka 服务器使用以下 pom.xml,并以独立模式运行,并在其上注册了大约 300 多个服务。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.etp</groupId>
<artifactId>service-registry</artifactId>
<version>0.0.1</version>
<name>Eureka server</name>
<description>Spring Boot Service registry</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<log4j2.version>2.17.1</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
服务的 application.properties :
spring.application.name=service-registry
server.port=8080
eureka.client.register-with-eureka = false
eureka.client.fetch-registry =false
eureka.client.serviceUrl.defaultZone:http://IP:8080/eureka
Dockerfile :
FROM openjdk:8
WORKDIR /
ADD /target/*.jar service-registry.jar
ADD configuration/application.properties configuration/application.properties
ADD configuration/logback.xml configuration/logback.xml
EXPOSE 8080
ENTRYPOINT ["java","-jar","service-registry.jar"]
当我启动/重新启动 eureka 服务时,它会占用整个可用 CPU 的大约 35-40%,并且内存消耗不断增加。在保持服务开启大约 2 天后,它会占用现在分配的所有内存。(~1Gb)有什么方法可以减少尤里卡服务器的内存或 CPU 消耗?
I am using following pom.xml for my Eureka Server and running in a standalone mode with around 300+ services are being registered on it.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.etp</groupId>
<artifactId>service-registry</artifactId>
<version>0.0.1</version>
<name>Eureka server</name>
<description>Spring Boot Service registry</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<log4j2.version>2.17.1</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties for the service :
spring.application.name=service-registry
server.port=8080
eureka.client.register-with-eureka = false
eureka.client.fetch-registry =false
eureka.client.serviceUrl.defaultZone:http://IP:8080/eureka
Dockerfile :
FROM openjdk:8
WORKDIR /
ADD /target/*.jar service-registry.jar
ADD configuration/application.properties configuration/application.properties
ADD configuration/logback.xml configuration/logback.xml
EXPOSE 8080
ENTRYPOINT ["java","-jar","service-registry.jar"]
When I start/restart eureka service then it takes up around 35-40% of the entire CPU available and memory consumption keeps on increasing continuously. After keeping the service ON for say ~2 days it takes up all memory which has been allocated right now.( ~1Gb) Is there any way to reduce the memory or cpu consumption for eureka server ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这个问题的答案有点晚了。作为另一个遭受同样问题的人。下面解决了我们的问题,它消耗了 25% 的 CPU,现在为 0。
运行应用程序时可以提供以下系统属性。然后它就会正常工作。
我相信
System.nanoTime()
调用会使事情实时消耗更多的 CPU 资源。下面是LatencyUtils的源代码。https://github.com/ LatencyUtils/LatencyUtils/blob/master/src/main/java/org/LatencyUtils/TimeServices.java
Maybe it's a late answer for this question. As another one suffering from the same problem. Below solved our issue, which was consuming %25 of CPU, now 0.
While running the app below system property can be provided.Then it'll work fine.
I believe
System.nanoTime()
calls to make things realtime consume more CPU resource. Below is the source code of LatencyUtils.https://github.com/LatencyUtils/LatencyUtils/blob/master/src/main/java/org/LatencyUtils/TimeServices.java