JVM Server vs Client Mode

Last modified on August 1st, 2014 by Joe.

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.

How to choose between client and server jvm mode?

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 on "JVM Server vs Client Mode"

  1. Sylvia says:

    Wonderful article. Every line is worth reading. You keep on giving nice information. Thanks. Thanks.

  2. Srini says:

    Articles like this help us understand the internals of java. Thanks a lot Joe.

  3. Akashdeep says:

    Its really helpful information…

    Thanks a lot Sir….

  4. Kuldeep Pandey says:

    its really a good concept. Thnks Sir

  5. Anonymous says:

    Thanks!

    Why we dont have Server/jvm.dll under JRE?

  6. Hanumanth Kumar says:

    Good Article !!!

  7. Joe says:

    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.

  8. Victor says:

    Good article!
    I’d love to hear more about inlining of virtual method invocations and adaptive compilation though.

  9. suyash says:

    Hi,

    Very nice example and explanation.

    Thanks a lot for sharing this info.

    Regards,
    Suyash Bhalekar

  10. Abhishek says:

    gr8 article

  11. Jitendra says:

    Good Articles

  12. Balaji says:

    Very Good Information.

    Thanks Joe!!!

  13. ranjan says:

    fine article

  14. Anonymous says:

    can you write about jboss configuration in full detail

  15. Zlatan says:

    Should be noted that there is no client mode in 64bit JVM!

  16. Teena says:

    Hi Joe, Please keep an index page of all the links in the site to browse quickly to the required article.

  17. Joe says:

    Thanks Zlatan for the information.

  18. Joe says:

    Yes Teena, I am working on it and will update soon.

  19. lakshmi says:

    thank u sir for this information

  20. Baskaran J says:

    Great Article. Its well articulated with all required details.

  21. […] 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 […]

  22. vanshaj says:

    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!

  23. Domnic Sundar J says:

    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?

    Please clarify!

  24. viaj says:

    very nice

  25. Guru says:

    Good one!!!!

  26. youngto says:

    You keep on giving nice information.Thanks

  27. ucheng says:

    Hi Joe,
    You are such a good writer! Clear and Informative!

  28. pradip garala says:

    Thanks joe…!

  29. Tung says:

    Thank you for good article. A lot of thing I don’t know about Java. :(

  30. pandian says:

    THANKS FOR YOUR INFORMATION AND HELPFUL FOR MY PROJECT

  31. Dhandapani says:

    Hello Sir,

    Thank you so much for this article,

    Thanks
    Dhandapani

  32. Saint Hill says:

    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.

    see http://stackoverflow.com/questions/8894258/fastest-way-to-iterate-over-all-the-chars-in-a-string/11876086#11876086

Comments are closed for "JVM Server vs Client Mode".