一、磁盘测试
首先利用FIO对我本机的磁盘性能做了下简单的测试,测试过程及结果如下:
[root@localhost3 storage]# /usr/local/bin/fio -filename=/storage/test_randread -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=2G -numjobs=30 -runtime=120 -group_reporting -name=mytest
mytest: (g=0): rw=randrw, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 30 threads
mytest: Laying out IO file(s) (1 file(s) / 2048MB)
Jobs: 30 (f=30): [mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm] [100.0% done] [77046KB/36086KB/0KB /s] [4815/2255/0 iops] [eta 00m:00s]
mytest: (groupid=0, jobs=30): err= 0: pid=6739: Sun May 20 03:43:17 2018
read : io=13007MB, bw=110989KB/s, iops=6936, runt=120002msec
clat (usec): min=0, max=213826, avg=3933.92, stdev=4254.00
lat (usec): min=0, max=213826, avg=3934.57, stdev=4254.30
clat percentiles (usec):
| 1.00th=[ 604], 5.00th=[ 980], 10.00th=[ 1304], 20.00th=[ 1784],
| 30.00th=[ 2160], 40.00th=[ 2544], 50.00th=[ 2928], 60.00th=[ 3376],
| 70.00th=[ 3984], 80.00th=[ 5152], 90.00th=[ 7776], 95.00th=[10944],
| 99.00th=[15552], 99.50th=[17792], 99.90th=[54528], 99.95th=[74240],
| 99.99th=[148480]
bw (KB /s): min= 1145, max= 5461, per=3.34%, avg=3703.50, stdev=550.43
write: io=5616.6MB, bw=47927KB/s, iops=2995, runt=120002msec
clat (usec): min=0, max=128681, avg=886.32, stdev=1759.41
lat (usec): min=0, max=128683, avg=887.74, stdev=1760.38
clat percentiles (usec):
| 1.00th=[ 58], 5.00th=[ 73], 10.00th=[ 76], 20.00th=[ 89],
| 30.00th=[ 131], 40.00th=[ 189], 50.00th=[ 318], 60.00th=[ 502],
| 70.00th=[ 788], 80.00th=[ 1272], 90.00th=[ 2288], 95.00th=[ 3440],
| 99.00th=[ 7264], 99.50th=[ 9920], 99.90th=[17536], 99.95th=[22656],
| 99.99th=[46848]
bw (KB /s): min= 475, max= 2682, per=3.34%, avg=1599.02, stdev=311.41
lat (usec) : 2=0.04%, 4=0.01%, 10=0.01%, 20=0.02%, 50=0.19%
lat (usec) : 100=7.21%, 250=6.27%, 500=4.69%, 750=3.92%, 1000=4.04%
lat (msec) : 2=18.10%, 4=33.47%, 10=17.54%, 20=4.27%, 50=0.15%
lat (msec) : 100=0.07%, 250=0.01%
cpu : usr=0.31%, sys=1.88%, ctx=1152784, majf=0, minf=6
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued : total=r=832428/w=359459/d=0, short=r=0/w=0/d=0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: io=13007MB, aggrb=110988KB/s, minb=110988KB/s, maxb=110988KB/s, mint=120002msec, maxt=120002msec
WRITE: io=5616.6MB, aggrb=47927KB/s, minb=47927KB/s, maxb=47927KB/s, mint=120002msec, maxt=120002msec
Disk stats (read/write):
dm-0: ios=831233/358981, merge=0/0, ticks=2685947/797509, in_queue=3483558, util=100.00%, aggrios=832476/359519, aggrmerge=0/1, aggrticks=2690623/727120, aggrin_queue=3415102, aggrutil=100.00%
sda: ios=832476/359519, merge=0/1, ticks=2690623/727120, in_queue=3415102, util=100.00%
从上面结果看到,我本机笔记本上的虚拟机,读IOPS可达到6936,写的IOPS却只有2995。
二、OLTP测试
对OLTP测试我设了一下几组对照测试
对照组 | 参数 |
---|---|
对照组1 | Innodb_flush_log_at_trx_commit=0 |
sync_binlog=1 | |
对照组2 | Innodb_flush_log_at_trx_commit=1 |
sync_binlog=1 | |
对照组3 | Innodb_flush_log_at_trx_commit=2 |
sync_binlog=1 | |
对照组4 | Innodb_flush_log_at_trx_commit=0 |
sync_binlog=100 | |
对照组5 | Innodb_flush_log_at_trx_commit=1 |
sync_binlog=100 | |
对照组6 | Innodb_flush_log_at_trx_commit=2 |
sync_binlog=100 | |
对照组7 | Innodb_flush_log_at_trx_commit=0 |
sync_binlog=0 | |
对照组8 | Innodb_flush_log_at_trx_commit=1 |
sync_binlog=0 | |
对照组9 | Innodb_flush_log_at_trx_commit=2 |
sync_binlog=0 |
因为对照组较多,所以我们写个shell脚本来跑sysbench的压测,压测逻辑大概是这样
冷备数据库
释放OS CACHE
根据参数选择不同的配置文件启动数据库
开始OLTP压测
#!/bin/bash
#author:xucl
#date:20180520
function CopyData()
{
cp -r /vagrant/mysql3306 /storage/
chown -R mysql.mysql /storage/mysql3306
}
function StartMySQL()
{
/usr/local/mysql/bin/mysqld --defaults-file=/storage/mysql3306/my.cnf --user=mysql &
}
function StopMySQL()
{
/usr/local/mysql/bin/mysqladmin -uroot -pxcl582388 -S /tmp/mysql3306.sock shutdown
}
function StartTest()
{
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc \
--mysql-db=sbtest --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare --db-driver=mysql
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc \
--mysql-db=sbtest --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on run --db-driver=mysql > /tmp/${log_name}.log
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc \
--mysql-db=sbtest --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on cleanup --db-driver=mysql
}
##01
log_name="01"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=0;set global sync_binlog=1;";
StartTest
StopMySQL
##11
log_name="11"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=1;set global sync_binlog=1;";
StartTest
StopMySQL
##21
log_name="21"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=2;set global sync_binlog=1;";
StartTest
StopMySQL
##0 100
log_name="0100"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=0;set global sync_binlog=100;";
StartTest
StopMySQL
##1 100
log_name="1100"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=1;set global sync_binlog=100;";
StartTest
StopMySQL
##2 100
log_name="2100"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=2;set global sync_binlog=100;";
StartTest
StopMySQL
##0 0
log_name="00"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=0;set global sync_binlog=0;";
StartTest
StopMySQL
##1 0
log_name="10"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=1;set global sync_binlog=0;";
StartTest
StopMySQL
##2 0
log_name="20"
rm -rf /storage/mysql3306
CopyData
sync
echo 3 > /proc/sys/vm/drop_caches
StartMySQL
sleep 3
mysql -uroot -pxcl582388 -S /tmp/mysql3306.sock -e "set global innodb_flush_log_at_trx_commit=2;set global sync_binlog=0;";
StartTest
StopMySQL
结果解读
参数 | TPS |
---|---|
Innodb_flush_log_at_trx_commit=0 | 120.49 |
sync_binlog=1 | |
Innodb_flush_log_at_trx_commit=1 | 111.73 |
sync_binlog=1 | |
Innodb_flush_log_at_trx_commit=2 | 124.25 |
sync_binlog=1 | |
Innodb_flush_log_at_trx_commit=0 | 125.83 |
sync_binlog=100 | |
Innodb_flush_log_at_trx_commit=1 | 122.68 |
sync_binlog=100 | |
Innodb_flush_log_at_trx_commit=2 | 214.80 |
sync_binlog=100 | |
Innodb_flush_log_at_trx_commit=0 | 138.05 |
sync_binlog=0 | |
Innodb_flush_log_at_trx_commit=1 | 99.35 |
sync_binlog=0 | |
Innodb_flush_log_at_trx_commit=2 | 113.07 |
sync_binlog=0 |
以上是本人在笔记本虚拟机上的做的一些实验,实验结果可能不准确,仅供学习参考用。