YON CISE

Java CPU Usage Spikes Periodically

Recently, I noticed that when our servers run continuously for about two weeks, the CPU usage gets very high periodically. At first, I thought there were some scheduled tasks causing this, but we couldn’t find any. So, I used the following command to see which threads were causing the high CPU usage:

top -Hp <pid>

I found that the top threads were C2 CompilerThread and C1 CompilerThread. Then, I used jinfo to turn on the PrintCompilation flag:

jinfo -flag +PrintCompilation <pid>

We saw a lot of made zombie and code cache is full messages in the stdout log. We can now confirm that the high CPU usage is caused by JIT repeatedly deoptimizing and optimizing. To fix this, we can increase the code cache size with the JVM argument ReservedCodeCacheSize, which defaults to 240M.