简体   繁体   English

为什么主机系统上的lua比linux vm慢?

[英]Why is lua on host system slower than in the linux vm?

Comparing executing time of this Lua Script on a Macbook Air (Mac OS 10.9.4, i5-4250U (1.3GHz), 8GB RAM) to a VM (virtualbox) running Arch Linux. 比较Macbook Air上的这个Lua Script的执行时间(Mac OS 10.9.4,i5-4250U(1.3GHz),8GB RAM)到运行Arch Linux的VM(虚拟机)。

Compiling Lua 5.2.3 in a Arch Linux virtualbox 在Arch Linux虚拟框中编译Lua 5.2.3

First I've compiled lua by myself using clang, to compare it with the Mac OS X clang binary. 首先,我使用clang编译lua,将其与Mac OS X clang二进制文件进行比较。

using tcc, gcc and clang 使用tcc,gcc和clang

$ tcc *[^ca].c lgc.c lfunc.c lua.c -lm -o luatcc
$ gcc -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luagcc
/tmp/ccxAEYH8.o: In function `os_tmpname':
loslib.c:(.text+0x29c): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
$ clang -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luaclang
/tmp/loslib-bd4ef4.o:loslib.c:function os_tmpname: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
clang version in VM VM中的clang版本
$ ls -lh |grep lua
-rwxr-xr-x 1 markus markus 210K 20. Aug 18:21 luaclang
-rwxr-xr-x 1 markus markus 251K 20. Aug 18:22 luagcc
-rwxr-xr-x 1 markus markus 287K 20. Aug 18:22 luatcc

compare the file size 比较文件大小

 $ ls -lh |grep lua -rwxr-xr-x 1 markus markus 210K 20. Aug 18:21 luaclang -rwxr-xr-x 1 markus markus 251K 20. Aug 18:22 luagcc -rwxr-xr-x 1 markus markus 287K 20. Aug 18:22 luatcc 

VM benchmarking VM基准测试

clang binary ~3.1 sec clang binary~3.1秒

$ time ./luagcc sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real    0m3.090s
user    0m3.080s
sys 0m0.007s

gcc binary ~3.09 sec gcc二进制~3.09秒

$ time ./luatcc sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real    0m7.071s
user    0m7.053s
sys 0m0.010s

tcc binary ~7.0 sec - no surprise here :) tcc二进制~7.1秒 - 这里不奇怪:)

 $ time ./luatcc sumdata.lua data.log Original Size: 117261680 kb Compressed Size: 96727557 kb real 0m7.071s user 0m7.053s sys 0m0.010s 

Compiling on Mac OS X 在Mac OS X上编译

Now compiling lua with the same clang command/options like in the VM. 现在使用与VM中相同的clang命令/选项编译lua。

Markuss-MacBook-Air:bin markus$ ./clang --version
clang version 3.4.2 (tags/RELEASE_34/dot2-rc1)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Markuss-MacBook-Air:bin markus$ clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
clang version Mac OS X 铿锵版Mac OS X.

I've tried two version. 我试过两个版本。 3.4.2 and the one which is provided by xcode. 3.4.2和xcode提供的那个。 The version 3.4.2 is a bit slower. 版本3.4.2有点慢。

 Markuss-MacBook-Air:bin markus$ ./clang --version clang version 3.4.2 (tags/RELEASE_34/dot2-rc1) Target: x86_64-apple-darwin13.3.0 Thread model: posix Markuss-MacBook-Air:bin markus$ clang --version Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.3.0 Thread model: posix 

file size 文件大小

 $ ls -lh|grep lua -rwxr-xr-x 1 markus staff 194K 20 Aug 18:26 luaclangmac 

HOST benchmarking HOST基准测试

clang binary ~4.3 sec 铿锵二进制~4.3秒

 $ time ./luaclangmac sumdata.lua data.log Original Size: 117261680 kb Compressed Size: 96727557 kb real 0m4.338s user 0m4.264s sys 0m0.062s 

Why? 为什么?

I would have expected that the host system is a little faster than the virtualization (or roughly the same speed). 我本以为主机系统比虚拟化(或大致相同的速度)快一点。 But not that the host system is reproducible slower. 但并非主机系统的可重现性较慢。

So, any ideas or explanations? 那么,任何想法或解释?

Update 2014.10.30 更新2014.10.30

Meanwhile I've installed Arch Linux nativly on my MBA. 与此同时,我已经在我的MBA上安装了Arch Linux。 The benchmarks are as fast as in the Arch Linux VM. 基准测试与Arch Linux VM一样快。

Can you try to run 'perf stat' instead of 'time'. 你能尝试运行'perf stat'而不是'time'。 It provides you much more details and the time measurement is more correct, avoiding timing differences inside the VM. 它为您提供了更多细节,时间测量更加正确,避免了VM内部的时序差异。

Here is an example: 这是一个例子:

$ perf stat ls > /dev/null

Performance counter stats for 'ls': 'ls'的性能计数器统计信息:

     23.348076      task-clock (msec)         #    0.989 CPUs utilized          
             2      context-switches          #    0.086 K/sec                  
             0      cpu-migrations            #    0.000 K/sec                  
            93      page-faults               #    0.004 M/sec                  
    74,628,308      cycles                    #    3.196 GHz                     [65.75%]
       740,755      stalled-cycles-frontend   #    0.99% frontend cycles idle    [48.66%]
    29,200,738      stalled-cycles-backend    #   39.13% backend  cycles idle    [60.02%]
    80,592,001      instructions              #    1.08  insns per cycle        
                                              #    0.36  stalled cycles per insn
    17,746,633      branches                  #  760.090 M/sec                   [60.00%]
       642,360      branch-misses             #    3.62% of all branches         [48.64%]

   0.023609439 seconds time elapsed

My guess is that the HFS+ journaling feature is adding latency. 我的猜测是HFS +日记功能正在增加延迟。 This would be easy enough to test: If TimeMachine is running on the Macbook Air, you could try disabling it, and disable journaling on the filesystem (obviously you should back up first). 这很容易测试:如果TimeMachine在Macbook Air上运行,你可以尝试禁用它,并禁用文件系统上的日记功能(显然你应该先备份)。 As root: 作为根:

diskutil disableJournal YourDiskVolume

I'd see if that's the cause of the problem. 我会看看这是不是问题的原因。 Then i would immediately re-enable journaling. 然后我会立即重新启用日记功能。

diskutil enableJournal YourDiskVolume

OS X 10.9.2 had a journaling-related bug that would hang the filesystem... this page explores this bug further, and even though the bug (#15821723) hasn't been reported as fixed, journaling reportedly no longer crashes the disk controller. OS X 10.9.2有一个与日志相关的错误会挂起文件系统... 这个页面进一步探讨了这个错误,即使错误(#15821723)没有被报告为已修复,据说日志记录不再崩溃磁盘控制器。

to test the speed of lua, instead of reading a file hard-code some sample data into the test script and loop over the lines over and over as necessary. 测试lua的速度,而不是读取文件硬编码一些示例数据到测试脚本中,并根据需要一遍又一遍地循环。 Like others mentioned, the filesystem effects are going to outweigh any compiler differences. 与其他提到的一样,文件系统效果将超过任何编译器差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM