sysbench压测工具操作文档

sysbench压测工具操作文档

sysbench是一个基于 LuaJIT 的可编写脚本的多线程基准测试工具。它最常用于数据库基准测试,但也可用于创建不涉及数据库服务器的任意复杂工作负载

一、安装sysbench

1.1、借助包管理器安装

  • Debian/Ubuntu
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
apt -y install sysbench
  • RHEL/CentOS
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
yum -y install sysbench
  • Fedora
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash	
dnf -y install sysbench
  • Arch Linux
pacman -Suy sysbench

1.2、源码编译安装

以CentOS系统为例

yum install gcc gcc-c++ autoconf automake make libtool mysql-devel git mysql
git clone https://github.com/akopytov/sysbench.git
##从Git中下载Sysbench
cd sysbench
##打开sysbench目录
git checkout 1.0.18
##切换到sysbench 1.0.18版本
./autogen.sh
##运行autogen.sh
./configure --prefix=/usr --mandir=/usr/share/man
make
##编译
make install

使用说明

帮助文档

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];创建测试线程的数目。默认为1
  --events=N                      limit for total number of events [0];请求的最大数目,0代表不限制
  --time=N                        limit for total execution time in seconds [10];最大执行时间,单位是s。默认是10s
  --forced-shutdown=STRING        number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off];过max-time强制中断。默认是off
  --thread-stack-size=SIZE        size of stack per thread [64K];每个线程的堆栈大小。默认是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];是否显示更多的调试信息。默认是off
  --validate[=on|off]             perform validation checks where possible [off];在可能情况下执行验证检查。默认是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];默认情况下使用的随机数分布 {uniform, gaussian, special, pareto, zipfian}
  --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];随机数生成器的种子。为 0 时,当前时间用作 RNG 种子
  --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

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]

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.

一般用法

sysbench 的一般命令行语法是

sysbench [options]... [testname] [command] 
  • options:部分包括测试需要的各种选项,有全局的也有每个测试模式自由的选项
  • testname:指定测试类型,基本类型有fileio,cpu,memory,threads,mutex,oltp(或者指定lua脚本)
  • command:控制命令
  • prepare:为需要它们的测试执行准备操作,例如在磁盘上为测试创建必要的文件fileio,或为数据库基准填充测试数据库
  • run:运行用testname参数指定的实际测试
  • cleanup:清除准备阶段生成的测试数据
  • help:显示使用testname参数指定的测试的使用信息

mysql压测示例

#准备数据
sysbench --db-driver=mysql --mysql-host=XXX --mysql-port=XXX --mysql-user=XXX --mysql-password=XXX --mysql-db=sbtest --table_size=25000 --tables=100 --events=0 --time=300  --threads=XXX oltp_read_write prepare

#运行workload
sysbench --db-driver=mysql --mysql-host=XXX --mysql-port=XXX --mysql-user=XXX --mysql-password=XXX --mysql-db=sbtest --table_size=25000 --tables=100 --events=0 --time=300   --threads=XXX --percentile=95 --report-interval=1 oltp_read_write run

#清理数据
sysbench --db-driver=mysql --mysql-host=XXX --mysql-port=XXX --mysql-user=XXX --mysql-password=XXX --mysql-db=sbtest --table_size=25000 --tables=100 --events=0 --time=300   --threads=XXX --percentile=95  oltp_read_write cleanup

CPU压测示例

sysbench cpu --cpu-max-prime=XXX --threads=XXX run

内存压测示例

sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --num-threads=XXX run

磁盘IO压测示例

#准备数据
sysbench --test=fileio --file-total-size=2G prepare

#运行
sysbench --test=fileio --file-total-size=2G run

#清理数据
sysbench --test=fileio --file-total-size=2G cleanup
posted @ 2023-03-24 13:35  大胡萝卜没有须  阅读(261)  评论(0编辑  收藏  举报