views:

741

answers:

5

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?

+1  A: 

Why not load all the tests in one JVM ? Can you do one or more of the following ?

  1. load all the tests via a higher-level class ?
  2. specify the test classes in a list (config file) and load each in sequence via Class.forName() ?
  3. if isolation is important, you can create a different class loader per test

If memory allocation is sizeable, it may speed things up by specifying the JVM memory startup size to the same figure as the maximum allocatable memory (-Xms vs -Xmx), which will save the JVM having to go back to the OS for more memory. However in this scenario I think that's unlikely to be the problem.

Brian Agnew
A: 

Run the tests with Java 5 or better. Startup time has been reduced significantly for Java 5.

You can't get much faster unless you can reuse a running VM: Prestarting a lot of them and then running a single test in each won't make your tests any faster.

So you need to figure a way to run several tests in a single VM.

Aaron Digulla
A: 

If it's really necessary for you to start a separate VM for each test, your best option is probably to make sure that you use one of the newest VM releases from Sun. The startup time has decreased quite a bit over the last Java versions and with 1.6.0_16, a simple "Hello world" program takes about 0.2s to run on my system.

If your question rather was ment to be "how to run more tests in one VM", the easiest approach depends on which test framework you are using (if you're not using a framework, you should really consider so). With JUnit and possibly the ant target for JUnit, you can either use patterns to match the tests you want to run or alternatively join different test classes in a test suite, which can then be run in one VM.

jarnbjo
+1  A: 

To add to what has been said by others, next version of Java (Java 7) should add a new improvement in JVM start-up times, due to modularization of the platform, according to this link.

Quote:

One benefit of modularization is that the platform is a smaller download, potentially improving start-up performance. Having a smaller memory footprint also enables significant performance improvements, especially for desktop applications.

ckarmann
+2  A: 

If you do want to reuse JVMs, the "somehow" could be Nailgun

Pete Kirkham