I developed a java application on a small windows desktop that parse XML files. I met a very interesting observation that I am very curious about.
我在一个解析XML文件的小型Windows桌面上开发了一个java应用程序。我遇到了一个非常有趣的观察,我非常好奇。
I produced an executable jar for my application and ran it on Windows Server machine that is very powerful. It has 2 physical Xeon processors each 8 cores clocked at 2.7 GHz, 50GB RAM and 7200 RPM HDD. The machine was idle when I started my application and I am pretty sure no other application shared the machine with me.
我为我的应用程序生成了一个可执行jar,并在非常强大的Windows Server机器上运行它。它有2个物理Xeon处理器,每个8核,主频为2.7 GHz,50GB RAM和7200 RPM硬盘。我启动应用程序时机器处于空闲状态,我很确定没有其他应用程序与我共享机器。
Later, I was running the executable on my Macbook Pro for the sake of fun to see its behaviour. My personal machine is Core i7 clocked at 2.2 GHz with 4 GB RAM and 5400 RPM HDD.
后来,我在我的Macbook Pro上运行可执行文件,以便看到它的行为。我的个人机器是Core i7,主频为2.2 GHz,配备4 GB RAM和5400 RPM HDD。
Surprisingly, the application was twice faster on my personal weaker machine. It was the same input \ same output. No IO but for reading the XMLs to parse them, I print nothing on Terminal but Start Time \ End Time & Final result which is one line
令人惊讶的是,应用程序在我个人较弱的机器上快了两倍。这是相同的输入\相同的输出。没有IO,但是为了读取XML来解析它们,我在终端上没有打印,但是开始时间\结束时间和最终结果是一行
I am very curious to understand the reason behind such a dramatic performance difference. Specially from a weaker machine on the level of the hardware. Is it the operating system that handles hardware in a better way?. Is it JVM working better?.
我非常好奇理解这种戏剧性的表现差异背后的原因。特别是来自硬件级别的较弱机器。它是以更好的方式处理硬件的操作系统吗? JVM工作得更好吗?
1 个解决方案
#1
9
On Windows default installations of JRE come with HotSpot Client compiler. This compiler does only basic optimizations, contrary to server HotSpot which does more aggressive optimizations and produces much faster code. Server HotSpot is default on most Unix-like and Linux distributions, including Mac OS X. The performance difference between those two compilers can be often 2-3x. The client HotSpot is optimized mostly for faster startup of desktop applications, not for top performance of long running processes.
在Windows上,JRE的默认安装附带HotSpot Client编译器。此编译器仅执行基本优化,与服务器HotSpot相反,后者执行更积极的优化并生成更快的代码。服务器HotSpot是大多数类Unix和Linux发行版的默认设置,包括Mac OS X.这两个编译器之间的性能差异通常是2-3倍。客户端HotSpot主要针对桌面应用程序的更快启动进行了优化,而不是针对长时间运行的流程的最佳性能。
To check which compiler you are using issue the following command:
要检查您使用的编译器,请发出以下命令:
java -version
On my machine it gives:
在我的机器上它给出:
java version "1.6.0_45"
Java (TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
^^^^^^ this
To get Server HotSpot on Windows, you need to download and install JDK and then run your program with -server
command line switch.
要在Windows上获取Server HotSpot,您需要下载并安装JDK,然后使用-server命令行开关运行程序。
#1
9
On Windows default installations of JRE come with HotSpot Client compiler. This compiler does only basic optimizations, contrary to server HotSpot which does more aggressive optimizations and produces much faster code. Server HotSpot is default on most Unix-like and Linux distributions, including Mac OS X. The performance difference between those two compilers can be often 2-3x. The client HotSpot is optimized mostly for faster startup of desktop applications, not for top performance of long running processes.
在Windows上,JRE的默认安装附带HotSpot Client编译器。此编译器仅执行基本优化,与服务器HotSpot相反,后者执行更积极的优化并生成更快的代码。服务器HotSpot是大多数类Unix和Linux发行版的默认设置,包括Mac OS X.这两个编译器之间的性能差异通常是2-3倍。客户端HotSpot主要针对桌面应用程序的更快启动进行了优化,而不是针对长时间运行的流程的最佳性能。
To check which compiler you are using issue the following command:
要检查您使用的编译器,请发出以下命令:
java -version
On my machine it gives:
在我的机器上它给出:
java version "1.6.0_45"
Java (TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
^^^^^^ this
To get Server HotSpot on Windows, you need to download and install JDK and then run your program with -server
command line switch.
要在Windows上获取Server HotSpot,您需要下载并安装JDK,然后使用-server命令行开关运行程序。