磁盘IO性能优化-实践
RAID卡缓存策略调整
可以将RAID卡缓存策略由No Write Cache if bad BBU调整为Write Cache OK if bad BBU,即在电池充放电时不关闭缓存,以此保证I/O性能。但是此法存在数据丢失风险,需要合理评估再做调整。
原因详解
服务器的Riad卡都带有可充电电池,这块可充电电池在不使用时也会有微弱的放电现象,当它的电量放电到低到一定程度时,Raid卡控制器就会对电池进行一次“放电”,将剩余的电量放掉,然后再进行一次“充电”。这其实是一种对电池保护机制,以及对Raid卡可用性提供保障的机制。
默认情况下,当RAID卡的电池的电量低于某阈值时,RAID卡固件认为此时的电池是不可用的,为了保证数据的安全,会禁用RAID的“缓存”,这种默认的机制本来是合理的,但是当RAID的缓存被禁用之后,RAID的I/O能力会大幅度下降。一般情况下,这个充放电(放电->充电)的时间可能会持续几个小时,对于I/O密集型的应用来说,由此带来的性能下降有可能是致命的,可能会导致系统I/O延迟增大、队列堆积、拖慢甚至有可能拖垮整个系统。
有两种方法解决这个问题:
注:下文中的操作适用于基于LSI的MegaRAID卡的服务器。
法一:检查电池的状态,对电池的充放电进行撑握,也可有计划地安排手动充放电。
一般服务器的RAID卡电池充放电周期为90天(具体周期可以通过下文的命令进行查看确认),然后在快接近下次充电的时候,选择在业务低谷时间手动强制充放电;以此避免因RAID卡电池在未知时间做充放电操作带来的性能隐患。
查看电池充放电周期:
MegaCli -AdpBbuCmd -getBbuProperties -aALL|egrep 'Period|Next'
输出样例:
Auto Learn Period: 27 Days
Next Learn time: Tue Sep 18 05:52:27 2018
手动强制充放电:
MegaCli -AdpBbuCmd -BbuLearn –a0
法二:改变RAID卡策略,使其在充放电时,不禁用Raid卡缓存。
这样做电池在自动充放电的时候,就不会关闭写缓存,I/O的性能不会下降;但是,假如在此时服务器断电,Raid卡缓存中的数据会来不及写进磁盘,从而造成数据的丢失;在RAID卡电池充放电的时候刚好遇到服务器断电的概率应该是很低的,但这确实是一个风险点,需要合理评估;对于DB类对数据安全性要求高的应用需要谨慎使用,对于I/O吞吐要求高但是对数据一致性要求不是非常苛刻的场景是非常建议做此调整的。
查看Raid卡当前的缓存策略:
MegaCli -LDGetProp -Cache -LAll -aAll
输出样例
Adapter 0-VD 0(target id: 0): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 1(target id: 1): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 2(target id: 2): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 3(target id: 3): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 4(target id: 4): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 5(target id: 5): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 6(target id: 6): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 7(target id: 7): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 8(target id: 8): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 9(target id: 9): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 10(target id: 10): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Exit Code: 0x00
注:因为此服务器上有11个VD,所以会显示11行,可以看到缓存策略是No Write Cache if Bad BBU,即在电池充放电时关闭缓存。
调整缓存策略,在充放电时不关闭写缓存:
MegaCli -LDSetProp CachedBadBBU -lall -a0
输出样例:
Set Write Cache OK if bad BBU on Adapter 0, VD 0 (target id: 0) success
Set Write Cache OK if bad BBU on Adapter 0, VD 1 (target id: 1) success
Set Write Cache OK if bad BBU on Adapter 0, VD 2 (target id: 2) success
Set Write Cache OK if bad BBU on Adapter 0, VD 3 (target id: 3) success
Set Write Cache OK if bad BBU on Adapter 0, VD 4 (target id: 4) success
Set Write Cache OK if bad BBU on Adapter 0, VD 5 (target id: 5) success
Set Write Cache OK if bad BBU on Adapter 0, VD 6 (target id: 6) success
Set Write Cache OK if bad BBU on Adapter 0, VD 7 (target id: 7) success
Set Write Cache OK if bad BBU on Adapter 0, VD 8 (target id: 8) success
Set Write Cache OK if bad BBU on Adapter 0, VD 9 (target id: 9) success
Set Write Cache OK if bad BBU on Adapter 0, VD 10 (target id: 10) success
确认操作结果,检查Raid卡当前的缓存策略:
Adapter 0-VD 0(target id: 0): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 1(target id: 1): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 2(target id: 2): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 3(target id: 3): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 4(target id: 4): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 5(target id: 5): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 6(target id: 6): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 7(target id: 7): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 8(target id: 8): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 9(target id: 9): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 10(target id: 10): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Exit Code: 0x00
注:
缓存策略已经变为Write Cache OK if bad BBU,即在电池充放电时不关闭缓存。
上述调整中是调整了所有的VD,根据不同的场景,我们可以指定VD进行操作。
如果需要将Cache策略修改为原始值,可以通过下面的命令进行操作:
MegaCli -LDSetProp NoCachedBadBBU -lall -a0
操作实例
我们ELK的机器都是2块磁盘RAID1,作为系统盘;10块数据盘做单盘RAID0。我们现在要把系统盘的CachedBadBBU关闭(前面把所有VD的缓存策略都调整为了CachedBadBBU),以保证数据安全性。
# 调整系统盘所在的VD0的缓存策略为NoCachedBadBBU
[root@BJSH-ELK-137-114.meitu-inc.com ~]# MegaCli -LDSetProp NoCachedBadBBU -l0 -a0
Set No Write Cache if bad BBU on Adapter 0, VD 0 (target id: 0) success
Exit Code: 0x00
[root@BJSH-ELK-137-114.meitu-inc.com ~]#
# 查看系统盘所在的VD0
[root@BJSH-ELK-137-114.meitu-inc.com ~]# MegaCli -LDGetProp -Cache -L0 -aAll
Adapter 0-VD 0(target id: 0): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Exit Code: 0x00
# 查看所有VD
[root@BJSH-ELK-137-114.meitu-inc.com ~]# MegaCli -LDGetProp -Cache -LAll -aAll
Adapter 0-VD 0(target id: 0): Cache Policy:WriteBack, ReadAhead, Cached, No Write Cache if bad BBU
Adapter 0-VD 1(target id: 1): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 2(target id: 2): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 3(target id: 3): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 4(target id: 4): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 5(target id: 5): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 6(target id: 6): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 7(target id: 7): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 8(target id: 8): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 9(target id: 9): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Adapter 0-VD 10(target id: 10): Cache Policy:WriteBack, ReadAhead, Cached, Write Cache OK if bad BBU
Exit Code: 0x00
[root@BJSH-ELK-137-114.meitu-inc.com ~]#
I/O 调度算法
目前默认为cfq,算法比较中庸,固态硬盘可调整为noop;针对机械磁盘,不同的应用可以对比测试下deadline等其他调度算法的性能表现。对于数据库等应用,避免饿死的情况,建议调整为deadline。
文件系统journal
文件系统日志,默认开启,可以暂时不做调整。
磁盘挂载参数
为提升磁盘I/O性能,可以考虑将磁盘挂载参数调整为async,noatime,data=writeback,barrier=0,nobh。
参数含义:
async:采用异步I/O
noatime:访问文件不修改文件元信息,提高文件系统读写性能
data=writeback: 启用回写模式,不记录data journal,提高文件系统写入性能
barrier=0:关闭barrier
nobh:关闭buffer_head,防止内核打断大块数据的IO操作
操作实例
调整ELK服务器data目录的此案挂载参数
[root@ELK-133-10 ~]# mount|grep data
/dev/sdc1 on /data1 type xfs (rw,noatime,nodiratime)
/dev/sdd1 on /data2 type xfs (rw,noatime,nodiratime)
/dev/sde1 on /data3 type xfs (rw,noatime,nodiratime)
/dev/sdf1 on /data4 type xfs (rw,noatime,nodiratime)
/dev/sdg1 on /data5 type xfs (rw,noatime,nodiratime)
/dev/sdb1 on /data6 type xfs (rw,noatime,nodiratime,barrier=1)
[root@ELK-133-10 ~]#
# 生成remount命令
[root@ELK-133-10 ~]# mount|grep data|awk '{print "mount "$1" "$3" -o remount,rw,noatime,data=writeback,barrier=0,nobh"}'
mount /dev/sdc1 /data1 -o remount,rw,noatime,data=writeback,barrier=0,nobh
mount /dev/sdd1 /data2 -o remount,rw,noatime,data=writeback,barrier=0,nobh
mount /dev/sde1 /data3 -o remount,rw,noatime,data=writeback,barrier=0,nobh
mount /dev/sdf1 /data4 -o remount,rw,noatime,data=writeback,barrier=0,nobh
mount /dev/sdg1 /data5 -o remount,rw,noatime,data=writeback,barrier=0,nobh
mount /dev/sdb1 /data6 -o remount,rw,noatime,data=writeback,barrier=0,nobh
[root@ELK-133-10 ~]#
# 执行remount命令
[root@ELK-133-10 ~]# mount|grep data|awk '{print "mount "$1" "$3" -o remount,rw,noatime,data=writeback,barrier=0,nobh"}'|bash
[root@ELK-133-10 ~]#
# 确认remount结果
[root@ELK-133-10 ~]# mount|grep data
/dev/sdc1 on /data1 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
/dev/sdd1 on /data2 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
/dev/sde1 on /data3 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
/dev/sdf1 on /data4 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
/dev/sdg1 on /data5 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
/dev/sdb1 on /data6 type xfs (rw,noatime,data=writeback,barrier=0,nobh)
[root@ELK-133-10 ~]#
性能数据对比
(待补充)
磁盘IO性能优化-实践的更多相关文章
- etcd 性能优化实践
https://mp.weixin.qq.com/s/lD2b-DZyvRJ3qWqmlvHpxg 从零开始入门 K8s | etcd 性能优化实践 原创 陈星宇 阿里巴巴云原生 2019-12-16 ...
- 第17 章 : 深入理解 etcd:etcd 性能优化实践
深入理解 etcd:etcd 性能优化实践 本文将主要分享以下五方面的内容: etcd 前节课程回顾复习: 理解 etcd 性能: etcd 性能优化 -server 端: etcd 性能优化 -cl ...
- 性能调优之访问日志IO性能优化
性能调优之访问日志IO性能优化 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821 ...
- Linux如何查看与测试磁盘IO性能
1. 查看磁盘 IO 性能 1.1 top 命令 top 命令通过查看 CPU 的 wa% 值来判断当前磁盘 IO 性能,如果这个数值过大,很可能是磁盘 IO 太高了,当然也可能是其他原因,例如网络 ...
- 让Elasticsearch飞起来!——性能优化实践干货
原文:让Elasticsearch飞起来!--性能优化实践干货 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog ...
- 018 磁盘 IO 性能监控/压测工具(sar、iotop、fio、iostat)
1 sar 命令查看当前磁盘 IO 读写 sar(System Activity Reporter 系统活动情况报告)是 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告 ...
- 直播推流端弱网优化策略 | 直播 SDK 性能优化实践
弱网优化的场景 网络直播行业经过一年多的快速发展,衍生出了各种各样的玩法.最早的网络直播是主播坐在 PC 前,安装好专业的直播设备(如摄像头和麦克风),然后才能开始直播.后来随着手机性能的提升和直播技 ...
- 手游录屏直播技术详解 | 直播 SDK 性能优化实践
在上期<直播推流端弱网优化策略 >中,我们介绍了直播推流端是如何优化的.本期,将介绍手游直播中录屏的实现方式. 直播经过一年左右的快速发展,衍生出越来越丰富的业务形式,也覆盖越来越广的应用 ...
- 磁盘IO性能监控(Linux 和 Windows)
磁盘IO性能监控(Linux 和 Windows) 作者:终南 <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...
随机推荐
- Found duplicate classes/resources
很可能是多个三方依赖重复了,依赖个插件,这个插件能查找出依赖关系, duplicate-finder-maven-plugin 使用命令显示 mvn dependency:tree [INFO] \- ...
- 第一次试验报告&学习总结
打印输出所有的"水仙花数",所谓"水仙花数"是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个"水仙花数". 试验代码: p ...
- C# DataTable 增加行与列
亲测有用的方法 DataTable AllInfos = new DataTable();//生成一个表格 DataColumn typeColumn = new DataColumn();//建一个 ...
- 后盾网lavarel视频项目---2、phpstorm显示类中的方法快捷键
后盾网lavarel视频项目---2.phpstorm显示类中的方法快捷键 一.总结 一句话总结: ctrl + f12 1.npm安装js插件? npm install hdjs 2.phpstor ...
- 在docker容器中调用docker命令
宿主容器均为CentOS7.6.1810 docker run -it --rm \ -v /usr/bin/docker:/usr/bin/docker \ -v /var/run/docker.s ...
- MYSQL启用数据库错误:ERROR 2002 (HY000)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) MYSQL服务 ...
- 动画演示 Delphi 2007 IDE 功能[2] - 定义变量
https://my.oschina.net/hermer/blog/319152 动画剧本: 第一个变量: 输入: var; 然后执行 Ctrl+J ... 回车 第二个变量: 执行 Ctrl+J; ...
- centos7:Kafka集群安装
解压文件到安装目录 tar -zxvf kafka_2.10-0.10.2.1.tgz 1.进入目录 cd kafka_2.10-0.10.2.1 mkdir logs cd config cp se ...
- Android:adb shell 命令详解
安卓系统是基于Linux系统开发,也就支持常见的Linux的命令,这些命令都保存在手机“/system/bin”的目录下,通过adb shell 便可以调用这些命令. 进入“/system/bin”该 ...
- Java多线程学习——sleep和yield
Thread.sleep(); Thread.yield(); 相同点: 让线程暂停运行. 都是静态方法,可以直接调用. 不同点: sleep让线程从运行状态进入阻塞状态,但是不放开手中的资源. yi ...