How To Speedup Java Over 100%
Java is used either for long running server side applications / application servers or for running short scripts. Let's look at how you can speed-up both these type of applications.
How to speed-up server-side Java applications
It is very simple really. Just add -server after the java command like this:
java -server HelloWorld
Replace HelloWorld with your application name. That wasn't so hard was it?
How to speed-up client-side Java applications
Download and install nailgun. You may want to read the quickstart guide for details.
Nailgun is a simple application server which allows you to run Java programs rapidly through the server instance. The nailgun client (ng for linux and ng.exe for windows) is a small c program which works on both windows and linux platforms. To run Java applications you just have to substitute ng (assuming it is in path) for java. ng reduces startup time by running programs from the same instance. However it uses socket connection for communication which can be further optimized.
Let's see how much ng improves the performance for simple client side applications.
Here is a simple HelloWorld program I ran using java:
[angsuman@jaguar project]$ time java HelloWorld Hello World! real 0m0.107s user 0m0.049s sys 0m0.012s
Here is the same program run using nailgun:
[angsuman@jaguar project]$ time ../software/nailgun-0.7.1/ng HelloWorld Hello World! real 0m0.002s user 0m0.000s sys 0m0.001s
Can you see the difference?
Here is the result of running helloworld in C (compiled with gcc):
[angsuman@jaguar project]$ time ./hello Hello World! real 0m0.001s user 0m0.001s sys 0m0.001s
I am using:
[angsuman@jaguar project]$ java -version java version "1.6.0_01″ Java(TM) SE Runtime Environment (build 1.6.0_01-b06) Java HotSpot(TM) Server VM (build 1.6.0_01-b06, mixed mode)
The Java code is:
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
The c code is:
#includeint main(void) { printf("Hello World!\n"); }
Let's finally put to rest the myth that "Java is slow".
Filed under Enterprise Software, Headline News, How To, Java Software, Linux, Open Source Software, Programming, Tech Note |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |





































August 29th, 2007 at 3:14 pm
I downloaded Nailgun and tried out a little test and was impressed by the speed. I did have issues when I tried to run multiple clients through it at the same time. When the first exited, they all did. It looks like it is not supported anymore… Last build was Feb, 2005. Is there any similar alternatives out there?
September 25th, 2007 at 7:11 am
I can build one if there is sufficient demand.
March 13th, 2008 at 10:10 am
It looks like it just speedups the startup time, but most of proffesional apps are started only once a month, so there is no speedup in that case.
The same trick like for example in winamp agent.
But of course very nice idea for some small applications run by user to do small tasks.