sysbench压力测试工具使用详细说明
2019年12月04日
阅读数:147
这篇文章主要向大家介绍sysbench压力测试工具使用详细说明,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。
#1、安装
#yum安装
#yum install -y sysbench
#编译安装
#下载安装源码 https://github.com/akopytov/sysbench
#bzr branch lp:sysbench //下载到当前目录,文件名为: sysbench
yum gcc automake m4 libtool bzr
./autogen.sh
./configure --prefix=/usr/local/sysbench --with-mysql-libs=/usr/local/mysql/lib/ --with-mysql-includes=/usr/local/mysql/include/
make
make install
ln -s /usr/local/sysbench/bin/sysbench /usr/bin/sysbench
#要添加环境变量,否则会报错
/etc/profile 添加环境变量
export LD_LIBRARY_PATH=/usr/local/mysql/lib/
source /etc/profile
step5:
sysbench --help验证是否成功
2、测试前准备
create database sbtest;
flush privivleges
或mysqladmin create sbtest
3、混合读写
#读写测试仍是用oltp.lua,只需把--oltp-read-only等于off。
sysbench --mysql-host=172.16.*.* --mysql-port=33306 --mysql-user=root --mysql-password=123123 \
--mysql-db=sbtest --test=/usr/local/sysbench/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=172.16.*.* --mysql-port=33306 --mysql-user=root --mysql-password=123123 \
--mysql-db=sbtest --test=/usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/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 >> /usr/local/sysbench/log/sysbench_oltpX_8_20140921.log
#测试过程
tail -10f /usr/local/sysbench/log/sysbench_oltpX_8_20140921.log
[ 60s ] thds: 2 tps: 37.70 qps: 752.16 (r/w/o: 526.37/38.80/186.99) lat (ms,99%): 1050.76 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 2 tps: 48.50 qps: 970.49 (r/w/o: 679.89/50.00/240.60) lat (ms,99%): 520.62 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 2 tps: 40.40 qps: 806.67 (r/w/o: 564.25/41.30/201.12) lat (ms,99%): 1129.24 err/s: 0.00 reconn/s: 0.00
#测试结果
SQL statistics:
queries performed:
read: 2358118
write: 173960
other: 836662
total: 3368740
transactions: 168437 (46.79 per sec.)
queries: 3368740 (935.70 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 3600.2268s
total number of events: 168437
Latency (ms):
min: 1.65
avg: 42.74
max: 2440.89
99th percentile: 773.68
sum: 7199694.56
Threads fairness:
events (avg/stddev): 84218.5000/448.50
execution time (avg/stddev): 3599.8473/0.00
#咱们通常关注的用于绘图的指标主要有:
response time avg: 平均响应时间。(后面的95%的大小能够经过--percentile=98的方式去更改)
transactions: 精确的说是这一项后面的TPS 。但若是使用了-oltp-skip-trx=on,这项事务数恒为0,须要用total number of events 去除以总时间,获得tps(其实还能够分为读tps和写tps)
read/write requests: 用它除以总时间,获得吞吐量QPS
固然还有一些系统层面的cpu,io,mem相关指标
sysbench还能够对文件系统IO测试,CPU性能测试,以及内存分配与传输速度测试,这里就不介绍了。
总结起来sysbench的缺点就是,模拟的表结构太简单,不像tpcc-mysql那样完整的事务系统。但对于性能压测对比仍是颇有用的,由于sysbench使用的环境参数限制是同样的。
#TPS了(Transcantion Per Second,既每秒事务数)
一样是衡量数据库的重要指标.不过MySQL不是每一个存储引擎都支持事务.因此就拿InnoDB来讲好了.TPS主要涉及提交和回滚
#QPS(Query Per Second,既每秒请求、查询次数)
#IOPS:(Input/Output operations Per Second,既每秒处理I/O的请求次数)
#四只更新测试
若是基准测试的时候,你只想比较两个项目的update(或insert)效率,那能够不使用oltp脚本,而直接改用update_index.lua:
./bin/sysbench --test=./share/tests/db/update_index.lua \
--mysql-host=10.0.201.36 --mysql-port=8066 --mysql-user=ecuser --mysql-password=ecuser \
--mysql-db=dbtest1a --oltp-tables-count=10 --oltp-table-size=500000 \
--report-interval=10 --rand-init=on --max-requests=0 \
--oltp-read-only=off --max-time=120 --num-threads=128 \
[ prepare | run | cleanup ]
5、须要说明的选项:
mysql-db=dbtest1a:测试使用的目标数据库,这个库名要事先建立
--oltp-tables-count=10:产生表的数量
--oltp-table-size=10000000:每一个表产生的记录行数
--oltp-dist-type=uniform:指定随机取样类型,可选值有 uniform(均匀分布), Gaussian(高斯分布), special(空间分布)。默认是special
--oltp-read-only=off:表示不止产生只读SQL,也就是使用oltp.lua时会采用读写混合模式。默认 off,若是设置为on,则不会产生update,delete,insert的sql。
--oltp-test-mode=nontrx:执行模式,这里是非事务式的。可选值有simple,complex,nontrx。默认是complex
simple:简单查询,SELECT c FROM sbtest WHERE id=N
complex (advanced transactional):事务模式在开始和结束事务以前加上begin和commit, 一个事务里能够有多个语句,如点查询、范围查询、排序查询、更新、删除、插入等,而且为了避免破坏测试表的数据,该模式下一条记录删除后会在同一个事务里添加一条相同的记录。
nontrx (non-transactional):与simple类似,可是能够进行update/insert等操做,因此若是作连续的对比压测,你可能须要从新cleanup,prepare。
--oltp-skip-trx=[on|off]:省略begin/commit语句。默认是off
--rand-init=on:是否随机初始化数据,若是不随机化那么初始好的数据每行内容除了主键不一样外其余彻底相同
--num-threads=12: 并发线程数,能够理解为模拟的客户端并发链接数
--report-interval=10:表示每10s输出一次测试进度报告
--max-requests=0:压力测试产生请求的总数,若是如下面的max-time来记,这个值设为0
--max-time=120:压力测试的持续时间,这里是2分钟。
6、其它测试(本测试只是基准测试,不表明实际生产环境下的性能指标)
1 测试CPU的性能
sysbench --test=cpu --help
#cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,本身能够根据机器cpu的性能来适当调整数值。
sysbench --test=cpu --cpu-max-prime=20000 run
sysbench --num-threads=2 --max-requests=100000 --max-time=120 --test=cpu run
#结论:一样的请求数,一样的执行时间,进程数越大,执行时间越短
2 测试IO,
#指定了最大建立16个线程,建立的文件总大小为3G,文件读写模式为随机读。
sysbench --test=fileio --num-threads=4 --file-total-size=30G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=4 --file-total-size=30G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=4 --file-total-size=30G --file-test-mode=rndrw cleanup
3 测试内存
测试顺序读:
sysbench --test=memory --memory-total-size=10G --memory-oper=read --memory-access-mode=seq run
测试随机读:
sysbench --test=memory --memory-total-size=10G --memory-oper=read --memory-access-mode=rnd run
#结论:顺序读比随机读快不少
测试顺序写:
sysbench --test=memory --memory-total-size=10G --memory-oper=write --memory-access-mode=seq run
测试随机写
sysbench --test=memory --memory-total-size=10G --memory-oper=write --memory-access-mode=rnd run
#结论:随机写比有序写速度快,缘由为:内存排序须要时间c
#本次测试整个过程是在内存中传输 4G 的数据量,每一个 block 大小为 8K。
sysbench --test=memory --memory-block-size=8K --memory-total-size=2G --num-threads=16 run
线程(threads)测试
sysbench --test=threads --num-threads=64 run
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
#若是须要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,而且还可能须要测试不一样的线程和不一样的文件块下磁盘的性能表现,这时,可使用以下脚本达到测试目的。
7、安装错误
#error
#####
[root@localhost sysbench-1.0]# /usr/local/sysbench/bin/sysbench -version
/usr/local/sysbench/bin/sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
./tests: error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or directory
出现这类错误表示,系统不知道xxx.so放在哪一个目录下,这时候就要在/etc/ld.so.conf中加入xxx.so所在的目录。
通常而言,有不少的so会存放在/usr/local/lib这个目录底下,去这个目录底下找,果真发现本身所须要的.so文件。
因此,在/etc/ld.so.conf中加入/usr/local/lib这一行,保存以后,再运行:/sbin/ldconfig –v更新一下配置便可。