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@elk-137-114.thatsit.cc ~]# 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@elk-137-114.thatsit.cc ~]#
# 查看系統盤所在的VD0
[root@elk-137-114.thatsit.cc ~]# 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@elk-137-114.thatsit.cc ~]# 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@elk-137-114.thatsit.cc ~]#
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.thatsit.cc ~]# 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.thatsit.cc ~]#
# 生成remount命令
[root@elk-133-10.thatsit.cc ~]# 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.thatsit.cc ~]#
# 執行remount命令
[root@elk-133-10.thatsit.cc ~]# mount|grep data|awk '{print "mount "$1" "$3" -o remount,rw,noatime,data=writeback,barrier=0,nobh"}'|bash
[root@elk-133-10.thatsit.cc ~]#
# 確認remount結果
[root@elk-133-10.thatsit.cc ~]# 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.thatsit.cc ~]#
性能數據對比
(待補充)