磁盘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 ...
随机推荐
- hdu5988(费用流,对数相乘做加法)
题意:一个网络流的图,有n个点,从1~n,然后m条边,每个点有两个值,一个是人的数量si一个是饭的数量bi.每条m边有容量ci,还有走上去可能踩断电线的概率pi(第一次踩上去没有事,之后都要p概率). ...
- sh脚本获取当前目录
#!/bin/bashcurDir=$(pwd)echo "cur dir is:$curDir"
- Spring中基于java的配置
Spring中为了减少XML配置,可以声明一个配置类类对bean进行配置,主要用到两个注解@Configuration和@bean 例子: 首先,XML中进行少量的配置来启动java配置: <? ...
- .Net Core-3.0-新闻:宣告推出.NET Core 3.0 Preview 7
ylbtech-.Net Core-3.0-新闻:宣告推出.NET Core 3.0 Preview 7 1.返回顶部 1. 今天,我们宣布推出.NET Core 3.0 Preview 7.我们已 ...
- C# 开发COM组件供c++使用
C# 开发COM组件供c++使用 Microsoft在解决和以往的COM和SDK开发技术之间的互操作性(Interoperability)方面做了很多的工作,其中包括COM和.NET对象之间的相互调用 ...
- C# AxWindowsMediaPlayer
AxWMPLib.AxWindowsMediaPlayer winPlayer = new AxWMPLib.AxWindowsMediaPlayer(); winPlayer.Dock = Dock ...
- kafka 消费者拉取消息
本文只跟踪消费者拉取消息的流程.对于 java 客户端, kafka 的生产者和消费者复用同一个网络 io 类 NetworkClient. 入口在 KafkaConsumer#pollOnce 中, ...
- 2018.03.27 pandas duplicated 和 replace 使用
#.duplicated / .replace import numpy as np import pandas as pd s = pd.Series([1,1,1,1,1,2,3,3,3,4,4, ...
- Delphi的类与继承
既然已经做出了com程序用delphi来开发的决定,那当然就要对delphi进行一些深入的了解.有人说delphi是一个用控件堆砌起来的工具,和vb没什么两样:也有人说dephi实际上是面向过程的,他 ...
- MyEclipse中的查找快捷键
MyEclipse中的查找快捷键 1.Ctrl+H:可以搜索文件,Java类名.方法名.包名等等. 例如:在MyEclipse中打开Search弹出框,或者在菜单中打开Search弹出框, 定位到 F ...