1.github地址:https://github.com/akopytov/sysbench
2.在线安装
依赖安装:
代码语言:javascript复制yum -y install make automake libtool pkgconfig libaio-devel
# For MySQL support, replace with mysql-devel on RHEL/CentOS 5
yum -y install mariadb-devel openssl-devel
# For PostgreSQL support
yum -y install postgresql-devel
sysbench安装(centos系统)
代码语言:javascript复制curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
3.用法
代码语言:javascript复制 sysbench [options]... [testname] [command]
参数解释:
testname是一个内置测试(例如文件、内存、cpu等)的可选名称,或者一个捆绑的Lua脚本的名称(例如oltp_read_only),或者一个自定义Lua脚本的路径。如果在命令行上没有指定测试名(因此也没有命令,因为在这种情况下,它将被解析为testname),或者测试名是一个短横线(“-”),那么sysbench期望Lua脚本在其标准输入上执行。
command是一个可选参数,将由sysbench传递给内置的测试或脚本,由testname指定。命令定义了测试必须执行的动作。
可用命令的列表取决于特定的测试。有些测试还实现了它们自己的自定义命令。有4个选项:
prepare ---准备数据
run ---测试
cleanup ---清理数据
help ---帮助
常见可选项列表如下:
Option | Description | Default value |
---|---|---|
--threads | The total number of worker threads to create | 1 |
--events | Limit for total number of requests. 0 (the default) means no limit | 0 |
--time | Limit for total execution time in seconds. 0 means no limit | 10 |
--warmup-time | Execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled. This is useful when you want to exclude the initial period of a benchmark run from statistics. In many benchmarks, the initial period is not representative because CPU/database/page and other caches need some time to warm up | 0 |
--rate | Average transactions rate. The number specifies how many events (transactions) per seconds should be executed by all threads on average. 0 (default) means unlimited rate, i.e. events are executed as fast as possible | 0 |
--thread-init-timeout | Wait time in seconds for worker threads to initialize | 30 |
--thread-stack-size | Size of stack for each thread | 32K |
--report-interval | Periodically report intermediate statistics with a specified interval in seconds. Note that statistics produced by this option is per-interval rather than cumulative. 0 disables intermediate reports | 0 |
--debug | Print more debug info | off |
--validate | Perform validation of test results where possible | off |
--help | Print help on general syntax or on a specified test, and exit | off |
--verbosity | Verbosity level (0 - only critical messages, 5 - debug) | 4 |
--percentile | sysbench measures execution times for all processed requests to display statistical information like minimal, average and maximum execution time. For most benchmarks it is also useful to know a request execution time value matching some percentile (e.g. 95% percentile means we should drop 5% of the most long requests and choose the maximal value from the remaining ones). This option allows to specify a percentile rank of query execution times to count | 95 |
--luajit-cmd | perform a LuaJIT control command. This option is equivalent to luajit -j. See LuaJIT documentation for more information |
请注意,所有大小选项的数值(如该表中的——thread-stack-size)都可以通过添加相应的后缀来指定
(K表示kilobytes, M表示megabytes, G表示gigabytes, T表示terabytes)。
随机数的选项:
Sysbench提供了许多算法来生成根据给定概率分布分布的随机数。下表列出了可用于控制这些算法的选项。
Option | Description | Default value |
---|---|---|
--rand-type | random numbers distribution {uniform, gaussian, special, pareto, zipfian} to use by default. Benchmark scripts may choose to use either the default distribution, or specify it explictly, i.e. override the default. | special |
--rand-seed | seed for random number generator. When 0, the current time is used as an RNG seed. | 0 |
--rand-spec-iter | number of iterations for the special distribution | 12 |
--rand-spec-pct | percentage of the entire range where 'special' values will fall in the special distribution | 1 |
--rand-spec-res | percentage of 'special' values to use for the special distribution | 75 |
--rand-pareto-h | shape parameter for the Pareto distribution | 0.2 |
--rand-zipfian-exp | shape parameter (theta) for the Zipfian distribution | 0.8 |
4. 实际测试案例
代码语言:javascript复制sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=dbtest oltp_insert prepare
代码语言:javascript复制sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root
--mysql-password=password --time=12000 --mysql-db=dbtest oltp_insert run > test1.txt &
ps:1.本文为sysbench 1.0.20版本,参数与老版本有区别;
2.其他操作系统的安装可参考文章开头地址。