一、概述

  sysbench是一个模块化的、跨渠道、多线程基准测验东西,首要用于评估测验各种不同系统参数下的数据库负载状况,它首要包含以下几种方式的测验:磁盘io功能、数据库功能、内存分配及传输速度等,具体的介绍见:gitee.com/cn-loongson…

  它首要包含以下几种方式的测验:

    1、cpu功能。

    2、磁盘io功能

    3、调度程序功能

    4、内存分配及传输速度

    5、POSIX线程功能

    6、数据库功能(OLTP基准测验)

  目前sysbench首要支撑 MySQL,pgsql,oracle 这3种数据库

二、装置

2.1、源码编译装置

  源码编译装置请参阅如下指令:

// 下载源码
git clone https://github.com/akopytov/sysbench.git

深化了解sysbench东西
  当前有0.4、0.5、1.0三个版别,咱们通过如下指令来切换到1.0版别:

git checkout 1.0

深化了解sysbench东西
  请履行如下指令来承认当前环境是否装置了依赖东西:

./autogen.sh

深化了解sysbench东西
  履行如下指令来进行配置编译选项:

./configure

深化了解sysbench东西
  编译源码请参阅如下指令:

make

深化了解sysbench东西
  按照请参阅如下指令:

sudo make install

  装置指令履行成果如下:

深化了解sysbench东西

2.2、指令行装置

  Ubuntu下履行如下指令进行装置:

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt -y install sysbench

  指令行装置履行成果如下:

深化了解sysbench东西

2.3、装置承认

  履行如下指令来承认sysbench是否装置成功:

sysbench --version
lyb@lyb:~/learn/sysbench$ 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
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.
lyb@lyb:~/learn/sysbench$

三、重要参数详解

3.1、查询支撑的参数

  履行如下指令来承认sysbench是否装置成功:

深化了解sysbench东西

3.2、重要参数说明

选项 默认值 描绘
–threads 创建1的作业线程总数 1
–events 恳求总数的约束。0(默认值)表明没有约束 0
–time 总履行时刻约束,以秒为单位。0表明不约束 10
–warmup-time 在启用计算信息运行实际基准测验之前,在禁用计算信息的状况下履行事情这么多秒。当您期望从计算数据中排除基准测验运行的初始阶段时,这十分有用。在许多基准测验中,初始时刻并不具有代表性,由于CPU/数据库/页面和其他缓存需求一些时刻来预热 0
–rate 这个数字指定了所有线程均匀每秒钟应该履行多少事情(事务)。0(默认)表明无限速率,即事情以尽或许快的速度履行 0
–thread-init-timeout 作业线程初始化的等待时刻,单位为秒 30
–thread-stack-size 每个线程的仓库大小 32k
–report-interval 以间隔时刻为秒定期上报中间计算信息。留意,此选项生成的计算信息是按间隔计算的,而不是累积的。0禁用中间陈述 0
–debugl 打印更多的调试信息 off
–validate 在或许的状况下对测验成果进行验证 off
–help 打印通用语法或指定测验的帮助并退出 off
–verbosity 具体等级(0 -只要关键音讯,5 -调试) 4
–percentile sysbench测量所有已处理恳求的履行时刻,以显现最小、均匀和最大履行时刻等计算信息。关于大多数基准测验,知道一个匹配某个百分比的恳求履行时刻值也是有用的(例如,95%百分比意味着咱们应该放弃最长恳求的5%,并从剩下的恳求中选择最大值)。此选项允许指定查询履行次数的百分位数用于计数 95
–luajit-cmd 履行一个LuaJIT控制指令。这个选项相当于luajit -j

四、实例

4.1、CPU功能测验

  运用如下指令进行CPU功能测验:

# 敞开两个线程,素数上限设置为20000
sysbench cpu --cpu-max-prime=20000 --threads=2 run

  履行CPU压测指令成果如下:

深化了解sysbench东西

4.2、内存功能测验

  运用如下指令进行内存压测:

sysbench memory --threads=14 --memory-block-size=16K --memory-total-size=100G --memory-access-mode=seq run

  履行内存压测指令成果如下:

深化了解sysbench东西

4.3、IO功能测验

  运用如下指令进行IO压测:

# 1、预备测验数据集,运用prepare指令
sysbench --test=fileio --file-total-size=2G prepare
# 2、混合随机读写测验
sysbench --test=fileio --file-test-mode=rndrw --file-total-size=2G --file-rw-ratio=2 run
# 3、清除测验数据集
sysbench --test=fileio --file-total-size=2G cleanup

  履行IO压测指令成果如下:

深化了解sysbench东西

4.4、POSIX线程功能测验

  运用如下指令进行POSIX线程功能压测:

sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run

  履行POSIX线程功能指令成果如下:

深化了解sysbench东西

4.5、多线程调度测验

  运用如下指令进行多线程调度测验:

sysbench mutex --threads=8 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run

  履行进行多线程调度测验指令成果如下:

深化了解sysbench东西