sysbench的安装详解

时间:2023-03-09 07:11:09
sysbench的安装详解

sysbench是一个压力测试工具、可以用它来测试cpu、mem、disk、thread、mysql、postgr、oracle;然而作为一个mysql dba 我当然是用它来压测mysql啦!

一、从哪里可以下载到sysbench

  sysbench的源码可以在github上面下载的到,sysbench的主页

https://github.com/akopytov/sysbench

二、sysbench的一些安装依赖

yum -y install  make automake libtool pkgconfig libaio-devel vim-common

  在我的机器上已经安装上了mysql相关的所有包,如果你机器上还没有安装过这些,那你还要安装上mysql的开发包,由于系统自带mariadb

  这个mysql分支,所以在安装mysql-devel时应该是安装mariadb-devel

三、安装sysbench

  1  进入到sysbench源码目录

/home/jianglexing/Desktop/sysbench-master

  2  执行autogen.sh用它来生成configure这个文件

./autogen.sh

  3  执行configure && make && make install 来完成sysbench的安装

./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make
make install

  我这里之所以要这样写是因为我的mysql安装在/usr/local/;而不是默认的rpm的安装位置

四、测试是否安装成功

[root@workstudio bin]# /usr/local/sysbench/bin/sysbench --version
sysbench 1.1.

  到目前为止sysbench的安装就算是完成了!

五、sysbench的帮助内容如下

 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]
--warmup-time=N execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled [0]
--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]
--thread-init-timeout=N wait time in seconds for worker threads to initialize [30]
--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
--luajit-cmd=STRING perform LuaJIT control command. This option is equivalent to 'luajit -j'. See LuaJIT documentation for more information
--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)
--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对数据库进行压力测试的过程

  1  prepare 阶段 这个阶段是用来做准备的、比较说建立好测试用的表、并向表中填充数据。

  2  run       阶段 这个阶段是才是去跑压力测试的SQL

  3  cleanup 阶段 这个阶段是去清除数据的、也就是prepare阶段初始化好的表要都drop掉

七、sysbench 中的测试类型大致可以分成内置的,lua脚本自定义的测试:

  1、内置:

    fileio 、cpu 、memory 、threads 、 mutex

  2、lua脚本自定义型:

    sysbench 自身内涵了一些测试脚本放在了安装目录下的:

[jianglexing@cstudio sysbench]$ ll share/sysbench
总用量
-rwxr-xr-x. root root 10月 : bulk_insert.lua
-rw-r--r--. root root 10月 : oltp_common.lua
-rwxr-xr-x. root root 10月 : oltp_delete.lua
-rwxr-xr-x. root root 10月 : oltp_insert.lua
-rwxr-xr-x. root root 10月 : oltp_point_select.lua
-rwxr-xr-x. root root 10月 : oltp_read_only.lua
-rwxr-xr-x. root root 10月 : oltp_read_write.lua
-rwxr-xr-x. root root 10月 : oltp_update_index.lua
-rwxr-xr-x. root root 10月 : oltp_update_non_index.lua
-rwxr-xr-x. root root 10月 : oltp_write_only.lua
-rwxr-xr-x. root root 10月 : select_random_points.lua
-rwxr-xr-x. root root 10月 : select_random_ranges.lua
drwxr-xr-x. root root 10月 : tests

八、通过sysbench自带的lua脚本对mysql进行测试:

  1、第一步 prepare

sysbench --mysql-host=localhost --mysql-port= --mysql-user=sbtest \
--mysql-password= --mysql-db=tempdb oltp_insert prepare

  2、第二步 run

sysbench --mysql-host=localhost --mysql-port= --mysql-user=sbtest     --mysql-password= --mysql-db=tempdb oltp_insert run
sysbench 1.1. (using bundled LuaJIT 2.1.-beta3) Running the test with following options:
Number of threads:
Initializing random number generator from current time Initializing worker threads... Threads started! SQL statistics:
queries performed:
read:
write:
other:
total:
transactions: (2254.37 per sec.)
queries: (2254.37 per sec.)
ignored errors: (0.00 per sec.)
reconnects: (0.00 per sec.) Throughput:
events/s (eps): 2254.3691
time elapsed: .0006s
total number of events: Latency (ms):
min: 0.31
avg: 0.44
max: 10.47
95th percentile: 0.67
sum: 9918.59 Threads fairness:
events (avg/stddev): 22545.0000/0.00
execution time (avg/stddev): 9.9186/0.00

  3、第三步 cleanup

sysbench --mysql-host=localhost --mysql-port= --mysql-user=sbtest     --mysql-password= --mysql-db=tempdb oltp_insert cleanup
sysbench 1.1. (using bundled LuaJIT 2.1.-beta3) Dropping table 'sbtest1'...

----

sysbench的安装详解