The difference between JVM client mode and Server mode
The main difference between JVM Server mode and client mode is that when starting: - Server mode is slow when starting, but once it starts, the performance will be greatly improved.
JVM can greatly improve performance when working in Server mode. The startup speed of applications in Server mode will be about 10% slower than client mode, but the running speed is at least 10 times faster than Client VM.
When the running mode parameters are not specified, the virtual machine starts to detect whether the host is a server. If so, it will start in Server mode. Otherwise, it will start in client mode. The basis for J2SE5.0 detection is at least 2 CPUs and a minimum of 2GB of memory.
Since the server's CPU, memory and hard disk are stronger than the client machine, after the program is deployed, it should be started in server mode to obtain better performance;
JVM defaults to -Xms is 1M, -Xmx is 64M in client mode; JVM defaults to -Xms is 128M, -Xmx is 1024M in server mode;
server: Slow startup and more complete compilation. The compiler is an adaptive compiler with high efficiency and is designed to optimize server-side applications and maximize program execution speed in the server environment.
client: Quick startup, low memory usage, fast compilation, optimized for desktop applications, optimized to reduce startup time in client environment;
When the JVM is used to start interactive applications of the GUI interface, it is recommended to use the client mode when the JVM is used to run the server background program.
We can check what mode jvm works by running:java -version.
About GCC in Figure 1
In the client mode, the new generation chooses serial gc, while the old generation chooses serial gc, while the old generation chooses serial gc
In server mode, the new generation chooses parallel recycling of gc, while the old generation chooses parallel gc.
Generally speaking, there are two ways to choose our system application: throughput priority and pause time priority. For throughput priority, the server's default parallel GC method is adopted, and for pause time priority, the concurrent gc (CMS) method is adopted.
Other extended knowledge points
JDK has two types of VM, VM client, and VM server applications. The two solutions share the hotspot code base of the Java runtime environment, but use different compilers, unique performance features for clients and servers, with differences including writing inline policies and default values for the heap.
Although the server is similar to the client virtual machine, the server VM has specially adjusted the maximum peak operating speed. Its purpose is to execute long-running server applications, which require the fastest run speeds exceeding a fast startup time or a smaller runtime memory footprint.
The Client VM compiler is a classic virtual machine and a compiler used by real-time upgrades (JIT) through previous versions of JDK. Client virtual machines provide improved performance for running applications and applets. Hotspots of Java Virtual Machines Customers have reduced the startup time and memory usage of applications to make them particularly suitable for the customer environment. In general, the client system has a better graphical user interface.
So the real difference is also at the compiler level:
The client virtual machine compiler does not attempt to perform more complex optimizations performed by the compiler on the server virtual machine, but during the swap it takes less time to analyze and compile a piece of code. This means that the client virtual machine can start faster and requires a smaller memory footprint.
The server virtual machine contains an advanced adaptive compiler that supports many C++ compiler optimizations for optimization, the same type, and some optimizations that cannot be done with traditional compilers, such as actively inlined virtual method calls. This is a competitive and performance advantage, static compiler. Adaptive optimization techniques are very flexible in its approach and are usually superior to even advanced static analysis and compilation techniques.
When starting -Server mode, the speed is slow, but once it is run, the performance will be greatly improved. The reason is that when the virtual machine is in -Client mode, it uses a lightweight compiler codenamed C1, while the virtual machine started in -Server mode uses a relatively heavyweight compiler codenamed C2. C2 is relatively thoroughly compiled than the C1 compiler, and after serving, it has higher performance.
Generally, just change the order of the two configurations -server KNOWN and -client KNOWN, as long as the JAVA_HOME/jre/bin directory exists at the same time, corresponding to their respective jvm
After saying so much, I actually summed up in one sentence:
The application starts slowly but runs faster in JVM Server mode, while the application starts quickly but runs faster in JVM Client mode.
Recommended: Please run in Server mode on the server, and run in Client mode in client mode or GUI mode.