Spring boot eureka服务器占用过多CPU和RAM

发布于 2025-01-11 12:47:44 字数 3862 浏览 0 评论 0原文

我正在为我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2025-01-18 12:47:44

也许这个问题的答案有点晚了。作为另一个遭受同样问题的人。下面解决了我们的问题,它消耗了 25% 的 CPU,现在为 0。

运行应用程序时可以提供以下系统属性。然后它就会正常工作。

-DLatencyUtils.useActualTime=false 

我相信 System.nanoTime() 调用会使事情实时消耗更多的 CPU 资源。下面是LatencyUtils的源代码。

https://github.com/ LatencyUtils/LatencyUtils/blob/master/src/main/java/org/LatencyUtils/TimeServices.java

java.util.concurrent.locks.LockSupport.parkNanos())。然而,如果
该财产。
LatencyUtils.useActualTime 设置为“false”,
时间服务器只会移动时间概念来响应调用
到 #setCurrentTime() 方法。

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.

-DLatencyUtils.useActualTime=false 

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

java.util.concurrent.locks.LockSupport.parkNanos()). However, if
the property.
LatencyUtils.useActualTime is set to "false",
TimeServers will only move the notion of time in response to calls
to the #setCurrentTime() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文