CPU Tuning

Cache share tuning

对于物理 CPU,同一个 core 的 threads 共享 L2 Cache,同一个 socket 的 cores 共享 L3 cache,所以虚拟机的 vcpu 应当尽可能在同一个 core 和 同一个 socket 中,增加 cache 的命中率,从而提高性能。IBM 测试过,合理绑定 vcpu 能给 JVM 来的 16% 的性能提升[2]。
      实现策略:虚拟机 vcpu 尽可能限定在一个 core 或者一个 socket 中。例如:当 vcpu 为 2 时,2 个 vcpu 应限定在同一个 core 中,当 vcpu 大于 2 小于 12 时,应限定在同一个 socket 中。

<vcpu
placement=
'static' cpuset='0-5'>4</vcpu>       #
cpuset 限定 vcpu

NUMA tuning

网易运维团队测试得出:2 个 vcpu 分别绑定到不同 numa
节点的非超线程核上和分配到一对相邻的超线程核上的性能相差有 30%~40%(通过 SPEC CPU2006 工具测试)。可见,同一个虚拟机的
vcpu 需限定在同一个 NUMA 节点,并且分配该 NUMA 节点下的内存给虚拟机,保证虚拟机尽可能访问 local memory 而非
remote memory。

关于 memory allocation mode: If memory is overcommitted in strict mode and
the guest does not have sufficient swap space, the kernel will kill
some guest processes to retrieve additonal memory. Red Hat recommends
using preferred allocation and specifying a single
nodeset (for example, nodeset='0') to prevent this situation[1].

<numatune>
  <memory
mode=
"preferred" nodeset="0"/> 
</numatune>

IRQ tuning

CPU0 常用于处理中断请求,本身负荷较重[3]。事实上,线上环境 CPU0 完全处理 eth0 的 IRQ,eth1 的 IRQ
完全由另一个 CPU 处理,同时 CPU0 处理着大量的 CAL 类型中断。预留 2 个或者 4 个物理 CPU,这些 CPU
和对应网卡中断做绑定,使得其它 CPU 更好更完整的为云主机所用。

VCPU topology tuning

Selecting any desired number of sockets, but with only a single core and
a single thread usually gives the best performance results[1]. 即 VCPU 的
topology 设置为 sockets = vcpu_number, cores = 1, threads = 1.

Disk IO Tuning

Disk IO cache Tuning

kvm 支持多种虚拟机多种 IO Cache 方式:writeback, none, writethrough
等。性能上:writeback > none > writethrough,安全上 writeback < none <
writethrough。For the best storage performance on guest operating
systems that use raw disk volumes or partitions, completely avoid the
page
cache on the host[2].

<disk type='file' device='disk'>
  <driver
name=
'qemu' type='qcow2' cache='none'/>  #
cache 可为 writeback, none, writethrough,directsync,unsafe 等
  ...
</disk>

           
      

Disk IO scheduler

cfq 参数调优。

Memory Tuning

1. 关于 zone_reclaim_mode,设置为 disable 。

2. 关于 swappiness 参数,若 CPU macro-architecture 非 Intel Nehalem 架构,无需要修改优化。

3. 关闭 KVM 内存共享:When KSM merges across nodes on a NUMA host with multiple
guest virtual machines, guests and CPUs from more distant nodes can
suffer a significant increase of access latency to the merged KSM
page[1].

Disable KSM 方式有两种:

1) 禁止某个 Guest 与其它 Guest 共享内存,XML 文件可配置为

<memoryBacking>
    <nosharepages/>
</memoryBacking>

2)  禁止所有 Guest 直接共享内存,Host 配置为

echo 0
/sys/kernel/mm/ksm/pages_shared
echo 0
/sys/kernel/mm/ksm/pages_sharing

4. 打开透明大页:KVM guests can be deployed with huge page memory support in
order to improve performance by increasing CPU cache hits against the
Transaction Lookaside Buffer (TLB)[1].

打开透明大页方式有两种:

1) 允许某个 Guest 开启透明大页

Guest
XML Format
<memoryBacking>
   <hugepages/>
</memoryBacking>
 
echo 25000
/pro c/sys/vm/nr_hugepages
mount -t
hugetlbfs hugetlbfs 
/dev/hugepages
service
libvirtd restart

2) 允许 Host 中所有 Guest 开启透明大页

echo always
/sys/kernel/mm/transparent_hugepage/enabled
echo never
/sys/kernel/mm/transparent_hugepage/defrag
echo 0
/sys/kernel/mm/transparent_hugepage/khugepaged/defrag

Network IO Tuning

开启 vhost_net 模式[3]。

参考资料

    1. Red Hat Enterprise Linux 6 Virtualization Tuning Optimization Guide
    2. Tuning KVM for performance    IBM
    3. 网易 openstack 部署运维实战

kvm 性能调优的更多相关文章

  1. 恒天云技术分享系列3 – KVM性能调优

    恒天云技术分享:http://www.hengtianyun.com/download-show-id-11.html KVM是什么 KVM 是 kernel-based Virtual Machin ...

  2. web前端性能调优

    最近2个月一直在做手机端和电视端开发,开发的过程遇到过各种坑.弄到快元旦了,终于把上线了.2个月干下来满满的的辛苦,没有那么忙了自己准备把前端的性能调优总结以下,以方便以后自己再次使用到的时候得于得心 ...

  3. [网站性能2]Asp.net平台下网站性能调优的实战方案

    文章来源:http://www.cnblogs.com/dingjie08/archive/2009/11/10/1599929.html 前言    最近帮朋友运营的平台进行了性能调优,效果还不错, ...

  4. Asp.net平台下网站性能调优的实战方案(转)

    转载地址:http://www.cnblogs.com/chenkai/archive/2009/11/07/1597795.html 前言 最近帮朋友运营的平台进行了性能调优,效果还不错,所以写出来 ...

  5. 第0/24周 SQL Server 性能调优培训引言

    大家好,这是我在博客园写的第一篇博文,之所以要开这个博客,是我对MS SQL技术学习的一个兴趣记录. 作为计算机专业毕业的人,自己对技术的掌握总是觉得很肤浅,博而不专,到现在我才发现自己的兴趣所在,于 ...

  6. sqlserver性能调优第一步

    相信不少的朋友,无论是做开发.架构的,还是DBA等,都经常听说“调优”这个词.说起“调优”,可能会让很多技术人员心头激情澎湃,也可能会让很多人感觉苦恼,不知道如何入手.当然,也有很多人对此不屑一顾,因 ...

  7. JavaScript:内存泄露、性能调优

    1.在进行JS内存泄露检查之前,先要了解JS的内存管理: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Manageme ...

  8. hadoop 性能调优与运维

    hadoop 性能调优与运维 . 硬件选择 . 操作系统调优与jvm调优 . hadoop运维 硬件选择 1) hadoop运行环境 2)  原则一: 主节点可靠性要好于从节点 原则二:多路多核,高频 ...

  9. JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解

    摘要: JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外,还有jps.jstack.jmap.jhat.jstat.hprof等小巧的工具,本博客希望 ...

随机推荐

  1. demo_07选择器练习

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. 【WPF】逻辑树和视觉树

    WPF中提供了遍历逻辑树和视觉树的辅助类:System.Windows.LogicalTreeHelper和 System.Windows.Media.VisualTreeHelper. 注意遍历的位 ...

  3. Xcode 设置输出颜色

    是不是看厌了Xcode单调的Log,在此,我教大家实现带颜色的Log 一 首先你需要安装一个Xcode插件---XCode Colors 插件Github地址 https://github.com/r ...

  4. UIStackView 简单使用

    UIStackView提供了一个高效的接口用于平铺一行或一列的视图组合.对于嵌入到StackView的视图,你不用再添加自动布局的约束了.Stack View管理这些子视图的布局,并帮你自动布局约束. ...

  5. KVO - 键值观察

    [基本概念] 键值观察是一种使对象获取其他对象的特定属性变化的通知机制.控制器层的绑定技术就是严重依赖键值观察获得模型层和控制器层的变化通知的.对于不依赖控制器层类的应用程序,键值观察提供了一种简化的 ...

  6. UIImage拉伸显示

    下面张图片,是设计来做按钮背景的:  button.png,尺寸为:24x60 现在我们把它用作为按钮背景,按钮尺寸是150x50,以下是没有经过技术性拉伸处理的情况: // 得到view的尺寸   ...

  7. underscore demo

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  8. django ORM中update_or_create功能,如果只要匹配某一特定字段呢

    今天发现的需求,在官方文档找到说法: In English, that means start with any non-'defaults' keyword argument that doesn’ ...

  9. 测来测去,感觉REQUESTS最实在

    URLLIB,URLLIB2,PYCURL,HTTPIE,,,在测试PUT及认证时,还是REQUESTS胜出.. 测试过程及样例代码如下: import urllib import urllib2 i ...

  10. [topcoder]IncreasingSubsequences

    http://community.topcoder.com/stat?c=problem_statement&pm=7753&rd=10672 http://community.top ...