Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid jvm warmup

Tags:

java

sorting

jvm

If I am designing a test on sorting algorithm can I do this way to avoid JVM warmup ? Thank you!

double count = 0;
double start, end;
for(int r = 0; r < warmup; r++) {
    // do test
}
for(int t = 0; t < runs; t++){
    start = System.nanoTime();
    // do test
    end = System.nanoTime();
    count += start - end;
}
double avg = count/avg
like image 314
Ang Avatar asked Dec 03 '10 13:12

Ang


People also ask

Why does the JVM require warmup?

Why does the JVM require warmup? Bookmark this question. Show activity on this post. 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.

Why do we need to warm-up the Java virtual machine?

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.

Why is my JVM so slow?

The first request made to a Java or JVM web application is often substantially slower than the average response time over the life of the process. This warm-up period can usually be attributed to lazy class loading and just-in-time compilation, which optimize the JVM for subsequent requests that execute identical code.

How do I warm up a Java process in Heroku?

Warming Up a Java Process 1 Prebooting an application. In order to do anything with a process before the router starts sending it requests, you must enable Heroku’s Preboot feature. 2 Creating a warm-up script. ... 3 Enabling the warm-up script. ... 4 Customizing the warm-up script. ... 5 Further reading. ...


1 Answers

The JVM warmup usually refers to the time it takes for the JVM to find the hotspots and JIT these sections of the code. If you run your actual tests a few hundred (actually a few thousand I believe) times you should be fairly good to go.

You should however know that, even if you do this, there are no guarantees. You'll have to experiment with your particular JVM to figure out how much work you have to do before the vital parts is JITed and so on.


In this little case study the JIT compilation kicked in after 1700 calls.

like image 134
aioobe Avatar answered Sep 29 '22 14:09

aioobe