Enabling the JProfilecache Feature
Introduction
During Java application startup, CPU contention can occur between hotspot method Just-In-Time (JIT) compilation and service request processing. This compilation latency may result in a slow performance ramp-up. The JProfilecache feature enables the Java process to rapidly achieve peak performance by leveraging profiling information collected from the previous run to prioritize hotspot method compilation at subsequent startups.
Application Scenario
The CPU resources are limited, the CPU usage of the compilation thread is high, and the peak performance cannot be reached quickly after the process is started.
Restrictions
- The JProfilecache feature is supported in BiSheng JDK 8 since 8u452.
- The Java version must match the JDK package that supports this feature.
- The BiSheng JDK acceleration software package has been installed based on Installing the BiSheng JDK Acceleration Library.
- JProfilecache is an experimental feature currently. To enable it, add -XX:+UnlockExperimentalVMOptions before the feature parameters.
- JProfilecache's hotspot recording capability does not support class unloading, and you need to set the -XX:-ClassUnloading option. Additionally, specific settings are required based on the garbage collector used. If using CMS, set the -XX:-CMSClassUnloadingEnabled option to disable class unloading during garbage collection (GC). If using G1, set the -XX:-ClassUnloadingWithConcurrentMark option.
- The hotspot recording and compilation data loading capabilities of JProfilecache do not support class data sharing. You need to set -XX:-UseSharedSpaces to disable UseSharedSpaces. Additionally, related options, such as -Xshare:on, enable UseSharedSpaces and thus cannot be used together.
- Currently, hotspot profiling and compilation data loading do not support pure interpretation mode.
- JProfilecache's hotspot recording capability relies on the performance profiling function of the interpreter. Therefore, you need to activate interpreter performance profiling by setting the -XX:+ProfileInterpreter option.
- JProfilecache's compilation data loading capability does not support tiered compilation. You need to set the startup option -XX:-TieredCompilation, which is enabled by default.
How to Use
The following uses the spring-petclinic-2.7.3.jar program as an example to show how to use JProfilecache.
- Create a compilation data file.
1java -XX:-ClassUnloading -XX:-CMSClassUnloadingEnabled -XX:-ClassUnloadingWithConcurrentMark -XX:+UnlockExperimentalVMOptions -XX:ProfilingCacheFile=jprofilecache.log -XX:+JProfilingCacheRecording -XX:JProfilingCacheRecordTime=30 -jar spring-petclinic-2.7.3.jar
- Enable JProfilecache to load compilation data.
1java -XX:+UnlockExperimentalVMOptions -XX:+JProfilingCacheCompileAdvance -XX:-TieredCompilation -XX:ProfilingCacheFile=jprofilecache.log -XX:JProfilingCacheDeoptTime=0 -jar spring-petclinic-2.7.3.jar
- Trigger compilation.
- Find the process ID and run the jcmd command to trigger JProfilecache compilation.
jcmd <pid> JProfilecache -notify
If the execution is successful, the message "Command executed successfully" is displayed. If the execution fails, the failure cause is displayed.
- Check whether the compilation is complete. If so, you can run the service.
jcmd <pid> JProfilecache -check
If the compilation is complete, the message "Last compilation task has compile finished" is displayed. If the compilation fails, the failure cause is displayed.
- If JProfilecache is enabled to trigger precompilation, the peak performance of the Java process may deteriorate. After the methods compiled by JProfilecache are deoptimized and recompiled, the peak performance is significantly improved.
- If JProfilecache is enabled to trigger precompilation and the methods compiled by JProfilecache are deoptimized after the specified period, the performance may fluctuate slightly during method recompilation. The actual performance depends on the service condition.
- Find the process ID and run the jcmd command to trigger JProfilecache compilation.
Table 1 describes options in the preceding commands.
Option |
Description |
|---|---|
-XX:JProfilingCacheRecording |
Whether to enable the hotspot recording capability of JProfilecache. |
-XX:JProfilingCacheRecordTime |
Compilation data recording time, in seconds. The default value is 0. |
-XX:ProfilingCacheFile |
Path to the generated compilation data file. |
-XX:JProfilingCacheCompileAdvance |
Whether to enable the compilation capability of JProfilecache. |
-XX:JProfilingCacheDeoptTime |
Duration after which JProfilecache will initiate method deoptimization. You can set JProfilingCacheDeoptTime to 0 to cancel the timer. The default value is 1200, in seconds. If the log "all profilecache methods have been deoptimized" is displayed, all the methods that are compiled by JProfilecache have been deoptimized. |