Mysql数据库服务器性能配置优化一 -- 硬件配置及优化,RAID优化

1、硬件信息:

 

DELL R710,E5620 @2.40GHz(4 core) * 2 ,24G RAM,Intel X25-M G2 34nm SSD * 4 (RAID 10)

 

数据库对服务器的CPU,内存,IO都有比较高的要求。CPU就不用多说了,主流的4核×2。内存如果有条件尽量大一些,现在也不太贵(有测试表明在某种应用情况下,innodb_buffer_pool_size设置到一定大小时,无论是FusionIO,普通SSD还是SAS硬盘的TPS都差不多了,后面的文章会提到)。

 

IO方面,最开始我是准备用传统的4块SAS 15K 146G做RAID10的,常见一个选择,比较保险,性能也还不错。后来看了不少SSD相关的文章(感谢cyberty的帮助:)),性能诱惑确实太大了。于是开始选择SSD,FusionIO性能非常强悍,不过价格也强悍,160GB的大概4800美刀。Intel 有企业版的X25-E,采用SLC结构,还是偏贵了一些,性价比不高,另外容量较小。最后选择了Intel X25-M 80G,4块做RAID10 能使用160G。X25-M的MTBF(Mean Time Between Failure,即平均无故障时间)为120万小时,不过MLC颗粒的擦写理论寿命1万次,为了保险起见还是用了RAID10,另外会部署一台使用SAS硬盘的slave DB同步数据做备份,就算用SSD这台出问题也可以很快恢复服务。

 

2、SSD需要的特殊处理:

 

如果是单块SSD,由于SSD的特殊性,即在写数据之前需要把用到的区域擦除然后再进行写操作。如果文件系统写操作能对齐SSD的BLOCK SIZE,性能会更好。可以使用fdisk对扇区做一些处理。


由于我这里做了RAID 10,所以情况有一点不一样,是否同样需要fdisk还没有完全搞清楚,目前是没有修改。有研究的哥们儿还请不吝赐教。

 

在分区时留下了一些连续空间留给SSD(10%到20%),Intel控制器会自动将这些空间用作空余空间替换使用,以保持性能延长寿命。

 

参考文章:http://memory.zol.com.cn/171/1718110.html

 

如果做了RAID,使用128KB的strip size(这里我没有具体测试,有机会还需要专门测试一下)

 

 

3、硬件RAID优化:

 

这批DELL机器需要在Linux下查看RAID的状态。

 

查了一些资料,说需要安装DELL的open manage。

 

可以用类似的方法安装open manage:http:///share/detail/14502805

 

debian下的安装:http:///blog/?p=210

 

不过这些感觉都还是相对麻烦了。

 

这里有一个简单的方法,首先用lspci命令查看一下,如果有类似

 

03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 1078 (rev 04)

 

这样的就可以用。

 

下载MegaCli

http://www.lsi.com/DistributionSystem/AssetDocument/8.00.23_Linux_CLI.zip

 

解压之后会得到一个rpm包,MegaCli-8.00.23-1.i386.rpm

 

使用alien命令转换成tgz

 

alien --to-tgz MegaCli-8.00.23-1.i386.rpm

 

解压tgz,就直接可以使用MegaCli64了(有可能需要chmod +x MegaCli64)。

 

有可能需要: apt-get install libsysfs-dev

 

./opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL

 

One thing I spent a while figuring out was how to get the rebuild progress, so here's how:

 

# ./opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -PhysDrv \[32:1\] -aALL

 

 

参考文章:http://hwraid.le-vert.net/wiki/LSIMegaRAIDSAS

 

http://pookey.co.uk/wordpress/archives/46-dell-perc-6i-and-raid-monitoring

 

There's also a really useful cheat sheet for common tasks

 

 

以下是这台DB服务器用MegaCli64打出来的RAID信息:

 

db2:~# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aAll          

                                    

 

Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0
Size                : 136.125 GB
State               : Optimal
Stripe Size         : 64 KB
Number Of Drives    : 1
Span Depth          : 1
Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disk's Default
Encryption Type     : None
 
Virtual Drive: 1 (Target Id: 1)
Name                :
RAID Level          : Primary-1, Secondary-3, RAID Level Qualifier-0
Size                : 148.0 GB
State               : Optimal
Stripe Size         : 64 KB
Number Of Drives per span:2
Span Depth          : 2
Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disk's Default
Encryption Type     : None

 

设置读取缓存:

 

/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached -LAll -aAll 

 

恢复:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Direct -LAll -aAll 

 



设置前的TPMC(XFS,cfq)

21219.334 TpmC

设置后

23286.666 TpmC(9.7% up)

设置前的TPMC(XFS,deadline)

22424.334 TpmC

设置后

23761.000 TpmC (5.9% up)


 

都有不少提高,cfq下有9.7%的提升,deadline也有5.9%。

 

设置硬盘缓存(Disk Cache):

 

打开:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp EnDskCache -LAll -aAll  

关闭:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp DisDskCache -LAll -aAll

 

默认是Disk's Default,在这里估计已经是打开的了,测试一下。

 



设置前的TPMC(XFS,deadline)

23761.000 TpmC

enable

23997.334 TpmC

disable

22853.000 TpmC


设置读取策略(ReadAhead):

 

打开:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp ADRA -LALL -aALL

 


设置前的TPMC(XFS,deadline),ReadAheadNone

23997.000 TpmC

ReadAdaptive

24753.334 TpmC

 

 

设置写缓存(write cache),一定要注意,写缓存可能导致数据丢失,有电池包(BBU)的情况下可以开启:

 

打开:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WB -LALL -aALL

关闭:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WT -LALL -aALL

 

关闭WB如果电池包有问题:/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp NoCachedBadBBU -LALL -aALL

查看电池状态:

/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -a0 | grep -e '^isSOHGood' -e '^Charger Status' -e '^Remaining Capacity'

 



WriteBack

24753.334 TpmC

WriteThrough

20377.334 TpmC



 

WriteThrough会降低不少的性能。

 

注意:根据http://www.mysqlperformanceblog.com/2009/03/02/ssd-xfs-lvm-fsync-write-cache-barrier-and-lost-transactions/ 的测试,打开write cache,有可能在极端情况下(突然断电)丢失少量数据,对于数据很敏感的DB,要小心使用。

 

 

看一下最后优化过后的RAID信息:

 

db2:~# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aAll      
                                     
 
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0
Size                : 136.125 GB
State               : Optimal
Stripe Size         : 64 KB
Number Of Drives    : 1
Span Depth          : 1
Default Cache Policy: WriteBack, ReadAdaptive, Cached, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Cached, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Enabled
Encryption Type     : None
 
 
Virtual Drive: 1 (Target Id: 1)
Name                :
RAID Level          : Primary-1, Secondary-3, RAID Level Qualifier-0
Size                : 148.0 GB
State               : Optimal
Stripe Size         : 64 KB
Number Of Drives per span:2
Span Depth          : 2
Default Cache Policy: WriteBack, ReadAdaptive, Cached, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Cached, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Enabled
Encryption Type     : None

相比默认的配置,TpmC(xfs,deadline)从22424提升到24753,提高了10.38%。

 


转载于:https://blog.51cto.com/jimmyzha/437274