1. 从费用上比较
收费和免费:
- xen 和 kvm 都是开源免费的虚拟化软件。
- vmware 是付费的虚拟化软件。
- hyper-v 比较特别,是微软windows 2008 r2附带的虚拟化组件,如果你买了足够的授权,hyper-v(包括hyper-v 2008 core)都可以免费使用。
因此:
- 如果是vmware或hyper-v虚拟windows系统,不管是虚拟化软件本身,还是其中的子系统,都要支付许可费用。
- 如果是vmware或hyper-v虚拟linux,虚拟化软件本身要支付许可费用,子系统可以用linux来节省成本。
- 如果是xen或kvm虚拟windows,其中的子系统要支付许可费用。
- 如果是xen或kvm虚拟linux,那么虚拟化软件本身和其中的子系统无需产生任何费用。
结论:
- 虚拟 windows,在有授权的情况下,建议使用 hyper-v;在没有授权的情况下,虚拟windows,建议使用 kvm
- 虚拟 linux,建议使用 xen,如考虑到需要降低管理维护和学习成本,建议使用kvm。
2. 从性能上比较
虚拟windows,如果都能得到厂商的支持,那么,性能优化可以不用担心。这几款软件全都能达到主系统至少80%以上的性能(磁 盘,cpu,网络,内存),这时建议使用 hyper-v 来虚拟windows,微软自身的产品,虚拟windows是绝对有优势的。
2.1 i/o 比较
如果是虚拟 linux,建议:
- 首先使用 xen,支持linux的半虚拟化,可以直接使用主系统的cpu和磁盘及网络资源,达到较少的虚拟化调度操作,可以达到非常高的性能,但xen操作复杂,维护成本较高。
- 其次我们推荐kvm来虚拟linux,linux本身支持kvm的virtio技术,可以达到少量的虚拟化调度操 作,得到较高的系统性能。
- 不推荐使用hyper-v来虚拟linux,太多的不兼容性导致linux基本无法在hyper-v上跑。
2.2 性能测试报告
本测试使用裸机作为虚拟服务测试的基准设备。在不跑虚拟机的情况下,两台裸机的性能偏差不会大于0.51%
在几乎所有测试中,kvm 的性能相比宿主机而言下降了1.5%以内,只有两项测试例外。第一个是 7-zip 压缩,比宿主机慢了 2.79%。第二个就奇怪了,我们搭了一个邮件服务器,用 postmark 测试其性能,结果表明 kvm 竟比宿主机快了4.11%。然后我在两台服务器中重新跑了几遍 postmark 测试,结果性能差异基本不变,浮动都在最初测试结果的1%以内。由于我对 virtio 的内部机制没有很深的理解,我只能在以后再对这个怪现象进行进一步了解。
xen 的性能相对宿主机而言差异就比较大了。有3项测试性能下降在2.5%以内,剩下的性能下降率都是 kvm 的2~4倍。postmark 测试的性能比 kvm 慢了14.41%,这结果令我大吃一惊。重新跑了下测试,性能差还是几乎不变,浮动都在最初结果的2%以内。kvm 表现最好的 cpu 测试:mafft 对齐测试,是 xen 表现倒数第二差的。
现在奉上一个简短的总结表:
best value | bare metal | kvm | xen | |
c-ray | lower | 35.35 | 35.66 | 36.13 |
pov-ray | lower | 230.02 | 232.44 | 235.89 |
smallpt | lower | 160 | 162 | 167.5 |
john the ripper (blowfish) | higher | 3026 | 2991.5 | 2856 |
john the ripper (des) | higher | 7374833.5 | 7271833.5 | 6911167 |
john the ripper (md5) | higher | 49548 | 48899.5 | 46653.5 |
openssl | higher | 397.68 | 393.95 | 388.25 |
7-zip | higher | 12467.5 | 12129.5 | 11879 |
timed mafft alignment | lower | 7.78 | 7.795 | 8.42 |
clomp | higher | 3.3 | 3.285 | 3.125 |
postmark | higher | 3667 | 3824 | 3205 |
如果需要完整数据,请查看goole docs 电子表格。
结论
基于上面的测试环境,kvm 的性能损耗几乎都在2%以内,xen 则在十多项测试中有3项损耗在2.5%以内,而其他几项损耗都在5~7%之间。虽然 kvm 在 postmark 测试中性能表现优异,但这是众多测试中仅有的一项 i/o 测试,如果想证明 kvm 确实在 i/o 处理方面很强悍,就需要更多测试。
2.3 更多的测试报告
在经过综合测试后,不论是单个parallel还是两个parallel,xen的跑分测试都比kvm要好。
三种虚拟化性能比较 lxc>>kvm>>xen (由于lxc使用cgroup机制,其性能损坏基本为0。)
三种虚拟化隔离比较 xen>>kvm>>lxc (lxc只能虚拟化linux)
三种虚拟化内存利用率 lxc>>kvm>>xen (由于lxc共用内核,内存利用率最高;其他两种方案每个虚机都需要单独的操作系统占用一部分内存空间。)
从运算性能和磁盘负载角度来说linux kvm不失为最快的虚拟化解决方案。相比之下,virtualbox在测试中排名第二,而xen在hvm模式下的虚拟化表现最差。
综上:比较有意思的是这些测试报告的结论都不太一样甚至是相反的。
3. 产方支持
如果以上产品我们不打算买厂商支持,其中vmware和hyper-v,是不建议使用的,主要是授权问题。
这时就剩下kvm和xen了,如果虚拟windows,建议使用 kvm,我们可以从 redhat那里免费拿到针对 windows 优化过的磁盘和网络的驱动 程序,可以达到较高的性能(几乎与hyper-v性能持平)。
而xen的 windows 优化驱动不是那么容易就能拿到的(由于redhat以后不支持 xen了,看看novell是否放水了,呵呵,就开放程度上来讲,redhat要好于novell)。
4. 特性比较
attribute | zones | xen | kvm |
cpu performance | high | high (with cpu support) | high (with cpu support) |
cpu allocation | flexible (fss + “bursting”) | fixed to vcpu limit | fixed to vcpu limit |
i/o throughput | high (no intrinsic overhead) | low or medium (with paravirt) | low or medium (with paravirt) |
i/o latency | low (no intrinsic overhead) | some (i/o proxy overhead) | some (i/o proxy overhead) |
memory access overhead | none | some (ept/npt or shadow page tables) | some (ept/npt or shadow page tables) |
memory loss | none | some (extra kernels; page tables) | some (extra kernels; page tables) |
memory allocation | flexible (unused guest memory used for file system cache) | fixed (and possible double-caching) | fixed (and possible double-caching) |
resource controls | many (depends on os) | some (depends on hypervisor) | most (os + hypervisor) |
observability: from the host | highest (see everything) | low (resource usage, hypervisor statistics) | medium (resource usage, hypervisor statistics, os inspection of hypervisor) |
observability: from the guest | medium (see everything permitted, incl. some physical resource stats) | low (guest only) | low (guest only) |
hypervisor complexity | low (os partitions) | high (complex hypervisor) | medium |
different os guests | usually no (sometimes possible with syscall translation) | yes | yes |
更多的特性比较:
mechanism | operating system | license | available since/between | features | |||||||||
file system isolation | copy on write | disk quotas | i/o rate limiting | memory limits | cpu quotas | network isolation | nested virtualization | partition checkpointing and live migration |
root privilege isolation | ||||
chroot | most unix-likeoperating systems | varies by operating system | 1982 | partial[5] | no | no | no | no | no | no | yes | no | no |
docker | linux[6] | apache license 2.0 | 2013 | yes | yes | not directly | not directly | yes | yes | yes | yes | no | no |
linux-vserver (security context) |
linux | gnu gplv2 | 2001 | yes | yes | yes | yes[7] | yes | yes | partial[8] | ? | no | partial[9] |
lmctfy | linux | apache license 2.0 | 2013 | yes | yes | yes | yes[7] | yes | yes | partial[8] | ? | no | partial[9] |
lxc | linux | gnu gplv2 | 2008 | yes[10] | partial. yes withbtrfs. | partial. yes withlvm ordisk quota. | yes | yes | yes | yes | yes | no | yes[10] |
openvz | linux | gnu gplv2 | 2005 | yes | no | yes | yes[11] | yes | yes | yes[12] | no | yes | yes[13] |
virtuozzo | linux,windows | proprietary | july 2000[14] | yes | yes | yes | yes[15] | yes | yes | yes[12] | ? | yes | yes |
solaris containers(zones) | solaris,opensolaris,illumos | cddl | february 2004 | yes | yes (zfs) | yes | partial. yes with illumos.[16] | yes | yes | yes[17] | partial. only when top level is a kvm zone (illumos) or a kz zone (oracle) | no[18] | yes[19] |
freebsd jail | freebsd | bsd license | 1998 | yes | yes (zfs) | yes[20] | no | yes[21] | yes | yes | yes | no | yes[22] |
sysjail | openbsd,netbsd | bsd license | no longer supported, as of march 3, 2009 | yes | no | no | no | no | no | yes | no | no | ? |
wpars | aix | proprietary | 2007 | yes | no | yes | yes | yes | yes | yes[23] | no | yes[24] | ? |
hp-ux containers (srp) | hpux | proprietary | 2007 | yes | no | partial. yes with logical volumes | yes | yes | yes | yes | ? | yes | ? |
icore virtual accounts | windows xp | proprietary/freeware | 2008 | yes | no | yes | no | no | no | no | ? | no | ? |
sandboxie | windows | proprietary/shareware | 2004 |