首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

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

2012-09-28 
Mysql数据库服务器性能配置优化一 -- 硬件配置及优化,RAID优化? ??近期公司采购了新的DB服务器,结合以前的

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

? ??近期公司采购了新的DB服务器,结合以前的一些经验再研究了一下Mysql的各种优化点,从硬件选择到Raid,从更换InnoDB引擎再到my.cnf。大部分的优化点国内没有什么文章提及(www.mysqlperformanceblog.com?里很多有价值的信息,对于喜欢研究Mysql的朋友再强烈推荐一把)。这里把一些关键点和优化过程写下来,有需要的朋友可以参考一下。(转贴请注明出处)

?

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这台出问题也可以很快恢复服务。

?

Intel?X25-M相关文章:

?

http://bbs.ttpod.com/viewthread.php?tid=44144

?

http://diybbs.zol.com.cn/1/16_107911.html

?

http://www.beareyes.com.cn/2/lib/200908/31/20090831254_0.htm

?

?

2、SSD需要的特殊处理:

?

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

?

参考文章:http://www.nuclex.org/blog/personal/80-aligning-an-ssd-on-linux

?

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

?

在分区时留下了一些连续空间?不使用(10%到20%),Intel控制器会自动将这些空间用作空余空间替换使用,以保持性能延长寿命。综合考虑了一下,我剩余了15G左右。

?

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

?

如果做了RAID,可以考虑使用128KB的strip size(由于没找到远程改stripe size的方法,没有具体测试,有机会还需要专门测试一下)

?

参考文章:http://www.tomshardware.com/forum/251218-32-intel-gen2-raid-stripe-size

?

?

3、DELL服务器查看RAID信息,硬件RAID优化:

?

需要在Linux下查看RAID的状态,DELL的RAID查看工具不支持Debian。

?

查了一些资料,说可以安装DELL的open manage。

?

http://apps.hi.baidu.com/share/detail/14502805

?

debian下的安装:http://www.tbaumi.de/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

?

?

下面开始RAID的优化,对具体的设置项不清楚的朋友可以单独Google一下。

?

TPMC数据是通过TPCC工具测试出来的。TPCC是perconatools的一部分,大牛Vadim Tkachenko?所出,他在很多文章中使用该工具来进行对比测试。在接下来第二篇优化文章中会具体提到这个工具。

?

工具地址:https://launchpad.net/perconatools

?

设置读取缓存:

?

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

?

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

?

设置前Direct(XFS,cfq)

21219.334 TpmC

设置后Cached

23286.666 TpmC(9.7% up)

设置前Direct(XFS,deadline)

22424.334 TpmC

设置后Cached

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,在这里估计已经是打开的了,测试一下。

?

设置前(XFS,deadline)

23761.000 TpmC

enable

23997.334 TpmC

disable

22853.000 TpmC

?

?

设置读取策略(ReadAhead):

?

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

?

设置前ReadAheadNone(XFS,deadline)

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

?

RAID配置如果选择不合适,性能差别很大,比如WriteBack还是WriteThrough。需要根据自己的使用情况做选择并测试。

?

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

http://blog.csdn.net/zjmzs/article/details/6046075

?

热点排行