University

JVM c1, c2 compiler thread - high CPU consumption?

Cogent Infotech
Blog
Location icon
Dallas, TX

JVM c1, c2 compiler thread  high CPU consumption?

Also known as a tiered compilation in Java Virtual Machines, the Java-platform development kit developers call their clients and servers internally with the name C1 and C2.  The threads that the client Just-in-Time compiler uses are known as C1 compiler threads. And those that the server Just-in-Time compiler uses are called C2 Compiler threads.

The C1 and C2 compiler threads streamline your application's performance. Often, these threads can consume a high CPU, creating problems. Here is a post to help prevent such a situation from arising.

Hot Code

Though a single application may be flooded with lines of code, only a few of these codes get implemented repeatedly. Marked as a hotspot, they are liable for your app's performance. When the app runs, the JVM uses the JIT compiler to streamline these hot codes. Very often, the code developed is not efficient, and this is why the JIT compiler chooses C1 and C2 compiler threads to optimise the code's performance.

Memory space used by the compiler for C1 and C2 compilation is known as Code Cache.

C1 and C2 compiler threads

JIT compilers have two types: client and server.

Depending on the JIT compiler chosen, you should download and install a suitable JDK. For instance, if you have developed a desktop app, you need a client JIT compiler JDK. If you want to build a server app, choose Server JIT compiler JDK.

Once the application begins, the client JIT compiler begins code compilation. However, the server JIT compiler observes the implementation process for some time. Depending on the knowledge it has, the compilation will start. Though the overall server JIT compilation takes time, it offers better results than the client JIT compiler.

The Java Development Kit works with client and server JIT compilers to streamline the app code. In the beginning, the client JIT compilers compile the code, and once sufficient data is acquired, the server JIT compiler starts functioning. The process is known as tiered compiling in Java Virtual Machines. The client and server JIT compiler are called C1 and C2 compiler threads, respectively.

The size of the compiler thread depends on the CPUs available

For 1 CPU, you need one C1 and C2 thread each; for 32 CPUs, you need three C1 and seven C2 threads. And the number further rises with 64 CPUs; the count of C1 and C2 threads are four and eight, respectively.

Solution for big CPU consumption for C1 and C2 compiler thread

Often C1 and C2 use too much CPU. However, you don't need to worry about it as the solutions are available here.

  • Do not be alarmed if the C2 compiler is erratically great and not consistently high; it doesn't affect your app performance.
  • Run this command to your app '-XX:-TieredCompilation' to deactivate the JIT hotspot compiling. It will lower the CPU consumption but may impact the app performance too.
  • If the CPU consumption is significant because of the C2 compiler thread, switch it off. Run this argument '-XX: TieredStopAtLevel=3' to disable the C2 compiler, and only C1 will work.
  • Using the print argument, users can print the compilation process details. It can help them change the compilation procedure accordingly- '-XX:+PrintCompilation'.
  • The hotspot compiler or streamlined code is stockpiled in the memory of the JVM code buffer with a 240 MB default size. The argument XX:ReservedCodeCacheSize=N' can enhance the size. Add 512 in place of N to increase the cache size of the code and lower the compiler thread CPU consumption.
  • Use argument '-XX:CICompilerCount' to boost the C2 compiler count threads. Check out the count of C2 compiler threads; if you notice a lower number, you can add more.

Conclusion

These solutions can help you reduce the high CPU consumption and boost the performance of your application. Use any of them that you find feasible for your problem to get the best results.

For more such information, check out Cogent Infotech.

No items found.

COGENT / RESOURCES

Real-World Journeys

Learn about what we do, who our clients are, and how we create future-ready businesses.
Blog
Introduction to JVM and JVM languages
VM hosts famous languages: Kotlin, Scala, Groovy, Clojure, JRuby
Arrow
Blog
Three Ways in Which AI is Transforming Marketing
In this blog, we will talk about how AI is transforming marketing. Click here to get an in-depth understanding of the topic.
Arrow
Blog
Creating Consumer and Business Value with Subscriptions
Subscription vs. Transaction: The Revenue Retention Revolution
Arrow

Download Resource

Enter your email to download your requested file.
Thank you! Your submission has been received! Please click on the button below to download the file.
Download
Oops! Something went wrong while submitting the form. Please enter a valid email.