官网推荐用二进制的方式来安装
安装
安装命令如下
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
[root@localhost sysbench-master]# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packagecloud.io/install/repositories/akopytov/sysbench/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
akopytov_sysbench-source/signature | 833 B 00:00:00
从 https://packagecloud.io/akopytov/sysbench/gpgkey 检索密钥
导入 GPG key 0x04DCFD39:
用户ID : "https://packagecloud.io/akopytov/sysbench-prerelease (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
指纹 : 9789 8d69 f99e e5ca c462 a0f8 cf10 4890 04dc fd39
来自 : https://packagecloud.io/akopytov/sysbench/gpgkey
akopytov_sysbench-source/signature | 1.0 kB 00:00:01 !!!
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:02
(2/2): epel/x86_64/primary_db | 6.9 MB 00:00:13
akopytov_sysbench-source/primary | 2.0 kB 00:00:01
akopytov_sysbench-source 15/15
软件包 pygpgme-0.3-9.el7.x86_64 已安装并且是最新版本
无须任何处理
Installing yum-utils...
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理
Generating yum cache for akopytov_sysbench...
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
导入 GPG key 0x04DCFD39:
用户ID : "https://packagecloud.io/akopytov/sysbench-prerelease (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
指纹 : 9789 8d69 f99e e5ca c462 a0f8 cf10 4890 04dc fd39
来自 : https://packagecloud.io/akopytov/sysbench/gpgkey
Generating yum cache for akopytov_sysbench-source...
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
The repository is setup! You can now install packages.
[root@localhost sysbench-master]# sudo yum -y install sysbench
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 sysbench.x86_64.0.1.0.20-1.el7 将被 安装
--> 正在处理依赖关系 libpq.so.5()(64bit),它被软件包 sysbench-1.0.20-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postgresql-libs.x86_64.0.9.2.24-4.el7_8 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================
正在安装:
sysbench x86_64 1.0.20-1.el7 akopytov_sysbench 430 k
为依赖而安装:
postgresql-libs x86_64 9.2.24-4.el7_8 base 234 k
事务概要
============================================================================================================================================
安装 1 软件包 (+1 依赖软件包)
总下载量:664 k
安装大小:1.8 M
Downloading packages:
(1/2): postgresql-libs-9.2.24-4.el7_8.x86_64.rpm | 234 kB 00:00:00
(2/2): sysbench-1.0.20-1.el7.x86_64.rpm | 430 kB 00:00:02
--------------------------------------------------------------------------------------------------------------------------------------------
总计 271 kB/s | 664 kB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : postgresql-libs-9.2.24-4.el7_8.x86_64 1/2
正在安装 : sysbench-1.0.20-1.el7.x86_64 2/2
验证中 : sysbench-1.0.20-1.el7.x86_64 1/2
验证中 : postgresql-libs-9.2.24-4.el7_8.x86_64 2/2
已安装:
sysbench.x86_64 0:1.0.20-1.el7
作为依赖被安装:
postgresql-libs.x86_64 0:9.2.24-4.el7_8
完毕!
可参考网址:sysbench
安装后的版本
[root@localhost ~]# /usr/bin/sysbench --version
sysbench 1.0.20
查看帮助
[root@localhost ~]# /usr/bin/sysbench --help
Usage:
sysbench [options]... [testname] [command]
Commands implemented by most tests: prepare run cleanup help
General options:
--threads=N number of threads to use [1]
--events=N limit for total number of events [0]
--time=N limit for total execution time in seconds [10]
--forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]
--thread-stack-size=SIZE size of stack per thread [64K]
--rate=N average transactions rate. 0 for unlimited rate [0]
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
--report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
--debug[=on|off] print more debugging info [off]
--validate[=on|off] perform validation checks where possible [off]
--help[=on|off] print help and exit [off]
--version[=on|off] print version and exit [off]
--config-file=FILENAME File containing command line options
--tx-rate=N deprecated alias for --rate [0]
--max-requests=N deprecated alias for --events [0]
--max-time=N deprecated alias for --time [0]
--num-threads=N deprecated alias for --threads [1]
Pseudo-Random Numbers Generator options:
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
--rand-spec-iter=N number of iterations used for numbers generation [12]
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
--rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]
--rand-pareto-h=N parameter h for pareto distribution [0.2]
Log options:
--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
--percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]
--histogram[=on|off] print latency histogram in report [off]
General database options:
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers) [mysql]
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
--db-debug[=on|off] print database-specific debug information [off]
Compiled-in database drivers:
mysql - MySQL driver
pgsql - PostgreSQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=[LIST,...] MySQL server port [3306]
--mysql-socket=[LIST,...] MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-ssl[=on|off] use SSL connections, if available in the client library [off]
--mysql-ssl-cipher=STRING use specific cipher for SSL connections []
--mysql-compression[=on|off] use compression, if available in the client library [off]
--mysql-debug[=on|off] trace all client library calls [off]
--mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]
--mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]
pgsql options:
--pgsql-host=STRING PostgreSQL server host [localhost]
--pgsql-port=N PostgreSQL server port [5432]
--pgsql-user=STRING PostgreSQL user [sbtest]
--pgsql-password=STRING PostgreSQL password []
--pgsql-db=STRING PostgreSQL database name [sbtest]
Compiled-in tests:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
See 'sysbench <testname> help' for a list of options for each test
使用举例
/usr/bin/sysbench --mysql-table-engine=innodb --mysql-db=test --oltp-table-size=100000 --db-driver=mysql --threads=16 --mysq1-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=abc.123
在正式的使用之前我们要找到自带的lua脚本,后面执行测试命令可以用这些模板
如这里首先
准备数据
[root@localhost ~]# sysbench /usr/share/sysbench/oltp_read_write.lua --tables=5 --table_size=10000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password=abc.123 --mysql-host=localhost --mysql-port=33891 --mysql-db=test prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 10000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 10000 records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 10000 records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 10000 records into 'sbtest5'
Creating a secondary index on 'sbtest5'...
[root@localhost ~]#
这里可以看到我创建了5张表,每张表插入了10000万条数据
Inserting 10000 records into ‘sbtest5’
查看我们生成的结果
对以上命令的解释
#/usr/share/sysbench/oltp_read_write.lua :上面查询到的sysbench自带读写脚本的路径
#–tables:指定生成表的数量,此处设置了5张表,表明生成5张测试表,读者可根据实际需要,调整此值。
#–table_size:指定生成表中生成的数据量,上述例子,表明每张表生成10000条测试数据,实际可以根据需要调整引值,比如调整为:1000000,即代表生成一百万条测试数据。
#–mysql-db: 连接的测试数据库名称,此处使用上面创建的数据库进行测试。
#–mysql-user: 连接的数据库的用户名
#–mysql-password: 连接的数据库的密码
#–mysql-port: 连接的数据库开发的端口
测试数据
[root@localhost ~]# sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password=abc.123 --mysql-host=localhost --mysql-port=33891 --mysql-db=test --tables=5 --table_size=10000 --threads=10 --time=30 --report-interval=3 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 10
Report intermediate results every 3 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 3s ] thds: 10 tps: 819.57 qps: 16431.40 (r/w/o: 11510.64/3278.28/1642.47) lat (ms,95%): 23.95 err/s: 0.00 reconn/s: 0.00
[ 6s ] thds: 10 tps: 859.63 qps: 17204.61 (r/w/o: 12041.16/3444.19/1719.26) lat (ms,95%): 21.11 err/s: 0.00 reconn/s: 0.00
[ 9s ] thds: 10 tps: 814.39 qps: 16280.42 (r/w/o: 11393.76/3257.88/1628.78) lat (ms,95%): 26.68 err/s: 0.00 reconn/s: 0.00
[ 12s ] thds: 10 tps: 725.56 qps: 14507.15 (r/w/o: 10154.47/2901.56/1451.11) lat (ms,95%): 30.26 err/s: 0.00 reconn/s: 0.00
[ 15s ] thds: 10 tps: 715.75 qps: 14336.39 (r/w/o: 10035.20/2869.68/1431.51) lat (ms,95%): 25.28 err/s: 0.00 reconn/s: 0.00
[ 18s ] thds: 10 tps: 745.62 qps: 14906.00 (r/w/o: 10435.97/2978.80/1491.23) lat (ms,95%): 23.52 err/s: 0.00 reconn/s: 0.00
[ 21s ] thds: 10 tps: 757.73 qps: 15160.59 (r/w/o: 10610.88/3034.25/1515.46) lat (ms,95%): 26.68 err/s: 0.00 reconn/s: 0.00
[ 24s ] thds: 10 tps: 808.61 qps: 16148.57 (r/w/o: 11303.23/3228.11/1617.22) lat (ms,95%): 20.74 err/s: 0.33 reconn/s: 0.00
[ 27s ] thds: 10 tps: 779.71 qps: 15619.91 (r/w/o: 10938.97/3120.85/1560.09) lat (ms,95%): 21.89 err/s: 0.33 reconn/s: 0.00
[ 30s ] thds: 10 tps: 860.68 qps: 17224.51 (r/w/o: 12053.12/3450.04/1721.35) lat (ms,95%): 20.00 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 331450
write: 94696
other: 47348
total: 473494
transactions: 23673 (788.15 per sec.)
queries: 473494 (15764.22 per sec.)
ignored errors: 2 (0.07 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 30.0344s
total number of events: 23673
Latency (ms):
min: 4.03
avg: 12.68
max: 268.02
95th percentile: 23.95
sum: 300153.50
Threads fairness:
events (avg/stddev): 2367.3000/13.09
execution time (avg/stddev): 30.0153/0.01
[root@localhost ~]#
这里我们准备了10个并发进程,执行时间为30s,每3s输出一次信息
其中,对于我们比较重要的信息包括:
queries:查询总数及qps
transactions:事务总数及tps
Latency-95th percentile:前95%的请求的响应时间
由此看,我们这台服务器配置还是可以的
清理数据
[root@localhost ~]# sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password=abc.123 --mysql-host=localhost --mysql-port=33891 --mysql-db=test --tables=5 --table_size=10000 cleanup
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
这样我们就学会了sysbench的简单使用了
参考
参考文档如下:
1 sysbench 安装使用
2 使用sysbench对mysql压力测试
3 sysbench测试mysql性能(TPS、QPS、IOPS)