C2 Compiler saturates the processor at startup

I have a Java 7 servlet application in Java 7, which is usually very useful in terms of consuming system resources. Typically, server CPU usage is below 50%. However, a few minutes after the launch, it behaves differently, to the extent that the CPU can be tied to 100% within a few minutes if it tries to serve a lot of traffic during this period. The result is slow response times, network timeouts, and even long pauses in garbage collection.

To diagnose the problem, I took a series of thread dumps when the server started, and I ran top -H at the same time. Comparing each java thread with pid, I can sequentially see C2 CompilerThread , using, of course, the most central processor. I did research on what this thread does, and I understand that this is Java compiler optimization code based on runtime statistics. But of all that I read, I can’t say how best to improve the situation. The only options I can get are the following:

  • Switching from C2 to TieredCompiler (but will it lead to better performance in the first few minutes after launch?)
  • Turn on -XX: + PrintCompilation to see what is being optimized (but what should I do with this information? Can I get it to be optimized before the server somehow accepts the traffic?)

What is the best approach and are there any other options to try to make it easier to use the CPU after startup?

+5
source share
1 answer

There are several platforms for JVM technology that can alleviate your problem using time-based compilation.

However, if you want to stick with standard JVMs, the one trick people use is that after you launch, you send some dummy requests so that the JVM warms up before you actually start working. This way you can decide when you want to pay for the JVM warm-up before serving your customers.

You can also force the JVM to compile all the code using the -Xcomp command-line options for the access point, but we do not recommend it, as this will slow down your application by compiling its rarely used code.

0
source

Source: https://habr.com/ru/post/1204215/


All Articles