`
angelguo
  • 浏览: 118194 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

sysbench 进行压力测试

 
阅读更多

介绍

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

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

 

安装

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

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

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
复制代码
[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
复制代码

报告:时间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
 View Code

报告:12.6S,8G/s

3.16K顺序分配

./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=seq run
 View Code

报告:7S,13G/S

4.16K随机分配

./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=rnd run
 View Code

报告:6.4S,15G/s

总结:对于分配同样大小的内存,块月大分配的速率越快,随机分配比顺序分配的速度要快

文件io测试

./sysbench --test=fileio help

文件IO的测试主要用于测试IO的负载性能。主要的测试选项为--file-test-mode。还有几个可以关注的参数包括--file-block-size、--file-io-mode、--file-fsync-freq 、--file-rw-ratio

复制代码
--file-num=N                   创建测试文件的数量,默认128个
  --file-block-size=N          block size大小,默认16K
  --file-total-size=SIZE       所有文件的总大小,默认2G
  --file-test-mode=STRING      测试类型 {seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
  --file-io-mode=STRING         I/O模式,需要系统支持默认sync[sync(同步IO),async(异步IO),mmap()]
  --file-async-backlog=N        每个线程的异步操作队列数,默认128个,需要--file-io-mode=async;
  --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
  --file-fsync-freq=N           当请求数达到多少时执行fsync()刷新,默认100,0代表过程中不执行fsync()
  --file-fsync-all=[on|off]     执行每一个写操作后执行fsync()刷新操作,默认关闭off
  --file-fsync-end=[on|off]     测试结束执行fsync()操作,默认开启on
  --file-fsync-mode=STRING      同步刷新方法,默认fsync {fsync, fdatasync} 
  --file-merged-requests=N      合并指定数量的IO请求,0代表不合并,默认0
  --file-rw-ratio=N            读写比例,默认1.5/1

复制代码
./sysbench --num-threads=12 --max-requests=10000  --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare
./sysbench --num-threads=12 --max-requests=10000  --test=fileio --file-total-size=3G --file-test-mode=rndrw run
./sysbench --num-threads=12 --max-requests=10000  --test=fileio --file-total-size=3G --file-test-mode=rndrw clean

注意:如果要对比两台服务器的io性能,需要跑相同的线程。

互斥锁测试

互斥锁测试模拟所有线程在同一时刻并发运行

./sysbench  --num-threads=12  --test=mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 run
复制代码
[root@localhost sysbench-0.4.12]# ./sysbench  --num-threads=12  --test=mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 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 mutex performance test
Threads started!
Done.


General statistics:
    total time:                          0.0869s
    total number of events:              12
    total time taken by event execution: 1.0301
    response time:
         min:                                 83.86ms
         avg:                                 85.84ms
         max:                                 86.88ms
         approx.  95 percentile:              86.78ms

Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   0.0858/0.00
复制代码

oltp测试

oltp是针对数据库的基准测试,例如每次对数据库进行优化后执行基准测试来测试不同的配置的tps。可以通过以下命令了解它的有关参数:

./sysbench --test=oltp help

复制代码
--oltp-test-mode=STRING                    测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
  --oltp-reconnect-mode=STRING             连接类型:session(每个线程到测试结束不重新连接),transaction(执行每个事务重新连接),query(每一个查询重新连接),random(随机);默认 [session]
  --oltp-sp-name=STRING                    指定执行测试的存储过程名
  --oltp-read-only=[on|off]                仅执行select测试,默认关闭
  --oltp-avoid-deadlocks=[on|off]          更新过程中忽略死锁,默认[off]
  --oltp-skip-trx=[on|off]                 语句以bigin/commit开始结尾,默认[off]
  --oltp-range-size=N                      范围查询的范围大小,默认 [100],例如begin 100 and 200
  --oltp-point-selects=N                   单个事务中select查询的数量,默认 [10]
  --oltp-use-in-statement=N                每个查询中主键查找(in 10个值)的数量,默认 [0]
  --oltp-simple-ranges=N                   单个事务中执行范围查询的数量(SELECT c  FROM sbtest WHERE id BETWEEN  N AND  M),默认[1]
  --oltp-sum-ranges=N                      单个事务中执行范围sum查询的数量,默认 [1]
  --oltp-order-ranges=N                    单个事务中执行范围order by查询的数量,默认[1]
  --oltp-distinct-ranges=N                 单个事务中执行范围distinct查询的数量,默认[1]
  --oltp-index-updates=N                   单个事务中执行索引更新的操作的数量,默认[1]
  --oltp-non-index-updates=N               单个事务中执行非索引更新操作的数量,默认[1]
  --oltp-nontrx-mode=STRING                指定单独非事务测试类型进行测试,默认select {select, update_key, update_nokey, insert, delete} [select]
  --oltp-auto-inc=[on|off]                 id列默认自增,默认[on]
  --oltp-connect-delay=N                   指定每一次重新连接延时的时长,默认1秒 [10000]
  --oltp-user-delay-min=N                  minimum time in microseconds to sleep after each request [0]
  --oltp-user-delay-max=N                  maximum time in microseconds to sleep after each request [0]
  --oltp-table-name=STRING                 指定测试的表名,默认[sbtest]
  --oltp-table-size=N                      指定表的记录大小,默认[10000]
  --oltp-dist-type=STRING                  随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布),默认 [special]
  --oltp-dist-iter=N                       number of iterations used for numbers generation [12]
  --oltp-dist-pct=N                        启用百分比特殊分布,默认 [1]
  --oltp-dist-res=N                        special 百分比[75]
  --oltp-point-select-mysql-handler=[on|off] Use MySQL HANDLER for point select [off]
  --oltp-point-select-all-cols=[on|off]    select查询测试时select所有列,默认[off]
  --oltp-secondary=[on|off]                索引不是主键索引而是二级索引,默认[off]
  --oltp-num-partitions=N                  指定表分区的数量,默认 [0]
  --oltp-num-tables=N                      指定测试表的数量,默认[1]
General database options:
  --db-driver=STRING  指定测试数据库类型,默认mysql
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

mysql options:
  --mysql-host=[LIST,...]       MySQL server host [localhost]
  --mysql-port=N                MySQL server port [3306]
  --mysql-socket=STRING         MySQL socket
  --mysql-user=STRING           MySQL user [sbtest]
  --mysql-password=STRING       MySQL password []
  --mysql-db=STRING             MySQL database name [sbtest]
  --mysql-table-engine=STRING   storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
  --mysql-engine-trx=STRING     whether storage engine used is transactional or not {yes,no,auto} [auto]
  --mysql-ssl=[on|off]          use SSL connections, if available in the client library [off]
  --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]
  --mysql-create-options=STRING additional options passed to CREATE TABLE []
复制代码

oltp测试主要会有以下相关参数的测试,,其它相关参数默认即可,有需求也可以自定义:

--mysql-engine-trx=STRING     指定不同的存储引擎测试。
--oltp-test-mode=STRING       测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
--oltp-sp-name=STRING         指定存储过程进行语句测试
--oltp-table-size=N           指定表的记录大小,默认[10000]
--oltp-num-tables=N           指定测试表的数量,默认[1]

需要先创建好测试数据库sbtest。

1.事务测试,测试12个线程执行1万条请求,10个表,每个表大小100W

./sysbench --num-threads=12 --max-requests=100000  --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 prepare
./sysbench --num-threads=12 --max-requests=100000  --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 run
./sysbench --num-threads=12 --max-requests=100000  --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 cleanup
复制代码
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=100000  --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 run
sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 12
Random number generator seed is 0 and will be ignored


Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 100000
Using 10 test tables
Threads started!
Done.

OLTP test statistics:
    queries performed:
        read:                            1400910
        write:                           500325
        other:                           200130
        total:                           2101365
    transactions:                        100065 (791.94 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 1901235 (15046.89 per sec.)
    other operations:                    200130 (1583.88 per sec.)

General statistics:
    total time:                          126.3540s
    total number of events:              100065
    total time taken by event execution: 1513.9202
    response time:
         min:                                  5.82ms
         avg:                                 15.13ms
         max:                               2352.66ms
         approx.  95 percentile:              18.00ms

Threads fairness:
    events (avg/stddev):           8338.7500/207.
复制代码

报告:执行当前测试花费126S,TPS:791/S,RQ:15046/S,95%的请求花费18毫秒

事务测试,每个事务包含如下语句:

复制代码
  Point queries:
SELECT c FROM sbtest WHERE id= N
  Range queries:
SELECT c FROM sbtest WHERE id BETWEEN  N AND  M
  Range SUM() queries:
SELECT SUM(K) FROM sbtest WHERE id BETWEEN  N and  M
  Range ORDER BY queries:
SELECT c FROM sbtest WHERE id between  N and  M ORDER BY c
  Range DISTINCT queries:
SELECT DISTINCT c FROM sbtest WHERE id BETWEEN  N and  M ORDER BY
c
  UPDATEs on index column:
UPDATE sbtest SET k=k+1 WHERE id= N
  UPDATEs on non-index column:
UPDATE sbtest SET c= N WHERE id= M
  DELETE queries:
DELETE FROM sbtest WHERE id= N
  INSERT queries:
INSERT INTO sbtest VALUES ( ...
复制代码

 非事务测试,执行语句如下

复制代码
  Point queries:
SELECT pad FROM sbtest WHERE id= N
  UPDATEs on index column:
UPDATE sbtest SET k=k+1 WHERE id= N
  UPDATEs on non-index column:
UPDATE sbtest SET c= N WHERE id= M
  DELETE queries:
DELETE FROM sbtest WHERE id= N
  The generated row IDs are unique over each test run, so no row
is deleted twice.
  INSERT queries:
INSERT INTO sbtest (k, c, pad) VALUES( N ,  M ,  S )
复制代码

总结

 sysbench是使用最广泛的基准压测工具,功能也很齐全报告也非常的详细。

分享到:
评论

相关推荐

    数据库经典压测工具sysbench双版本 sysbench0.5支持oracle sysbench1.1 支持达梦 附详细文档

    通过执行预定义或自定义的测试脚本,sysbench0.5可以帮助管理员了解数据库在高压力下的表现,从而进行优化。 对于Oracle数据库,sysbench0.5通常需要进行一些配置调整,以确保与Oracle特定的语法和特性兼容。这可能...

    06-MySQL压力测试工具sysbench1

    MySQL 压力测试工具 sysbench 介绍 sysbench 是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。目前 sysbench 主要支持 MySQL, pgsql, oracle 这 3 种数据库。 ...

    用于mysql压测

    在使用sysbench进行压力测试时,我们可以关注以下几个关键知识点: 1. **测试场景设置**:sysbench支持多种测试模式,包括OLTP(在线事务处理)测试如read-write、read-only等,以及自定义SQL脚本。可以根据实际...

    mysql数据库测试报告

    综上所述,通过对MySQL数据库的测试报告进行详细分析,我们了解了Inodes对表创建的限制、并发连接的资源管理以及如何通过Sysbench进行压力测试等方面的知识点。这些信息对于优化MySQL数据库性能、提升服务质量具有...

    sysbench-1.0.19.zip

    首先,让我们详细了解sysbench如何进行MySQL压力测试。sysbench提供了安装和配置的步骤,用户需要先编译源代码,然后根据自己的MySQL服务器配置进行设置。在运行测试之前,需要创建测试表并填充数据。sysbench支持...

    sysbench基准测试

    它提供了丰富的测试场景,比如OLTP(在线事务处理)操作、CPU压力测试、文件IO性能测试等,是系统管理员和开发人员进行性能调优时常用的工具。 ### 1. `sysbench`简介 `sysbench`由Anton Koksharov开发,旨在提供...

    sysbench-1.0.zip

    3. **压力测试模块**:sysbench可以生成高并发的请求,模拟真实环境下的负载,从而测试数据库在高压力下的性能表现。 4. **CPU性能测试模块**:除了数据库测试,sysbench还可以进行CPU密集型计算的性能测试,如整数...

    sysbench-master.zip

    sysbench的核心在于其模块化的结构,可以支持多种测试场景,包括OLTP(在线事务处理)场景下的数据库压力测试、文件系统的IO性能测试以及CPU密集型计算的基准测试。它能够灵活地配置测试参数,以便对系统性能进行...

    sysbench-1.0.20.tar.gz

    sysbench是由Anton Kapela开发的一款开源软件,它提供了多种性能测试场景,包括压力测试数据库服务器、模拟多线程计算任务、磁盘I/O性能测试等。sysbench-1.0.20是sysbench的一个特定版本,适用于x86和ARM架构,这...

    sysbench压测工具

    `sysbench`是一款多用途的压力测试工具,广泛用于评估系统的性能,特别是在数据库、CPU、内存以及文件I/O等方面。它最初设计是用来测试MySQL数据库的性能,但随着时间的推移,其功能得到了扩展,现在可以应用于各种...

    sysbench 0.5

    2. **可扩展性**:它包含多种预定义的测试模块,如CPU基准测试、随机读写测试、SQLite数据库压力测试等,同时允许用户自定义测试脚本。 3. **结果记录与分析**:sysbench能够生成详细的测试报告,包括每秒操作数...

    mysql压力测试工具

    下面,我们将深入探讨sysbench的功能、安装、配置以及如何使用它进行MySQL的压力测试。 1. **sysbench功能** - **系统性能测试**:sysbench提供了CPU、内存、磁盘I/O等系统层面的基准测试,能够分析系统在不同...

    sysbench-0.4.12.14

    sysbench不仅可以用于数据库的压力测试,还可以用作系统整体性能的诊断和调优。 sysbench-0.4.12.14 是sysbench的一个特定版本,可能包含了该版本的源代码、编译脚本、文档和其他相关资源。这个版本可能已经过测试...

    sysbench-0.4.12

    1. CPU性能测试:sysbench-0.4.12可以进行多线程的CPU基准测试,包括计算密集型的prime测试和线程压力测试,来评估处理器的并行处理能力。 2. 内存性能测试:通过内存填充、顺序读写、随机读写等操作,sysbench可以...

    sysbench-0.4.10.tar.gz

    1. **sysbench介绍**:sysbench是由Antonin Houska开发的一款强大的性能测试工具,它可以用来做系统压力测试、CPU基准测试、内存性能测试、磁盘IO性能测试,以及数据库的OLTP(在线事务处理)性能测试。 2. **版本...

    Sysbench压测工具搭建和使用实践

    本文将详细介绍如何搭建Sysbench环境以及如何进行有效的压力测试实践。 首先,让我们从安装Sysbench开始。在Linux环境下,通常可以通过包管理器来安装。对于基于Debian的系统,如Ubuntu,可以使用`apt-get`命令: ...

Global site tag (gtag.js) - Google Analytics