为什么要压力测试
采购新设备,评估新设备性能
开发新项目,评估数据库容量
新系统上线前,预估/模拟数据库负载
更换数据库版本,评估性能变化
关注指标
CPU
%wait,%user,%sys
内存
只内存读写,不产生swap
IO
IOPS、 iowait、 svctm、 %util
数据库
TPS/TpmC、吞吏量(QPS)、响应时长、 InnoDB指标
影响因素
硬件
– CPU(省电模式、超线程、多核)
– 内存(镜像模式、 xen内核限制可用总内存大小)
– 阵列卡(BBU、 CACHE、条带、读写策略、 FW)
– 硬盘(SSD/SAS)
系统
– 内核参数(tcp相关)
– 文件系统
– IO调度器
MySQL
– TRANSACTION ISOLATION LEVEL
– Buffer pool
– Concurrency thread
– Redo log
– Binlog sync
– innodb_flush_log_at_trx_commit
----
可靠性测试
模拟意外事件
– 断电(硬件冷重启)
– RESET(硬件热重启)
– 阵列卡掉线
– 磁盘掉线
– REBOOT(系统重启)
– 正常关闭服务(kill -TERM)
– 异常关闭服务(kill -9)
– 磁盘空间满
– 删除文件
– 破坏性修改已打开文件
– …
长期极限高压
– 持续数小时、数天、数周运行高负载计算、 IO任务
– 考验服务器在高压下的性能波劢情况
– 考验硬件设备在高压下的稳定性表现
模拟恶劣环境
– 供电不稳
– 通风冷却不好
– 湿气大、灰尘多
注意事项
只在本地加压
压测数据量小
压测时间过短
压测模式太少
压力负载过大或过小
每轮测试完毕要净化环境
测试工具 sysbench,tpcc-mysql
#unzip sysbench-0.5.zip
yum install automake libaio libaio-devel libtool -y-----LOAD,CPU,QPS,TPS,CONNECT,IO,NET/IN,NET/OUT
[root@mysql5635 proc]#more loadavg
0.00 0.01 0.05 1/221 8408[root@mysql5635 proc]#cat /proc/cpuinfo
tar xvfz sysbench-0.4.12-1.1.tgz
./autogen.sh
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make &&make install--cpu性能测试
./sysbench --help
./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@mysql5635 sysbench]#ls /usr/local/mysql/lib/|grep libmysqlclient.so.18
libmysqlclient.so.18libmysqlclient.so.18.1.0[root@mysql5635 sysbench]#echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
[root@mysql5635 sysbench]#ldconfig
drivers/mysql/libsbmysql.a -L/usr/local/mysql/lib -lmysqlclient_r scripting/lua/src/liblua.a -ldl -lrt -laio -lm -pthread/usr/bin/ld: cannot find -lmysqlclient_r
fileio - 文件 I/O测试
cpu - CPU系能测试
memory - 内存功能速度测试
threads - 线程子系统系能测试
mutex - 互斥性能测试
运行
– sysbench --test=[mode] [other_options] prepare
– sysbench --test=[mode] [other_options] run
– sysbench --test=[mode] [other_options] cleanup
通用基准
– 最大请求数:5,000,000
– 并发线程数:8 ~ 512
基准 – OLTP
– mode=complex
– engine=innodb
– oltp-table-size=100,000,000
sysbench支持以下几种测试模式:
1、CPU运算性能
2、磁盘IO性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
测试用例
初始化测试库环境(总共10个测试表,每个表 100000 条记录,填充随机生成的数据)
./sysbench --mysql-host=127.0.0.1 --mysql-port=3317 --mysql-user=tpcc --mysql-password=*** \--test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare
--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行。
在上面初始化数据参数的基础上,再增加一些参数,即可开始进行测试了:
./sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc \--mysql-password=**** --test=tests/db/oltp.lua --oltp_tables_count=10\--oltp-table-size=10000000 --num-threads=8 --oltp-read-only=off \--report-interval=10 --rand-type=uniform --max-time=3600\--max-requests=0 --percentile=99 run >> /tmp/2017080101.log
--num-threads=8 表示发起 8个并发连接
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
即:模拟 对10个表并发OLTP测试,每个表1000万行记录,持续压测时间为 1小时。
真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。
--oltp测试
--创建db
mysql> create database sbtest;
/data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000\--mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8prepare/data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000\--mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 run >> /home/mysql/sysbench_20180806.log
测试结果解读如下:
[root@mysql5635 sysbench]#cat /home/mysql/sysbench.log
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads:8Report intermediate results every10second(s)
Random number generator seed is0and will be ignored
Threads started!
-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计
[ 10s] threads:8, tps: 194.81, reads/s: 2737.20, writes/s: 780.05, response time: 206.36ms (99%)
[ 20s] threads:8, tps: 213.60, reads/s: 2991.02, writes/s: 856.40, response time: 176.82ms (99%)
[ 30s] threads:8, tps: 233.90, reads/s: 3274.61, writes/s: 934.00, response time: 111.08ms (99%)
[ 40s] threads:8, tps: 224.40, reads/s: 3141.18, writes/s: 899.19, response time: 87.77ms (99%)
[ 50s] threads:8, tps: 229.70, reads/s: 3215.82, writes/s: 916.01, response time: 138.09ms (99%)
[ 60s] threads:8, tps: 238.98, reads/s: 3346.58, writes/s: 957.24, response time: 70.88ms (99%)
[ 70s] threads:8, tps: 225.50, reads/s: 3156.95, writes/s: 901.19, response time: 97.78ms (99%)
[ 80s] threads:8, tps: 232.51, reads/s: 3255.48, writes/s: 931.25, response time: 105.51ms (99%)
[ 90s] threads:8, tps: 230.79,