Why does the JVM require warmup?

2019-01-16 14:06发布

I understand that in the Java virtual machine (JVM), warmup is potentially required as Java loads classes using a lazy loading process and as such you want to ensure that the objects are initialized before you start the main transactions. I am a C++ developer and have not had to deal with similar requirements.

However, the parts I am not able to understand are the following:

  1. Which parts of the code should you warm up?
  2. Even if I warm up some parts of the code, how long does it remain warm (assuming this term only means how long your class objects remain in-memory)?
  3. How does it help if I have objects which need to be created each time I receive an event?

Consider for an example an application that is expected to receive messages over a socket and the transactions could be New Order, Modify Order and Cancel Order or transaction confirmed.

Note that the application is about High Frequency Trading (HFT) so performance is of extreme importance.

7条回答
【Aperson】
2楼-- · 2019-01-16 15:05

It is all about JIT compiler, which is used on the JVM to optimize bytecode in the runtime (because javac can't use advanced or agressive optimization technics due to platform-independent nature of the bytecode)

  1. you can warmup the code that will process your messages. Actually, in most cases you don't need do to it by special warm-up cycles: just let the application to start and process some of the first messages - JVM will try to do its best to analyse code execution and make optimizations :) Manual warm-up with fake samples can yield even worse results

  2. code will be optimized after some amount of time and will be optimized until some event in the program-flow would degradate code state (after it JIT compiler will try to optimize the code again - this process never ends)

  3. short-living objects are subjects to be optimized too but generally it should help your message processing tenured code to be more efficient

查看更多
登录 后发表回答