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 ~]#
性能数据对比
(待补充)
转载于:https://www.cnblogs.com/thatsit/p/ci-panio-xing-neng-you-huashi-jian.html