日期:2014-05-16  浏览次数:20589 次

(转)针对MySQL的Linux性能调优技巧[翻译]
http://mdba.cn/?p=244
原文作者: Alexander Rubin,Percona 工程师
原文连接:Linux performance tuning tips for MySQL
为了方面阅读,我没依照原文按行逐句的进行翻译。另外,我自己的扩充了一下基础知识点,很多知识点也是我第一次去学习,翻阅了一些资料。
原文中对Linux系统参数的优化主要分为文件系统、内存与swap、CPU三方面。
文件系统(Filesystem)
1)使用ext4或者xfs文件系统,mount选项使用noatime选项。
系统默认记录文件创建、修改和上一次访问等信息,记录上last access time需要一定的开销。使用noatime选项,不记录last access time,可以提升系统的性能。
参考:The atime and noatime attribute
2)IO调度算法选择NOOP或则Deadline。
echo deadline > /sys/block/sda/queue/scheduler
add "elevator=deadline" to grub.conf
内存优化(Memory&Swap)
优先使用内存
尽可能使用内存,而少使用swap。只有当内存不够用的时候,系统才会使用swap。
echo 0 > /proc/sys/vm/swappiness
add "vm.swappiness = 0" to /etc/sysctl.conf
屏蔽NUMA特性
设置numactl的interleave参数值为all,即是允许所有的处理器可以交叉访问所有的内存,一致性内存访问(UMA, Uniform Memory Access)方式。
numactl --interleave=all
Node Interleaving: Enable or Disable?详细讲述了交叉访问模式的作用。
The MySQL “swap insanity” problem and the effects of the NUMA architecture深度分析MySQL对于swap的使用和NUMA架构对MySQL的性能影响。
NUMA(Non-Uniform Memory Access)非一致性内存访问架构,是一种多核处理器的内存设计方案。针对每个处理器,NUMA会把全局的存储器分为本地内存(local memory)和非本地内存(no-local memory)。处理器访问本地内存速度比非本地内存的速度快很多。
CPU优化
检查CPU是否开启了节能选项,ondemand表示处于节能状态。[Centos 5.x]
cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
ondemand

ps ax | grep kndemand
2778 ? S< 0:00 [kondemand/0]
2779 ? S< 0:00 [kondemand/1]
2780 ? S< 0:00 [kondemand/2]
2781 ? S< 0:00 [kondemand/3]
2782 ? S< 0:00 [kondemand/4]
2783 ? S< 0:00 [kondemand/5]
2784 ? S< 0:00 [kondemand/6]
2785 ? S< 0:00 [kondemand/7]
上面的的进程状态显示8个cores均开启了节能模式。
另外,通过/proc/cpuinfo中cpu的当前的时钟频率与“model name”中数字是否一致可以得知cpu是否处于节能状态。如下,“model name”显示的2.13GHz,而“cpu Mhz”显示的1867.000MHz,cpu没有达到最大的时钟频率,处于节能状态。
cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 26
model name : Intel(R) Xeon(R) CPU E5506 @ 2.13GHz
stepping : 5
cpu MHz : 1867.000
cache size : 4096 KB
Centos6.x 编译内核的时候没有加上cpufreq  performance模块,因此不能使用”cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor”检查cpu是否处于节能工作状态。
也可以使用
watch grep \"cpu MHz\" /proc/cpuinfo
检查cpu的工作频率。