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?
source share