Skip to content


修改numa和io调度优化mysql性能

一.NUMA设置
单机单实例,建议关闭NUMA,关闭的方法有三种:
1.硬件层,在BIOS中设置关闭;
2.OS内核,启动时设置numa=off;
3.可以用numactl命令将内存分配策略修改为interleave(交叉)

方法3
修改mysql.server 330行加上numactl
vi /opt/mysql/bin/mysql.server

/usr/bin/numactl –interleave all $bindir/mysqld_safe –datadir=$datadir –pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
wait_for_pid created $!; return_value=$?

numastat 查看内存分配

node0 node1
numa_hit 56506002860 201877592362
numa_miss 9099468163 1450668930
numa_foreign 1450668930 9099468163
interleave_hit 6205106 4793392
local_node 56485823400 201848609519
other_node 9119647623 1479651773

二.IO调度算法
Linux有四种IO调度算法:CFQ,Deadline,Anticipatory和NOOP,CFQ是默认的IO调度算法。完全随机的访问环境下,CFQ与Deadline,NOOP性能差异很小,但是一旦有大的连续IO,CFQ可能会造成小IO的响应延时增加,所以数据库环境建议修改为deadline算法,表现更稳定。
IO调度算法都是基于磁盘设计,所以减少磁头移动是最重要的考虑因素之一,但是使用Flash存储设备之后,不再需要考虑磁头移动的问题,可以使用NOOP算法。NOOP的含义就是NonOperation,意味着不会做任何的IO优化,完全按照请求来FIFO的方式来处理IO。

IO调度,默认cfq
echo ‘deadline’ > /sys/block/sdb/queue/scheduler
cat /sys/block/sdb/queue/scheduler

noop anticipatory [deadline] cfq

减少预读,默认128
echo ’16’ > /sys/block/sda/queue/read_ahead_kb
增大队列,默认128
echo ‘512’ > /sys/block/sda/queue/nr_requests
尽量不使用交换区,默认60
echo ‘0’ > /proc/sys/vm/swappiness

开机运行
vi /etc/rc.local

echo ‘deadline’ > /sys/block/sdb/queue/scheduler
echo ’16’ > /sys/block/sda/queue/read_ahead_kb
echo ‘512’ > /sys/block/sda/queue/nr_requests

vi /etc/sysctl.conf

vm.swappiness=0

参考:
http://blog.wl0.org/2011/03/how-to-start-mysqld-using-numactl/
http://jcole.us/blog/archives/2010/09/28/mysql-swap-insanity-and-the-numa-architecture/
http://linuxcommand.org/man_pages/numactl8.html
http://software.intel.com/zh-cn/blogs/2008/11/24/numaxeon1/
http://www.mysqlops.com/2011/07/01/mysql_multi_using_numactl.html
https://wickie.hlrs.de/platforms/index.php/Thread_And_Memory_Pinning
http://www.cyberciti.biz/tips/linux-hugetlbfs-and-mysql-performance.html
http://www.hellodb.net/2011/07/mysql-linux-hardware-tuning.html
http://blog.csdn.net/liuben/article/details/5482167
http://hatemysql.com/2011/07/05/mysql%E6%9C%BA%E5%99%A8%E9%85%8D%E7%BD%AE%E6%A0%87%E5%87%86/

Posted in Mysql.

Tagged with , , , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.