sysbench安装使用,结果信息分析

【1】下载安装 sysbench

GITHub: https://github.com/akopytov/sysbench

【1.1】yum安装 sysbench

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

核验,sysbench --version  ,sysbench --help

  

默认位置在 /usr/sysbench

【1.2】编译安装

下载解压

wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip"
unzip sysbench-1.0.zip

安装

(1)基本安装

yum -y install make automake libtool pkgconfig libaio-devel
cd sysbench-1.0
./autogen.sh

(2)检查mysql环境

rpm -qa |grep -i mysql 
rpm -ql mysql-community-libs
rpm -ql mysql-community-devel

 (3)没有Mysql包的话要安装,如果(2)中有的话,请忽略

https://centos.pkgs.org/7/mysql-8.0-x86_64/mysql-community-devel-8.0.22-1.el7.x86_64.rpm.html

Download latest mysql80-community-release-el7 rpm from
http://repo.mysql.com/

# wget http://repo.mysql.com/mysql80-community-release-el7.rpm
Install mysql80-community-release rpm:
# rpm -Uvh mysql80-community-release*rpm
Install mysql-community-devel rpm package:
# yum --enablerepo=mysql80-community install mysql-community-devel -y

(4)安装

#结合mysql用的话要这样  
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib ,这个路径可以从上面的rpm -ql mysql_comunity-libs 之类的拿到 make make install
说明:
--prefix=/usr/sysbench/                    :指定sysbench的安装目录。
--with-mysql-includes=/usr/include/mysql/  :指定安装mysql时候的includes目录。
--with-mysql-libs=/usr/lib/mysql/          :指定装mysql时候的lib目录。
--with-mysql                               :sysbench默认支持mysql,如果需要测试oracle或者pgsql则需要制定–with-oracle或者–with-pgsql。

(5)核验:

  

添加到环境变量:

echo "export PATH=$PATH:/usr/local/sysbench/bin" >>/etc/profile

source /etc/profile

注意:如果要测试哪个盘,就要切换目录到哪个盘,然后构造测试数据,见【6】

【1.3】安装 sysbench-tpcc

官方主页:https://github.com/Percona-Lab/sysbench-tpcc

Percona安装源(yum源)
[root@zhumh ~]# wget https://www.percona.com/redir/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
[root@zhumh ~]# yum -y install percona-release-0.1-6.noarch.rpm
[root@zhumh ~]# yum -y install sysbench
[root@zhumh ~]# yum -y install sysbench-tpcc

【1.4】结合mysql安装,最佳实践

centos 7.6
git clone https://github.com/akopytov/sysbench.git
cd sysbench

使用mysql-community.repo 
yum install m4  autoconf  automake libtool mysql-devel

找到和/usr/lib64/mysql/libmysqlclientx  所在的目录
/usr/include/mysql和/usr/lib64/mysql


rpm -qa  |grep -i mysql    
rpm -ql mysql-community-libs
rpm -ql mysql-community-devel


./autogen.sh
./configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql --prefix=/data/sysbench 
make && make install


测试数据
./bin/sysbench   /data/sysbench/share/sysbench/oltp_insert.lua  --tables=10 --mysql-user=root --mysql-password=bfgame20     --mysql-db=mytest  
--mysql-socket=/data/mysql/mysql.sock  --threads=20 --events=500000000  --time=0  run 

--mysql-host    IP
--mysql-port    端口号
--mysql-db  希望链接的数据库
--mysql-user    用户名
--mysql-password    密码
--table_size    每张表初始化的数据数量
--tables    初始化表的数量
--threads   启动的线程
--time  运行时间设为0表示不限制时间
--report-interval   运行期间日志,单位为秒
--events    最大请求数量,定义数量后可以不需要--time选项
 

【2】帮助文档 sysbench --help

[root@DB1 ~]# sysbench fileio help  
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

fileio options:
  --file-num=N                  number of files to create [128]
  --file-block-size=N           block size to use in all IO operations [16384]
  --file-total-size=SIZE        total size of files to create [2G]
  --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
  --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
  --file-async-backlog=N        number of asynchronous operatons to queue per thread [128]
  --file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []
  --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]
  --file-fsync-all[=on|off]     do fsync() after each write operation [off]
  --file-fsync-end[=on|off]     do fsync() at the end of test [on]
  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]
  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]
  --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

[root@DB1 ~]# 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
  pgsql - PostgreSQL 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]

pgsql options:
  --pgsql-host=STRING     PostgreSQL server host [localhost]
  --pgsql-port=N          PostgreSQL server port [5432]
  --pgsql-user=STRING     PostgreSQL user [sbtest]
  --pgsql-password=STRING PostgreSQL password []
  --pgsql-db=STRING       PostgreSQL database name [sbtest]

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

【3】使用方法

【3.1】命令格式与常规语法

sysbench [options]... [testname] [command] 

常规语法:

  • testname是的内置测试(例如,一个可选的名字fileio, memorycpu等),或捆绑的Lua脚本之一(例如的名称oltp_read_only),或者路径到自定义Lua中。如果在命令行上未指定测试名称(因此也没有 命令,因为在这种情况下它将被解析为testname),或者测试名称是破折号(“ -”),则sysbench期望使用Lua脚本以在其标准输入上执行。

  • command:是一个可选参数,它将由sysbench传递给用testname指定的内置测试或脚本命令 定义测试必须执行操作可用命令的列表取决于特定的测试。一些测试还实现了自己的自定义命令。

    以下是典型测试命令及其用途的说明:

    • prepare生成测试所需要的数据,例如在磁盘上创建测试所需的文件fileio ,或为数据库基准测试填充测试数据库。
    • run进行性能测试,运行使用testname 参数指定的实际测试所有测试均提供此命令。
    • cleanup清除测试数据,在创建一个测试的那些测试中运行后删除临时数据。
    • help:显示使用testname参数指定的测试的使用信息 这包括测试提供的命令的完整列表,因此应使用它来获取可用的命令。
  • options:是以开头的零个或多个命令行选项的列表 '--'与命令一样,该sysbench testname help命令应用于描述特定测试提供的可用选项。

    有关 sysbench本身提供的常规选项的说明,请参见常规命令行选项

您可以sysbench --help用来显示常规命令行语法和选项。

【3.2】Testname

包含2种,内建脚本和Lua脚本

  • sysbench可以实现如下基准测试:
  • oltp_*.lua: OLTP类的数据库基准测试;
  • fileio:文件系统的(IO)基准测试;
  • cpu: 简单的CPU基准测试;
  • memory: 内存访问基准测试;
  • threads: 基于线程的调度基准测试;
  • mutex: POSIX互斥量基准测试

ll /usr/share/sysbench/  ,这是yum安装生成的

  

如果是我们编译安装的,则会在指定目录下的 share/sysbench

如下图:

  

【4】Options

【4.1】全局参数

General options:

--threads=N 指定测试使用多少线程数,默认为1

--events=N 测试执行的总events数量,默认0

--time=N 最大执行时间,单位为秒。默认是10

--forced-shutdown=STRING 超过max-time强制中断, 默认是 off [off]

--thread-stack-size=SIZE 每个线程的堆栈大小, 默认是 64k

--rate=N average transactions rate. 0 for unlimited rate [0]

--report-interval=N 在N秒内输出一次统计数据。默认0禁用

--report-checkpoints=[LIST,...] 转储完全统计信息并在指定时间点复位所有计数器。 参数是逗号分隔值的列表,表示从必须执行报告检查点的测试开始所经过的时间(以秒为单位)。 默认情况下,报告检查点处于关闭状态

--debug[=on|off] 是否显示更多的调试信息, 默认是off

--validate[=on|off] 在可能情况下执行验证检查, 默认是off。

--help[=on|off] 输出 help 信息, 并退出

--version[=on|off] 输出版本信息, 并退出

--config-file=FILENAME 配置文件

--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]

【4.2】伪随机数

Pseudo-Random Numbers Generator options:

--rand-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special

--rand-spec-iter=N 产生数的迭代次数。默认是12

--rand-spec-pct=N 值的百分比被视为’special’ (for special distribution)。默认是1

--rand-spec-res=N 'special'的百分比值。默认是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 参数h用于 pareto 分布[0.2]

【4.3】日志

Log options:

--verbosity=N 日志级别,默认为3,5=debug,0=只包含重要信息

--percentile=N 表示设定采样比例,默认是 95%,即丢弃5%的长请求,在剩余的95%里取最大值 [95]

--histogram[=on|off] print latency histogram in report [off]

【4.4】数据库

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]

【4.5】 Mysql

Compiled-in database drivers:

mysql - MySQL driver

mysql options:

--mysql-host ==>被测mysql服务的ip地址,默认localhost
--mysql-port ==>被测mysql服务的端口,默认3306
--mysql-socket ==>被测mysql服务的socket
--mysql-user ==>测试mysql服务的用户,默认sbtest
--mysql-password==>测试mysql服务的密码,默认空
--mysql-db ==>被测试库名,默认sbtest
--mysql-ssl ==>使用SSL连接,默认off
--mysql-ssl-cipher ==>使用SSL连接的秘密
--mysql-compression==>使用压缩,默认off
--mysql-debug ==>跟踪所有客户端库调用,默认off
--mysql-ignore-errors==>列出要忽略的错误的编号列表,all是全部,[LIST,...]
--mysql-dry-run ==>干运行,假设所有的MySQL客户端API调用都是成功的,而不用执行它们,默认off;

--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]

【4.6】 fileio

[root@zhumh ~]# sysbench fileio help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

fileio options:

--file-num=N 指定测试生成多少文件[128]

--file-block-size=N --指定测试块的大小(通常测试mysql默认为16k[16384],或8k[8192])[16384]

--file-total-size=SIZE --指定测试生成总文件大小(file-total-size/file-num=文件个数)[2G]

--file-test-mode=STRING --指定测试磁盘IO的模式

seqwr --顺序写

seqrewr --顺序读写

seqrd --顺序读

rndrd --随机读

rndwr --随机写

rndrw --随机读写

--file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync

--file-async-backlog=N 对应每个线程队列的异步操作数,默认为128。

--file-extra-flags=STRING 使用额外的标志来打开文件(sync,dsync,direct),mysql通常用direct方式

--file-fsync-freq=N --执行fsync()的频率,默认为100,0为不使用 (0 - don't use fsync()) [100]

--file-fsync-all[=on|off] do fsync()--每次执行完一次写操作就执行一次fsync(),默认为off

--file-fsync-end[=on|off] --在测试结束时才执行fsync。默认是on

--file-fsync-mode=STRING 用什么样的模式来同步文件fsync, fdatasync (see above) fsync

--file-merged-requests=N --如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0

--file-rw-ratio=N --测试时的读写比例。默认是1.5

生成测试用的数据文件,要求生成的数据文件至少要比内存大,否则数据由于被操作系统缓存而无法体现 I/O 密集型工作负载。

【4.7】 cpu

[root@zhumh ~]# sysbench cpu help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

cpu options:

--cpu-max-prime=N upper limit for primes generator [10000]

cpu 测试为测试计算素数直到某个最大值所需的时间。–cpu-max-prime指定这个最大素数值
sysben测试cpu时,为什么采用素数加法运算?
在这种模式下每个请求在于计算素数——cpu-max-primes选项指定一个值。所有的计算执行使用64位的整数。

【4.8】memory

[root@zhumh ~]# sysbench memory help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

memory options:

–memory-block-size=SIZE 测试内存块的大小,默认为1K
–memory-total-size=SIZE 数据传输的总大小,默认为100G
–memory-scope=STRING 内存访问的范围,包括全局和本地范围,默认为global
–memory-hugetlb=[on|off] 是否从HugeTLB池分配内存的开关,默认为off
–memory-oper=STRING 内存操作的类型,包括read, write, none,默认为write
–memory-access-mode=STRING 内存访问模式,包括seq,rnd两种模式,默认为seq

【4.9】 threads

[root@zhumh ~]# sysbench threads help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

threads options:

1. --thread-yields=N number of yields to do per request [1000] 每个请求产生多少个线程,默认[1000]

2. --thread-locks=N number of locks per thread [8] 每个线程的锁数量,默认 [8]

线程调度:线程并发执行,循环响应信号量花费的时间{越少越好}
测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用

【4.10】mutex

[root@zhumh ~]# sysbench mutex help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

mutex options:

1. --mutex-num=N total size of mutex array [4096] 数组互斥总大小,默认[4096]

2. --mutex-locks=N number of mutex locks to do per thread [50000] 每个线程互斥锁的数量,默认 [50000]

3. --mutex-loops=N number of empty loops to do inside mutex lock [10000] 内部互斥锁的空循环数量,默认 [10000]

互斥锁:并发线程同时申请互斥锁循环一定次数花费的时间{越少越好}

测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁

【4.11】OLTP

[root@zhumh ~]# sysbench /usr/share/sysbench/oltp_common.lua help

sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)

oltp_common.lua options:

--distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1]

--sum_ranges=N Number of SELECT SUM() queries per transaction [1]

--skip_trx[=on|off] Don't start explicit transactions and execute all queries as in the AUTOCOMMIT mode [off]

--secondary[=on|off] Use a secondary index in place of the PRIMARY KEY [off]

--create_secondary[=on|off] Create a secondary index in addition to the PRIMARY KEY [on]

--index_updates=N Number of UPDATE index queries per transaction [1]

--range_size=N Range size for range SELECT queries [100]

--auto_inc[=on|off] Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on]

--delete_inserts=N Number of DELETE/INSERT combination per transaction [1]

--tables=N Number of tables [1]

--mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb]

--non_index_updates=N Number of UPDATE non-index queries per transaction [1]

--table_size=N Number of rows per table [10000]

--pgsql_variant=STRING Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0

--simple_ranges=N Number of simple range SELECT queries per transaction [1]

--order_ranges=N Number of SELECT ORDER BY queries per transaction [1]

--range_selects[=on|off] Enable/disable all range SELECT queries [on]

--point_selects=N Number of point SELECT queries per transaction [10]

 

【4.11】LUA脚本

oltp_read_only ==>只读测试
oltp_read_write ==>读写测试

oltp_insert ==>简单插入测试
bulk_insert ==>批量插入测试

oltp_delete ==>delete删除测试

oltp_update_index ==>带索引的更新测试
oltp_update_non_index ==>不带索引的更新测试

oltp_point_select ==>等值查询测试
select_random_points ==>随机等值查询测试
select_random_ranges ==>随机范围查询测试

【5】测试样例

【5.1】mysql

5.1.1 创建sbtest数据库

Create database sbtest;

5.1.2 测试脚本
sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60 --mysql-user=root --mysql-password=root --mysql-socket=/data/mysql/db_zhumh/mysql.sock /usr/share/sysbench/oltp_read_write.lua prepare

sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60 --mysql-user=root --mysql-password=root --mysql-socket=/data/mysql/db_zhumh/mysql.sock /usr/share/sysbench/oltp_read_write.lua run

【5.2】IO

--创建10G的文件,分成4个,测试16K块大小,使用direct方式读,测试600秒(10分钟),启用64个线程,每3秒输出一次结果

#sysbench --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3 fileio prepare

#sysbench --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3 fileio run

#sysbench --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3 fileio cleanup

磁盘:S3610 * 6 raid10, 内存128G

测试出相关场景下的极限IOPS

随机读写(3:2 oltp场景)

sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct run

fileio_oltp_32

随机读写(51 oltp场景)

sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct --file-rw-ratio=5 run

fileio_oltp_51

随机写

sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndwr --file-block-size=16384 --file-extra-flags=direct run

fileio_rndwr

随机读

sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrd --file-block-size=16384 --file-extra-flags=direct run

【6】Tpcc

6.1 Option

[root@localhost sysbench]# sysbench /usr/share/sysbench/tpcc.lua help

sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

tpcc.lua options:

--enable_purge=STRING Use purge transaction (yes, no) [no]

--force_pk=N Force using auto-inc PK on history table [0]

--mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb]

--mysql_table_options=STRING Extra table options, if MySQL is used. e.g. 'COLLATE latin1_bin' []

--report_csv=STRING Report output in csv (yes, no) [no]

--scale=N Scale factor (warehouses) [100]

--tables=N Number of tables [1]

--trx_level=STRING Transaction isolation level (RC, RR or SER) [RR]

--use_fk=N Use foreign keys [1]

6.2 测试脚本

必须要先 prepare  然后才能 run

./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql prepare

./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql run

./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql cleanup

【7】mysql详细压测参考

https://blog.51cto.com/4709096/2494135

【7.3】我的实践

结合 iostat -xk 1 查看磁盘;

结合 vmstat 1 查看CPU以及上下文切换 cs

-- (1)fileio 测试
/* 每次测试之后,都要运行,清理缓存
    sync                                   -- 将脏数据刷新到磁盘
    echo 3 > /proc/sys/vm/drop_caches    -- 清除OS Cache
    swapoff -a && swapon -a              -- 清除OS swap缓存

sync
echo 3 > /proc/sys/vm/drop_caches

    iostat -xk 1    # 查看磁盘IO使用率
    vmstat 1        # 查看CPU使用率
*/

-- rndrd
sysbench --test=fileio --file-total-size=100G --file-test-mode=rndrd --file-block-size=16k --threads=16 --events=100000000 --file-num=100 --time=180 run

-- seqrd
sysbench --test=fileio --file-total-size=100G --file-test-mode=seqrd --file-block-size=16k --threads=16 --events=100000000 --file-num=100 --time=180 run

-- rndrw
sysbench --test=fileio --file-total-size=100G --file-test-mode=rndwr --file-block-size=16k --threads=16 --events=100000000 --file-num=100 --time=180 run

-- seqwr
sysbench --test=fileio --file-total-size=100G --file-test-mode=seqwr --file-block-size=16k --threads=16 --events=100000000 --file-num=100 --time=180 run



-- (2)mysql 测试
mysql -e "create database test;"
mysql -e "create user dbtest@'%' identified by '123456';grant all on *.* to dbtest@'%';"

/* 每次测试之后,都要运行,清理缓存
    sync                                   -- 将脏数据刷新到磁盘
    echo 3 > /proc/sys/vm/drop_caches    -- 清除OS Cache
    swapoff -a && swapon -a              -- 清除OS swap缓存
    
--参考
./sysbench --test=/root/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=500000000 
--oltp-tables_count=4 --mysql-table-engine=innodb --mysql-user=adtime --mysql-password=adtime100  --mysql-host=10.2.50.37  --mysql-db=test  prepare

*/


-- 构造数据
sysbench oltp_common --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=8 --table_size=50000000 --tables=5  prepare


-- insert 
sysbench oltp_insert --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=1024 --table_size=50000000 --tables=5 --time=180 run
sysbench oltp_insert --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=512 --table_size=50000000 --tables=5 --time=180 run

-- select  
sysbench oltp_point_select --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=1024 --table_size=50000000 --tables=5 --time=120 run
sysbench oltp_point_select --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=512 --table_size=50000000 --tables=5 --time=120 run

-- update_index
sysbench oltp_update_index --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=1024 --table_size=50000000 --tables=5 --time=120 run
sysbench oltp_update_index --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=512 --table_size=50000000 --tables=5 --time=120 run



-- TPS  
sysbench oltp_write_only --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=128 --table_size=50000000 --tables=5 --time=120 run
sysbench oltp_write_only --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=dbtest --mysql-password=123456 --mysql-db=test --threads=64 --table_size=50000000 --tables=5 --time=120 run

【8】运行结果信息分析

该部分转自:https://blog.csdn.net/qq_39884410/article/details/107785519

General statistics(综合统计)
total time: 10.0004s
total number of events: 25875

CPU测试,在10s范围内进行素数计算这个行为一共进行了25875次,实际执行时间为10.0004s;


latency(ms)
min 0.36
avg 0.39
max 16.12
95th percentile 0.44
sum: 9884
这部分数据应该统计的是线程真正执行的时间,总共9884.06ms, 单次执行最少时间为0.36ms,
最多时间为16.12ms, 平均时间为0.39ms, 95%次的执行时间在0.44ms左右;


Threads fairness:
events (avg/stddev): 43084.0000/0.00
execution time (avg/stddev): 9.8626/0.00

归纳总结,线程执行时间为9.8626s, 执行平均次数为43084次;

SQL statistics:  --SQL统计
    queries performed:
        read:                            0       -- 读总数
        write:                           646611  -- 写总数
        other:                           323312  -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           969923  -- 全部总数
    transactions:                        161643 (1346.83 per sec.)  -- 总事务数(每秒事务数)TPS
    queries:                             969923 (8081.51 per sec.)  -- 总请求数(每秒请求数)QPS
    ignored errors:                      26     (0.22 per sec.)     -- 忽略的总错误数(每秒忽略的错误数)
    reconnects:                          0      (0.00 per sec.)     -- 重连总数(每秒重连数)

General statistics: --一般统计
    total time:                          120.0165s  -- 总耗时
    total number of events:              161643     -- 共发生多少事务数

Latency (ms):   -- 响应时间
         min:                                    1.90  -- 最小耗时
         avg:                                    5.94  -- 平均耗时
         max:                                  208.35  -- 最长耗时
         95th percentile:                        9.06  -- 95%的测试平均耗时
         sum:                               959723.32  -- 总耗时

Threads fairness:  -- 线程的稳定性
    events (avg/stddev):           20205.3750/37.94  -- 事件(平均值/偏差)
    execution time (avg/stddev):   119.9654/0.01     -- 执行时间(平均值/偏差)

【参考文档】

mysql压测:https://blog.51cto.com/4709096/2494135

本文转自:https://blog.csdn.net/weixin_34159110/article/details/93135184

SQL statistics:  --SQL统计
    queries performed:
        read:                            0       -- 读总数
        write:                           646611  -- 写总数
        other:                           323312  -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           969923  -- 全部总数
    transactions:                        161643 (1346.83 per sec.)  -- 总事务数(每秒事务数)TPS
    queries:                             969923 (8081.51 per sec.)  -- 总请求数(每秒请求数)QPS
    ignored errors:                      26     (0.22 per sec.)     -- 忽略的总错误数(每秒忽略的错误数)
    reconnects:                          0      (0.00 per sec.)     -- 重连总数(每秒重连数)

General statistics: --一般统计
    total time:                          120.0165s  -- 总耗时
    total number of events:              161643     -- 共发生多少事务数

Latency (ms):   -- 响应时间
         min:                                    1.90  -- 最小耗时
         avg:                                    5.94  -- 平均耗时
         max:                                  208.35  -- 最长耗时
         95th percentile:                        9.06  -- 95%的测试平均耗时
         sum:                               959723.32  -- 总耗时

Threads fairness:  -- 线程的稳定性
    events (avg/stddev):           20205.3750/37.94  -- 事件(平均值/偏差)
    execution time (avg/stddev):   119.9654/0.01     -- 执行时间(平均值/偏差)
原文地址:https://www.cnblogs.com/gered/p/14142946.html