Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java/JVM (HotSpot): Is there a way to save JIT performance gains at compile time?

When I measure the throughput of my Java application, I see a 50% performance increase over time:

  • For the first 100K messages, I get ~3,000 messages per second
  • For the second 100K messages, I get ~4,500 messages per second.

I believe the performance improves as JIT optimizes the execution path.

The reason given for not saving the JIT compilation is that "the optimizations that the JVM performs are not static, but rather dynamic, based on the data patterns as well as code patterns. It's likely that these data patterns will change during the application's lifetime, rendering the cached optimisations less than optimal."

However, I know for a fact that these data patterns won't change during my application's lifetime, or even over multiple application lifetimes. So how can I "save" these performance gains in the HotSpot JVM?

See also, the relevant question and discussion.

like image 539
Rudiger Avatar asked Sep 23 '10 14:09

Rudiger


2 Answers

You could try adapting your app to run it with Nailgun. Instead of invoking your app against a fresh JVM each time you invoke it against a Nailgun server which is a long-lived JVM. The second time you invoke your app, the nailgun JVM will have optimized the paths in your classes and should therefore execute a lot faster than it would from fresh.

like image 80
locka Avatar answered Oct 04 '22 12:10

locka


Use '-server' to do much more up front. Hotspot does not as far as I know allow for saving jit information between runs so -server is the simplest way to tell it what you want it to do.

like image 40
Thorbjørn Ravn Andersen Avatar answered Oct 04 '22 11:10

Thorbjørn Ravn Andersen