jdk client server端区别

jvm的client和server端区别

client 端和 server 端区别

虚拟机 HotSpot
–为什么叫HotSpot虚拟机?
– 如同它的名字,它的特点就是热点代码探测技术,这个技术可以通过执行计数器找出最具有编译价值的代码,然后通过JIT即时编译成机 – 器码并缓存起来,提高执行效率。

HotSpot虚拟机分client端和server端,准确的说应该是分两种类型,因为client,server VM是两种适用不同业务场景的虚拟机类型。
client VM使用的是C1编译器, server VM使用的是C2编译器。

- C1:编译时间短,优化策略简单
- C2:编译时间长,优化策略复杂
C1,C2 都属于JIT编译技术,是JIT的不同实现

所以client server最大的区别就是C1和C2的区别,主要体现在编译策略上:

Client启动快,内存占用少,编译快,针对桌面应用程序优化(比如GUI),为在客户端环境中减少启动时间而优化
Server启动慢,但是一旦运行起来后,性能将会有很大的提升,因为编译更完全,效率高,针对服务端应用优化

另外client/server VM除了在编译策略和性能上的区别外,在内存分配和GC上也不一样:

- client 默认-Xms是1M,-Xmx是64M,新生代选择的是串行gc,旧生代选择的是串行gc
- server 默认-Xms是128M,-Xmx是1024M,新生代选择的是并行回收gc,旧生代选择的是并行gc

大家可以根据具体的业务场景选择,不过现在的系统大部分都是B/S架构,前后端又是分离的,所以我们用的虚拟机大部分都是server类型。

client 端和 server 端对比

client:比较简单,相比server模式许多更复杂的优化,它只需要较少时间来分析和编译一段代码。
它为应用程序和小程序提升了运行时性能。减少了启动时间和内存占用,并对GUI做了优化,以适合客户端环境。

server:比较复杂,先解释执行,然后jvm统计执行热点,将这些热点代码仔细优化编译成本地代码,然后执行本地代码,当这个热点不再是热点的时候,释放编译的代码,重新解释执行。

Server VM包含一个高级自适应编译器,该编译器支持与充分利用c++编译器进行的很多想同类型的优化,以及一些传统编译器无法完成的优化,例如跨虚拟方法调用的主动内联。与静态编译器相比,这是一个竞争优势和性能优势。自适应优化技术的方法非常灵活,通常甚至优于高级静态分析和编译技术。
相比于client模式,server模式最大程度的提升了峰值运行速度。这更适合于需要长时间运行的服务器程序。
而比起客户端程序需要的快速启动和更小的运行内存的占用,服务器程序需要更快的运行速度。
所以,启动时,速度较慢,但是一旦运行起来后,时间久了,性能将会有很大的提升。
所以,这种模式适合长时间的大程序运行,所以比较适合服务器。

在这里插入图片描述
可以看到最明显的差异是JVM client端和server端关于method call方法调用上的性能对比(红色是server VM,黄色是client VM,越高越好)。
那个差别不是一般的大,在后来的测试中发现,相差至少有10倍

其他

从白皮书的第2章(Java HotSpot性能引擎体系结构)开始:
The JDK includes two flavors of the VM – a client-side offering, and a VM tuned for server applications. These two solutions share the Java HotSpot runtime environment code base, but use different compilers that are suited to the distinctly unique performance characteristics of clients and servers. These differences include the compilation inlining policy and heap defaults.

Although the Server and the Client VMs are similar, the Server VM has been specially tuned to maximize peak operating speed. It is intended for executing long-running server applications, which need the fastest possible operating speed more than a fast start-up time or smaller runtime memory footprint.

The Client VM compiler serves as an upgrade for both the Classic VM and the just-in-time (JIT) compilers used by previous versions of the JDK. The Client VM offers improved run time performance for applications and applets. The Java HotSpot Client VM has been specially tuned to reduce application start-up time and memory footprint, making it particularly well suited for client environments. In general, the client system is better for GUIs.

因此,真正的区别还在于编译器级别:

The Client VM compiler does not try to execute many of the more complex optimizations performed by the compiler in the Server VM, but in exchange, it requires less time to analyze and compile a piece of code. This means the Client VM can start up faster and requires a smaller memory footprint.

The Server VM contains an advanced adaptive compiler that supports many of the same types of optimizations performed by optimizing C++ compilers, as well as some optimizations that cannot be done by traditional compilers, such as aggressive inlining across virtual method invocations. This is a competitive and performance advantage over static compilers. Adaptive optimization technology is very flexible in its approach, and typically outperforms even advanced static analysis and compilation techniques.

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值