Why Is Maven So Slow? [Solved]By Roger Keays, 24 October 2012, 10:46 AM |
![Why Is Maven So Slow? [Solved]](ox/webcore/attachments/22600/maven-logo.png?width=295&height=295)
I couldn't figure out why the heck my maven builds where taking so long. I thought Java was supposed to be fast these days and here I am waiting 30 seconds to run a unit test. So I did some digging and eventually found the problem.
On Linux, the default JVM is the Server JVM which does all sorts of useful optimisations for long running server process but is absolutely dog slow for building source code (this could also be a reason why the Linux community thinks Java sucks so much).
To find out what JVM you are running simply type:
$ java -version java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)
If you see "Server VM" like the example above do me a favor and time your maven compile (mvn clean compile) then switch to the Client VM, time it again and post your results in the comments below.
Why Is Maven So Slow? [Solved]Here is my output with the Server VM:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:05.320s
[INFO] Finished at: Tue Oct 23 22:25:44 ECT 2012
[INFO] Final Memory: 19M/197M
[INFO] ------------------------------------------------------------------------
The simplest way to switch to the Client VM is to find and patch jvm.cfg. You can also export MAVEN_OPTS="-client", but unfortunately maven doesn't use these options when forking for unit tests or executing your app so you have to update your pom.xml adding -client to all plugins that fork jvms.
My jvm.cfg is in $JAVA_HOME/jre/lib/i386/jvm.cfg. Edit it and make sure -client KNOWN appears on the first line.
-client KNOWN
-server KNOWN
-hotspot ALIASED_TO -client
-classic WARN
-native ERROR
-green ERROR
Now check that it worked.
$ java -version java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode)
And rebuild your app.
$ mvn clean install ... [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.612s
[INFO] Finished at: Tue Oct 23 22:33:48 ECT 2012
[INFO] Final Memory: 17M/78M
[INFO] ------------------------------------------------------------------------
That's a full three times faster using half the memory.
I just got a few more years life out of my laptop.
![]() |
Roger is an active member of the JSF 2 Expert Group and is happy to be a contributor to the Java Community. He has been writing software since the age of 8 and his other interests include languages, science, travel and surfing. You can follow Roger on Twitter and Google+. |
| « JSF Error Pages That Actually Work | Back to Blog | How To Sort Your Unit Tests By Layer In TestNG » |