Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up Java VM (JVM) startup time?

I am running tests that start multiple JVM processes. Summary startup time of JVMs is quite significant compared to time of actual tests that run inside JVM. How do I speed things up?

I have used "-client" option already, this does help but not as much as I wanted. Is there any other way, say preloading bunch of JVMs and reusing them somehow?

like image 617
Hubert Łępicki Avatar asked Sep 29 '09 08:09

Hubert Łępicki


People also ask

How can I speed up JVM?

JVM startup performance can be improved in many ways: CDS, straight up tuning, CPU pinning and jlink (since JDK 9) can be good options. AOT (JDK 9, Linux-only) has some rough edges but can be tuned to help small applications.

Why is JVM startup slow?

2.1 Possible Causes for Slow JVM Startup An application might seem slow when it starts because, The application might be waiting to import files. A large number of methods might have to be compiled. There might be a problem in code optimization (especially on single-CPU machines).

What is the fastest JVM?

The fastest of them all is GraalVM EE 17, but the difference compared to OpenJDK 8/OpenJDK 17 is marginal. Here is a graph with the typical 256-byte message latency for the various JDK variants used (lower is better): Graph 1, Shows the median (typical) latency in ns for the various JDK variants.


1 Answers

If you do want to reuse JVMs, the "somehow" could be Nailgun. Nailgun keeps a JVM running, then uses a light native client to start a particular class and handle console io. This is good for running small command line Java utilities, but as it reuses the same JVM can accumulate state.

To work around the state accumulation, at the cost of running multiple JVMs, another option is Drip. Drip keeps a fresh JVM spun up in reserve with the correct classpath and other JVM options so you can quickly connect and use it when needed, then throw it away. Drip hashes the JVM options and stores information about how to connect to the JVM in a directory with the hash value as its name.

like image 79
Pete Kirkham Avatar answered Oct 02 '22 19:10

Pete Kirkham