RAID卡緩存策略調整
能夠將RAID卡緩存策略由No Write Cache if bad BBU
調整爲Write Cache OK if bad BBU
,即在電池充放電時不關閉緩存,以此保證I/O性能。可是此法存在數據丟失風險,須要合理評估再作調整。html
緣由詳解
服務器的Riad卡都帶有可充電電池,這塊可充電電池在不使用時也會有微弱的放電現象,當它的電量放電到低到必定程度時,Raid卡控制器就會對電池進行一次「放電」,將剩餘的電量放掉,而後再進行一次「充電」。這實際上是一種對電池保護機制,以及對Raid卡可用性提供保障的機制。
默認狀況下,當RAID卡的電池的電量低於某閾值時,RAID卡固件認爲此時的電池是不可用的,爲了保證數據的安全,會禁用RAID的「緩存」,這種默認的機制原本是合理的,可是當RAID的緩存被禁用以後,RAID的I/O能力會大幅度降低。通常狀況下,這個充放電(放電->充電)的時間可能會持續幾個小時,對於I/O密集型的應用來講,由此帶來的性能降低有多是致命的,可能會致使系統I/O延遲增大、隊列堆積、拖慢甚至有可能拖垮整個系統。算法
有兩種方法解決這個問題:數據庫
注:下文中的操做適用於基於LSI的MegaRAID卡的服務器。緩存
-
法一:檢查電池的狀態,對電池的充放電進行撐握,也可有計劃地安排手動充放電。安全
通常服務器的RAID卡電池充放電週期爲90天(具體週期能夠經過下文的命令進行查看確認),而後在快接近下次充電的時候,選擇在業務低谷時間手動強制充放電;以此避免因RAID卡電池在未知時間作充放電操做帶來的性能隱患。bash
查看電池充放電週期:服務器
MegaCli -AdpBbuCmd -getBbuProperties -aALL|egrep 'Period|Next'
輸出樣例:markdown
-
Auto Learn Period: 27 Days
-
Next Learn time: Tue Sep 18 05:52:27 2018
手動強制充放電:異步
MegaCli -AdpBbuCmd -BbuLearn –a0
-
法二:改變RAID卡策略,使其在充放電時,不由用Raid卡緩存。async
這樣作電池在自動充放電的時候,就不會關閉寫緩存,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 ~]#
性能數據對比
(待補充)