I created a spring-boot project from https://start.spring.io/ and set the version to 2.1.1.RELEASE. I had not add any code but the following maven dependences.

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

When I start the this app, I notice that the CUP utilization will reach over 100% for few seconds during the startup and finally will drop back to be normal after the app started up.

At first, I thought it was caused by the full GC of metadata,so I add the -XX:MetaspaceSize=128m JVM option. After that the full GC disappear, but the CPU utilization still reach over 100%.

java -XX:MetaspaceSize=128m -jar demo.jar

I tested on a machine with the following configuration:

  • CPU: 4
  • Memory: 16G
  • JDK: oracle 1.8.0_201

So what make me confused that it is a normal situation that the CPU utilization will reach 100% for few seconds during application startup . cleanshot 2019-02-28 at 12 31 16

Comment From: wilkinsona

Spring Boot uses more than one thread during startup so it is normal for CPU usage to peak at over 100%.

Comment From: slice-chopsach

Hey @wilkinsona , is there any workaround to not hit max CPU usage in spring boot applications? We have a service which hits max CPU usage on deployments leading to very high latencies for some of the APIs serving live traffic.

Comment From: wilkinsona

You need to identify the bottlenecks in your application and optimise them. If that's not possible, you need to reduce the load or increase capacity. If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Comment From: ccdredzik

@wilkinsona Are you sure that it is not a spring-boot bug? I am currently looking at my java services based on spring-boot. A service running with maximum 25mcores under load, aside from startup when it can use up to 1.75 cores. That is 70 times more CPU usage when initialising a rather simple app.

Comment From: soulsoul

mark