11

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.

Community
  • 1
  • 1
Rudiger
  • 6,634
  • 9
  • 40
  • 57
  • This is a slightly stupid comment, but I'm going to say it anyway just to help the debate - I'm as interested in knowing the answer as everyone else! :) I would guess that certain optimisations performed by the JVM will depend on the data being processed. Unless your data is identical (including the time in which it arrives) the optimisations performed could be different each time. If the data is always the same, then you only need run the app once :) – Rich Sep 23 '10 at 14:31
  • There is also this: http://stackoverflow.com/questions/2178640/is-there-a-way-to-save-the-java-jit-information-for-the-next-run-so-that-i-dont – Rich Sep 23 '10 at 14:50
  • If you knew what optimizations the VM was taking with your code, and you know the data patterns will not change, is it possible for you to use the what-was-optimized knowledge and modify your app's logic to reflect it? – matt b Sep 23 '10 at 15:04

4 Answers4

6

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.

locka
  • 5,809
  • 3
  • 33
  • 38
3

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
2

Few more options to tune up the JIT.

1. Class Data sharing http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.user.aix64.60%2Fuser%2Fclassdatasharing.html

2. Tiered Compilation See details for flag -XX:+TieredCompilation

3. Custom CompileThreshold Controls number of invocations of a function that would make it eligible for JIT compile. See details for flag -XX:CompileThreshold. Never make this to ZERO or ONE. Your tampering here may result in deterioration of performance. JVM gives you the option though. -server defaults this to 10000.

Ronn Macc
  • 1,271
  • 9
  • 7
2

Are you sure it is CPU related and not IO related? I have seen this behaviour a lot of times, when hitting a cold cache somewhere worsens performance.

gpeche
  • 21,974
  • 5
  • 38
  • 51