CodexBloom - Programming Q&A Platform

Strange CPU usage spike on Ubuntu 22.04 when running Java application with OpenJDK 11

๐Ÿ‘€ Views: 0 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-07-05
java ubuntu performance Java

I'm performance testing and Quick question that's been bugging me - I've searched everywhere and can't find a clear answer..... I tried several approaches but none seem to work. I'm experiencing a important CPU usage spike on my Ubuntu 22.04 server when running a Java application using OpenJDK 11. The application is a Spring Boot service that handles around 100 concurrent requests, and while it's designed to be efficient, I noticed that CPU usage fluctuates wildly, sometimes hitting 90% for several seconds. This behavior seems to occur mainly during peak load times. I've tried profiling the application with VisualVM, and it shows that the garbage collector is invoked more frequently than expected. Hereโ€™s the GC log snippet I captured: ``` [GC (Allocation Failure) 2020K->2048K(204800K), 0.0023452 secs] [Full GC (Ergonomics) 2048K->1024K(204800K), 0.0145674 secs] ``` Iโ€™ve also increased the heap size in my `application.properties`: ``` server.port=8080 spring.application.name=myapp spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=user spring.datasource.password=pass # JVM Options JAVA_OPTS=-Xms512m -Xmx2048m -XX:+UseG1GC ``` Despite this, the performance scenario continues. I've looked into possible memory leaks but havenโ€™t found anything alarming. Additionally, I monitored the application using `htop` and found that the Java process spikes in CPU usage without corresponding memory usage increases. Could this be related to the G1 garbage collector's behavior under load, or is there something else I might be missing in my configuration? Any insights would be appreciated! My development environment is Linux. I've been using Java for about a year now. What's the correct way to implement this? I'm using Java 3.9 in this project. Thanks, I really appreciate it! I recently upgraded to Java 3.11. I appreciate any insights!