sysbench是一个模块化、跨平台、多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用。sysbench主要用于以下性能测试:

  • 文件I/O性能
  • 调度
  • 内存分配和传输
  • POSIX线程
  • 数据库

 

安装

下载地址:https://github.com/akopytov/sysbench/releases

1.安装插件

yum install libtool -y

2.安装

./configure  --prefix=/usr/local/sysbench-0.4.12 --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make 
make install
cp  -r sysbench/tests  /usr/local/sysbench-0.4.12
ln -s /usr/local/sysbench-0.4.12/bin/sysbench /usr/local/sysbench-0.4.12/sysbench

修改环境变量,在环境变量中加入

export LD_LIBRARY_PATH=/usr/local/mysql/lib

注意:如果安装目录中没有configure那么需要执行以下操作:

chmod +x autogen.sh

./autogen.sh

如果想要让 sysbench 支持 oracle /pgsql 的话,就需要在编译的时候加上参数
--with-oracle

或者

--with-pgsql

一般语法 

prepare:用于文件IO和数据库OLTP测试的数据准备阶段。

run:性能测试阶段

cleanup:移除测试过程中产生的数据

help:显示帮助信息,获取--test帮助可以使用--test=name --help

通用命令选项

这部分命令参数的通用的,不管--test测试什么内容都可以使用这些通用的命令。可以执行sysbench --help了解各参数的具体解释

General options:
  --num-threads=N             number of threads to use [1]
  --max-requests=N            limit for total number of requests [10000]
  --max-time=N                limit for total execution time in seconds [0]
  --forced-shutdown=STRING    amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE    size of stack per thread [32K]
  --init-rng=[on|off]         initialize random number generator [off]
  --seed-rng=N                seed for random number generator, ignored when 0 [0]
  --tx-rate=N                 target transaction rate (tps) [0]
  --tx-jitter=N               target transaction variation, in microseconds [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. []
  --test=STRING               test to run
  --debug=[on|off]            print more debugging info [off]
  --validate=[on|off]         perform validation checks where possible [off]
  --help=[on|off]             print help and exit
  --version=[on|off]          print version and exit

Log options:
  --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [4]

  --percentile=N      percentile rank of query response times to count [95]

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
  oltp - OLTP test

Commands: prepare run cleanup help version

See 'sysbench --test=<name> help' for a list of options for each test.

主要的参数有

--num-threads、

--max-requests、

--test

以下几个参数也经常会使用:

--max-time 最大的测试时长

--debug(开启debug可以显示更详细的每个线程的执行情况)

CPU测试

对CPU的性能测试通常有:1. 通过算质数;2计算圆周率等;sysbench使用的就是通过质数相加的测试。对CPU测试直接运行run即可

./sysbench --num-threads=12 --max-requests=10000 --debug=on --test=cpu --cpu-max-prime=20000 run

上面的测试是:12个线程执行1万条请求,每个请求执行质数相加到20000

sysbench 压力测试

thread测试

测试线程调度的性能,用于高负载下的线程性能测试。

  --thread-yields=N      每个请求执行“lock/yield/unlock”循环的次数,默认1000

  --thread-locks=N       每个线程的互斥锁,默认8个

./sysbench --num-threads=12 --max-requests=10000  --test=threads --thread-yields=100 --thread-locks=2 run

sysbench 压力测试

memory测试

内存分配测试,主要是针对不同的块大小进行内存的连续读写或者随机读写测试。

memory options:

--memory-block-size=SIZE    size of memory block for test [1K]
  --memory-total-size=SIZE    total size of data to transfer [100G]
  --memory-scope=STRING       memory access scope {global,local} [global]
  --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
  --memory-oper=STRING        type of memory operations {read, write, none} [write]
  --memory-access-mode=STRING memory access mode {seq,rnd} [seq]

1.8k顺序分配

./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
sysbench 压力测试
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 12
Random number generator seed is 0 and will be ignored


Doing memory operations speed test
Memory block size: 8K

Memory transfer size: 102400M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 13107200 (993893.95 ops/sec)

102400.00 MB transferred (7764.80 MB/sec)


General statistics:
    total time:                          13.1877s
    total number of events:              13107200
    total time taken by event execution: 91.9173
    response time:
         min:                                  0.00ms
         avg:                                  0.01ms
         max:                                  0.93ms
         approx.  95 percentile:               0.02ms

Threads fairness:
    events (avg/stddev):           1092266.6667/4629.30
    execution time (avg/stddev):   7.6598/0.02
View Code

报告:时间13S,7.7G/S

2.8k随机分配

./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
sysbench 压力测试
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 12
Random number generator seed is 0 and will be ignored


Doing memory operations speed test
Memory block size: 8K

Memory transfer size: 102400M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 13107200 (1036066.63 ops/sec)

102400.00 MB transferred (8094.27 MB/sec)


General statistics:
    total time:                          12.6509s
    total number of events:              13107200
    total time taken by event execution: 71.5377
    response time:
         min:                                  0.00ms
         avg:                                  0.01ms
         max:                                  0.90ms
         approx.  95 percentile:               0.02ms

Threads fairness:
    events (avg/stddev):           1092266.6667/19850.15
    execution time (avg/stddev):   5.9615/0.02
View Code

相关文章: