Wednesday, February 4, 2009

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:

#include
int main(void)
{
printf("Hello World!\n");
}
Now Lets Don Say That JAVA is Slow

No comments:

Post a Comment