JVM is launched in client mode by default in SUN/Orace JDK. JVM provides option to launch it in server or client mode. These two modes give different run time performance options.
At high level there are two steps from java source to running program. In first step we compile the java source to binary class file. In next step binary class is executed. In java class execution, combination of interpretation and compilation is done. Generally it is interpretation and to boost the performance JVM uses a just-in-time (JIT) compiler.
JIT compiles selective block of code to native instructions. Because running native instructions is always better and gives good performance. This is done at the cost of spending resource to compile code to native. There will be a performance benefit, if that block of code is used repeatedly as in subsequent runs instead of interpreting the binary code the native instructions will be executed.
When the JVM is launched in ‘server’ mode, it performs aggressive optimization than the ‘client’ mode. So server mode is better suited for production deployments and gives better performance. In case of tiny programs, where there is minimal scope for optimization server mode may not be best suited and in times it can even give worst performance than the client mode because of the additional cost of native code conversion.
The policy of having a JIT compiler and the performance optimization algorithm are completely the choice of the JVM implementors and it is not enforced in JVM specification. So when we study this behavior it is completely specific to the JVM we use and it cannot be generalized.
To choose between server and client mode we can have client mode for small programs that are not executed for a longer period and server mode otherwise. The startup of the JVM might be slower in server mode and the runtime memory footprint also will be larger. Client mode starts JVM in quicker time and memory footprint is also lesser. This is because client mode does not try to optimize many code blocks as the server mode does. Therefore the shorter startup time and less memory usage.
So what is the special optimization done by server mode? One example is in lining of virtual method invocations wherever it is used. This is done by adaptive compilation. One more thing done by server mode is, it does not give back the memory acquired back to the OS till the execution is complete. But in case of client mode if a certain block of memory is left unused it may give back to the OS during the execution of the program. Initial options like InitialHeapSize and MaxHeapSize are taken as large numbers in server mode on launch in comparison with client mode.
JVM hotspot VM options provide rich set of opportunities to calibrate the runtime performance. So to launch is client mode we need not give any options as by default the JVM launches in client mode. To launch in server mode just use “- server” when we run java tool like,
java -server ClassName
This is based on SUN/Oracle JDK. If it is JRockit VM the default is server mode and client mode should be launched using option “-client”. Ah I forgot to mention a thing, as always the same java class can be used for running in both the modes. When we download JDK we get both the modes bundled. If we download JRE alone, then we get only the client mode with it.
Just in case if you don’t know what JVM you are using then the following java code should help.
String jvmName = System.getProperty("java.vm.name"); // jvmName = Java HotSpot(TM) Server VM
In a future article, I plan to showcase performance benchmark of sever and client mode.
Comments are closed for "JVM Server vs Client Mode".
Wonderful article. Every line is worth reading. You keep on giving nice information. Thanks. Thanks.
Articles like this help us understand the internals of java. Thanks a lot Joe.
Its really helpful information…
Thanks a lot Sir….
its really a good concept. Thnks Sir
Why we dont have Server/jvm.dll under JRE?
Good Article !!!
When we install JRE separately, we don’t get the server (server/jvm.dll) mode.
Inside the JDK there is a JRE and the jvm.dll can be found at “\Java\jdk1.7.0_07\jre\bin\server” which will be used when we use server mode.
I’d love to hear more about inlining of virtual method invocations and adaptive compilation though.
Very nice example and explanation.
Thanks a lot for sharing this info.
Very Good Information.
can you write about jboss configuration in full detail
Should be noted that there is no client mode in 64bit JVM!
Hi Joe, Please keep an index page of all the links in the site to browse quickly to the required article.
Thanks Zlatan for the information.
Yes Teena, I am working on it and will update soon.
thank u sir for this information
Great Article. Its well articulated with all required details.
[…] of JVM Server and Client Mode 09/12/2012Couple of weeks back, I wrote an article to introduce JVM server and client mode and discussed about how they differ performance wise. I just thought of running some programs and […]
I always listen my project manager that “in production environmnt latency will not be there” but didnt know why he tell like this
With this article i came to know why in production application behaves faster.
Thanks Joe for a nice article!
Thanks for the Info…
I know that,
1,When we install JDK:
we can get the jvm.dll both in Server and Client under JDK–>JRE.
2, When we install JRE seperately:
Why we are not having server/jvm.dll under JRE.?but we are having client/jvm.dll in it?
why we dont have server mode option under JRE, when we install JRE seperately?
You keep on giving nice information.Thanks
You are such a good writer! Clear and Informative!
Thank you for good article. A lot of thing I don’t know about Java. :(
THANKS FOR YOUR INFORMATION AND HELPFUL FOR MY PROJECT
Thank you so much for this article,
In a recent test posted to StackOverflow, it can be demonstrated that -server is slower with the optimized code it produces than the equivalent code produced in -client mode. I am interested to hear what you think may be causing this phenomenom.