操作环境
Centos 7
Mysql 5.7
sysbench 0.4.12
操作说明
LVM2中snapshot使用的COW方式进行快照,在写数据的时候会对写性能有影响。
通过sysbench对mysql进行性能测试,了解性能影响的程度。
操作步骤
1.通过sysbench测试未启动snapshot时mysql的性能
准备mysql数据
[root@centos7-mysql ~]# sysbench --test=oltp --oltp-table-size=10000000 --db-driver=mysql --mysql-socket=/usr/local/mysql/mysql.sock --mysql-user=root --mysql-password='123456' --mysql-db=sbtest prepare
开始测试
[root@centos7-mysql ~]# sysbench --test=oltp --oltp-table-size=10000000 --oltp-read-only=off --init-rng=on --num-threads=16 --max-requests=0 --oltp-dist-type=uniform --max-time=600 --mysql-user=root --mysql-password='123456' --db-driver=mysql --mysql-socket=/usr/local/mysql/mysql.sock run > result-nosnap.log
2.给lv创建快照
[root@centos7-mysql ~]# lvcreate -s -n snapdatalv-1 -L 10G /dev/vgtest/datalv
[root@centos7-mysql ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <13.91g
swap centos -wi-ao---- 1.60g
datalv vgtest owi-aos--- 20.00g
snapdatalv-1 vgtest swi-a-s--- 10.00g datalv 0.01
[root@centos7-mysql ~]# sysbench --test=oltp --oltp-table-size=10000000 --oltp-read-only=off --init-rng=on --num-threads=16 --max-requests=0 --oltp-dist-type=uniform --max-time=600 --mysql-user=root --mysql-password='hgctech' --db-driver=mysql --mysql-socket=/usr/local/mysql/mysql.sock run > result-withsnap.log
4.对比两者的性能
未启动snapshot时,mysql性能
[root@centos7-mysql ~]# cat result-nosnap.log
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.
Doing OLTP test.
Running mixed OLTP test
Using Uniform distribution
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.
OLTP test statistics:
queries performed:
read: 674240
write: 240800
other: 96320
total: 1011360
transactions: 48160 (80.23 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 915040 (1524.42 per sec.)
other operations: 96320 (160.47 per sec.)
Test execution summary:
total time: 600.2526s
total number of events: 48160
total time taken by event execution: 9602.5361
per-request statistics:
min: 4.80ms
avg: 199.39ms
max: 3170.00ms
approx. 95 percentile: 384.15ms
Threads fairness:
events (avg/stddev): 3010.0000/22.35
execution time (avg/stddev): 600.1585/0.06
启动snapshot时,mysql的性能
[root@centos7-mysql ~]# cat result-withsnap.log
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.
Doing OLTP test.
Running mixed OLTP test
Using Uniform distribution
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.
OLTP test statistics:
queries performed:
read: 294938
write: 105335
other: 42134
total: 442407
transactions: 21067 (35.09 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 400273 (666.70 per sec.)
other operations: 42134 (70.18 per sec.)
Test execution summary:
total time: 600.3788s
total number of events: 21067
total time taken by event execution: 9602.5025
per-request statistics:
min: 5.17ms
avg: 455.81ms
max: 5379.73ms
approx. 95 percentile: 1065.17ms
Threads fairness:
events (avg/stddev): 1316.6875/25.72
execution time (avg/stddev): 600.1564/0.10
通过上图对比,未启动snapshot时的性能远远高于启动snapshot时的性能。