SysBench是一款开源的、跨平台的、模块化的、多线程的性能测试工具,通过高负载地运行在数据库上,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。用于评估操作系统的性能参数。

1 sysbench简介

Sysbench使得我们无需采用真正的复杂的数据库benchmark而获取系统的性能概况。

目前主要支持的数据库有mysql、oracle、postgresql。

可评估的系统性能参数有:

1.      Cpu性能

2.      内存分配与传输速度测试

3.      互斥体测试

4.      文件I/O性能

5.      线程调度性能

6.      数据库服务性能(OLTP基准)

本来sysbench主要是为mysql编写的benchmark。但是现在SysBench将进一步扩展,以支持更多的数据库backends,distributed benchmarks和第三方插件模块。

sysbench按照指定的数量开启线程,每个线程与mysql建立一个连接,每个线程不停地进行事务操作,打开事务,然后进行一些查询、更新、插入操作,提交事务,再开始新的事务;所有的sql只访问一个表-sbtest,是由sysbench的prepare命令建好的。其中的记录数,也是在prepare时指定好并创建的。测试结束,会有一个统计结果,包括例如每秒事务数、平均响应时间等等;

2  sysbench下载与安装

1.下载

下载地址:Phoronix Test Suite download | SourceForge.net

获得sysbench-0.4.8.tar.gz源码。sysbench-0.4.8.tar.gz编译未通过。

2.安装

默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数


  1. [root@RedHat sysbench-0.4.8]# ./configure --without-mysql
  2. [root@RedHat sysbench-0.4.8]# make
  3. [root@RedHat sysbench-0.4.8]# make install

如果需要测试mysql,则需要配置参数选项:

./configure

--with-mysql-includes=/opt/mysql/include/mysql 表示mysql头文件目录

--with-mysql-libs=/opt/mysql/lib/mysql表示mysql模块目录

如果缺少libtool请至ftp://ftp.gnu.org/gnu/libtool/下载

3 sysbench帮助说明

请查看sysbench帮助


  1. [root@RedHat sysbench-0.4.8]# sysbench
  2. Missing required command argument.
  3. Usage:
  4.   sysbench [general-options]... --test=<test-name> [test-options]... command
  5. General options:
  6.   --num-threads=N            number of threads to use [1]
  7.   --max-requests=N           limit for total number of requests [10000]
  8.   --max-time=N               limit for total execution time in seconds [0]
  9.   --thread-stack-size=SIZE   size of stack per thread [32K]
  10.   --init-rng=[on|off]        initialize random number generator [off]
  11.   --test=STRING              test to run
  12.   --debug=[on|off]           print more debugging info [off]
  13.   --validate=[on|off]        perform validation checks where possible [off]
  14.   --help=[on|off]            print help and exit
  15. Compiled-in tests:
  16.   fileio - File I/O test
  17.   cpu - CPU performance test
  18.   memory - Memory functions speed test
  19.   threads - Threads subsystem performance test
  20.   mutex - Mutex performance test
  21.   oltp - OLTP test
  22. Commands: prepare run cleanup help
  23. See 'sysbench --test=<name> help' for a list of options for each test.
  24. [root@RedHat sysbench-0.4.8]#

其中通用参数

参数名

参数描述

--num-threads=N

测试时使用的线程数,默认为1

--max-requests=N

请求数最大现在,默认10000

-max-time=N

执行时间最大限制,默认为0

--thread-stack-size=SIZE

每个线程的stack大小,默认是32K

--init-rng=[on|off]

是否初始化随机数生成器

--test=STRING

运行的测试

--debug=[on|off]

是否打印更多的debug信息

--validate=[on|off]

是否执行有效性检查

--help=[on|off]

打印帮助并退出

其中--test=STRING中的STRING可选项有:

STRING

描述

fileio

文件IO测试

cpu

CPU性能测试

memory

内存分配与传输速度测试

threads

线程子系统性能测试

mutex

互斥体性能测试

oltp

数据库OLTP测试

4 文件IO测试

4.1 参数说明


  1. [root@RedHat test]# sysbench --test=fileio help
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. fileio options:
  4.   --file-num=N                  number of files to create [128]
  5.   --file-block-size=N           block size to use in all IO operations [16384]
  6.   --file-total-size=SIZE        total size of files to create [2G]
  7.   --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
  8.   --file-io-mode=STRING   file operations mode {sync,async,fastmmap,slowmmap} [sync]
  9.   --file-extra-flags=STRING  additional flags to use on opening files {sync,dsync,direct} []
  10.   --file-fsync-freq=N      do fsync() after this number of requests (0 - don't use fsync()) [100]
  11.   --file-fsync-all=[on|off]     do fsync() after each write operation [off]
  12.   --file-fsync-end=[on|off]     do fsync() at the end of test [on]
  13.   --file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
  14.   --file-merged-requests=N merge at most this number of IO requests if poss ible (0- don't merge) [0]
  15.   --file-rw-ratio=N             reads/writes ratio for combined test [1.5]
  16. [root@RedHat test]#

参数选项说明:

参数名

描述

--file-num=N

创建的文件数目,默认为128个

--file-block-size=N

所有IO操作中的block大小,默认是16384

--file-total-size=SIZE

创建的文件的总大小,默认为2G

--file-test-mode=STRING

测试的访问模式,可选一下6个参数:seqwr(顺序写)/seqrewr(顺序读写)/seqrd(顺序读)/ rndwr(随机写)/rndrw(随机读写)/rndrd(随机读);

--file-io-mode=STRING

文件操作模式,有以下四种选择:sync,async,fastmmap,slowmmap默认为sync

--file-extra-flags=STRING

打开文件是的标识,有以下选择:sync,dsync,direct

--file-fsync-freq=N

在N个请求之后执行fsync(),默认值为100,0表示不执行fsync()

--file-fsync-all=[on|off]

是否每一次写操作之后均执行fsync()

--file-fsync-end=[on|off]

在测试结束时执行fsync(),默认开启

--file-fsync-mode=STRING

同步使用什么方法:fsync, fdatasync,默认为fsync

--file-merged-requests=N

尽可能的合并N个请求,0表示不合并,默认为0

--file-rw-ratio=N

读写比例默认为1.5:1

4.2 测试案例

创建2个进程,创建的文件总大小为3G,文件读写模式为随机读。

可以获取读写速度~


  1. [root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw prepare (准备测试文件)
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3.  
  4. 128 files, 4096Kb each, 512Mb total
  5. Creating files for the test...
  6. [root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw run (运行测试)
  7. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  8.  
  9. Running the test with following options:
  10. Number of threads: 2
  11.  
  12. Extra file open flags: 0
  13. 128 files, 4Mb each
  14. 512Mb total file size
  15. Block size 16Kb
  16. Number of random requests for random IO: 10000
  17. Read/Write ratio for combined random IO test: 1.50
  18. Periodic FSYNC enabled, calling fsync() each 100 requests.
  19. Calling fsync() at the end of test, Enabled.
  20. Using synchronous I/O mode
  21. Doing random r/w test
  22. Threads started!
  23. Done.
  24.  
  25. Operations performed:  6000 Read, 4000 Write, 12800 Other = 22800 Total
  26. Read 93.75Mb  Written 62.5Mb  Total transferred 156.25Mb  (3.2979Mb/sec)
  27.   211.07 Requests/sec executed
  28.  
  29. Test execution summary:
  30.     total time:                          47.3783s
  31.     total number of events:              10000
  32.     total time taken by event execution: 36.6912
  33.     per-request statistics:
  34.          min:                            0.0000s
  35.          avg:                            0.0037s
  36.          max:                            0.2687s
  37.          approx.  95 percentile:         0.0230s
  38.  
  39. Threads fairness:
  40.     events (avg/stddev):           5000.0000/180.00
  41.     execution time (avg/stddev):   18.3456/0.19
  42.  
  43. [root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw cleanup (清除测试文件)
  44. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  45.  
  46. Removing test files...
  47. [root@RedHat test]#

5 CPU性能测试

Sysbench采用寻找最大素数的方式测试CPU性能:


  1. [root@RedHat ~]# sysbench --test=cpu help
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. cpu options:
  4.   --cpu-max-prime=N      upper limit for primes generator [10000]
  5. [root@RedHat ~]#

5.1 参数解析

参数名

描述

--cpu-max-prime=N

素数的最大限制,默认为10000;

5.2 测试案例


  1. [root@RedHat ~]# sysbench --test=cpu --cpu-max-prime=20000 run
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Doing CPU performance benchmark
  6. Threads started!
  7. Done.
  8. Maximum prime number checked in CPU test: 20000
  9. Test execution summary:
  10.     total time:                          124.1761s
  11.     total number of events:              10000
  12.     total time taken by event execution: 123.3658
  13.     per-request statistics:
  14.          min:                            0.0051s
  15.          avg:                            0.0123s
  16.          max:                            0.1908s
  17.          approx.  95 percentile:         0.0171s
  18. Threads fairness:
  19.     events (avg/stddev):           10000.0000/0.00
  20.     execution time (avg/stddev):   123.3658/0.00
  21. [root@RedHat ~]#

6. 内存性能测试

6.1 测试参数


  1. [root@RedHat ~]# sysbench --test=memory help
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. memory options:
  4.   --memory-block-size=SIZE    size of memory block for test [1K]
  5.   --memory-total-size=SIZE    total size of data to transfer [100G]
  6.   --memory-scope=STRING       memory access scope {global,local} [global]
  7.   --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
  8.   --memory-oper=STRING        type of memory operations {read, write, none} [write]
  9.   --memory-access-mode=STRING memory access mode {seq,rnd} [seq]
  10. [root@RedHat ~]#

参数说明:

参数名

描述

--memory-block-size=SIZE

内存块大小,默认为1K

--memory-total-size=SIZE

传输的数据量,默认为100G

--memory-scope=STRING

内存访问是局部local还是全局global,默认为global

--memory-hugetlb=[on|off]

从hugetlb中分配内存

--memory-oper=STRING

内存操作类型read, write, none,默认为写

--memory-access-mode=STRING

内存访问模式seq,rnd,默认为seq;

6.2 测试案例

[root@RedHat test]# sysbench --test=memory --memory-block-size=4k --memory-total-size=64M run

7.线程性能测试

7.1 测试参数


  1. [root@RedHat ~]# sysbench --test=threads help
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. threads options:
  4.   --thread-yields=N      number of yields to do per request [1000]
  5.   --thread-locks=N       number of locks per thread [8]
  6. [root@RedHat ~]#

参数说明:

参数名

描述

--thread-yields=N

内存块大小,默认为1K

--thread-locks=N

传输的数据量,默认为100G

7.2 测试案例


  1. [root@RedHat test]# sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 64
  5. Doing thread subsystem performance test
  6. Thread yields per test: 100 Locks used: 2
  7. Threads started!
  8. Done.
  9. Test execution summary:
  10.     total time:                          24.8159s
  11.     total number of events:              10000
  12.     total time taken by event execution: 1575.5529
  13.     per-request statistics:
  14.          min:                            0.0002s
  15.          avg:                            0.1576s
  16.          max:                            2.0173s
  17.          approx.  95 percentile:         0.5627s
  18. Threads fairness:
  19.     events (avg/stddev):           156.2500/12.62
  20.     execution time (avg/stddev):   24.6180/0.08
  21. [root@RedHat test]#

8 互斥体性能测试

8.1 测试参数


  1. [root@RedHat ~]# sysbench --test=mutex help
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. mutex options:
  4.   --mutex-num=N        total size of mutex array [4096]
  5.   --mutex-locks=N      number of mutex locks to do per thread [50000]
  6.   --mutex-loops=N      number of empty loops to do inside mutex lock [10000]
  7. [root@RedHat ~]#

参数解析:

参数名

描述

--mutex-num=N

互斥体数据大小,默认为4096

--mutex-locks=N

每个线程上互斥锁的数目,默认为50000;

--mutex-loops=N

互斥锁内空循环的数目,默认为10000

8.2 测试案例


  1. [root@RedHat test]# sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
  2. sysbench v0.4.8:  multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 16
  5. Doing mutex performance test
  6. Threads started!
  7. Done.
  8. Test execution summary:
  9.     total time:                          0.0482s
  10.     total number of events:              16
  11.     total time taken by event execution: 0.2271
  12.     per-request statistics:
  13.          min:                            0.0015s
  14.          avg:                            0.0142s
  15.          max:                            0.0312s
  16.          approx.  95 percentile:         0.0126s
  17. Threads fairness:
  18.     events (avg/stddev):           1.0000/0.00
  19.     execution time (avg/stddev):   0.0142/0.01
  20. [root@RedHat test]#

9 OLTP测试

不做分析了

10. 参考资料:

Phoronix Test Suite download | SourceForge.net

sysbench_qiudakun的博客-CSDN博客

http://www.ningoo.net/html/2009/performance_test_tool_sysbench.html

文章知识点与官方知识档案匹配,可进一步学习相关知识
PostgreSQL技能树首页概览6089 人正在系统学习中

[转帖]Sysbench - 一种系统性能benchmark的更多相关文章

  1. Sysbench - 一种系统性能benchmark

    SysBench是一款开源的.跨平台的.模块化的.多线程的性能测试工具,通过高负载地运行在数据库上,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.用于评估操作系统的性能参数. 1      ...

  2. [转帖]TPC-C解析系列01_TPC-C benchmark测试介绍

    TPC-C解析系列01_TPC-C benchmark测试介绍 http://www.itpub.net/2019/10/08/3334/ 学习一下. 自从蚂蚁金服自研数据库OceanBase获得TP ...

  3. [转帖]Docker五种存储驱动原理及应用场景和性能测试对比

    Docker五种存储驱动原理及应用场景和性能测试对比 来源:http://dockone.io/article/1513 作者: 陈爱珍 布道师@七牛云   Docker最开始采用AUFS作为文件系统 ...

  4. 【转帖】四种BI 开源工具介绍-SpagoBI,openI,JasperSoft,Pentaho

    四种BI 开源工具介绍-SpagoBI,openI,JasperSoft,Pentaho 1 BI系统的简述 从技术角度来说 BI 包含了 ETL.DW.OLAP.DM等多环节.简单的说就是把交易系统 ...

  5. [转帖]Docker四种网络模式

    Docker(十四)-Docker四种网络模式 https://www.cnblogs.com/zhuochong/p/10069293.html 计算机网络相关的知识 非常有用.. Docker 安 ...

  6. 【转帖】两种IO模式:Proactor与Reactor模式

    两种IO模式:Proactor与Reactor模式 https://www.cnblogs.com/pigerhan/p/3474217.html. 挺好的说明了epoll和IOCP的区别 在高性能的 ...

  7. sysbench的安装与使用(with MySQL)

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试. 项目主页: http://sysbench.sourceforge.net/ 安装文档htt ...

  8. NtQuerySystemInformation的使用(提供50余种信息)

    今天,我们主要讨论的是一个函数NtQuerySystemInformation(ZwQuerySystemInformation).当然,你不要小看这么一个函数,它却为我们提供了丰富的系统信息,同时还 ...

  9. mysql sysbench基准测试

    git项目地址: https://github.com/akopytov/sysbench 利用sysbench很容易对mysql做性能基准测试(当然这个工具很强大,除了测试主流数据库性能,还能测试其 ...

  10. 利用sysbench进行MySQL OLTP基准测试

      Preface       In order to know clearly about the real performance threshold of database server,we ...

随机推荐

  1. 28、Flutter Key详解

    在Flutter中,Key是不能重复使用的,所以Key一般用来做唯一标识.组件在更新的时候,其状态的保 存主要是通过判断组件的类型或者key值是否一致.因此,当各组件的类型不同的时候,类型已经足够 用 ...

  2. Redis系列(二):解读redis.conf文件、配置、初步使用

    一.解读redis.conf配置文件 # redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k =&g ...

  3. 案例解析丨 Spark Hive 自定义函数应用

    摘要:Spark目前支持UDF,UDTF,UDAF三种类型的自定义函数. 1. 简介 Spark目前支持UDF,UDTF,UDAF三种类型的自定义函数.UDF使用场景:输入一行,返回一个结果,一对一, ...

  4. 小熊派开发实践丨小熊派+合宙Cat.1接入云服务器

    摘要:使用小熊派开发板,以合宙的AIR724为通信模组(Cat.1),以AT指令方式,通过mqtt协议接入云服务器. 本贴使用小熊派开发板+合宙的Air724(Cat.1模组),接入自己搭建的EMQ服 ...

  5. SARIF:DevSecOps工具与平台交互的桥梁

    摘要:静态扫描工具融入在DevSecOps的开发过程中,对提高产品的整体的安全水平发挥着重要的作用.为了获取安全检查能力覆盖的最大化,开发团队通常会引入多个安全扫描工具.为了降低各种分析工具的结果汇总 ...

  6. Solon 框架,maven 单月下载量突破 200 万了!

    Solon 是什么开源项目? 一个,Java 新的生态型应用开发框架.它从零开始构建,有自己的标准规范与开放生态(历时五年,已有全球第二级别的生态规模).与其他框架相比,它解决了两个重要的痛点:启动慢 ...

  7. cxf 动态调用 WebService No compiler detected, make sure you are running on top of a JDK instead of a JRE

    WebService cxf No compiler detected, make sure you are running on top of a JDK instead of a JRE [202 ...

  8. Codeforces Round 908 (Div. 2)

    总结 T1 题目大意: A,B两人玩游戏,游戏规则如下: 整场游戏有多轮,每轮游戏先胜 \(X\) 局的人获胜,每场游戏先胜 \(Y\) 局的人获胜. 你在场边观看了比赛,但是你忘记了 \(x\) 和 ...

  9. 初识QT、窗口以及信号槽

    1 基本规范: 无论是写什么样的代码,第一步都应该是创建一个程序对象 #include <QApplication> int main(int argc, char *argv[]) { ...

  10. COOIS增强

    一.订单抬头增强 二.结构添加字段 添加ZGCWL字段 三.BADI增强 四.其他界面增强 不同的界面,选择不同的修改结构 抬头 ct_ioheader 组件 ct_ioopcomp 工序 ct_io ...