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.下载

下载地址:http://sourceforge.net/projects/sysbench/

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

2.安装

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

[root@RedHat sysbench-0.4.8]# ./configure --without-mysql

[root@RedHat sysbench-0.4.8]# make

[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帮助

[root@RedHat sysbench-0.4.8]# sysbench

Missing required command argument.

Usage:

sysbench [general-options]... --test=<test-name> [test-options]... command

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]

--thread-stack-size=SIZE   size of stack per thread [32K]

--init-rng=[on|off]        initialize random number generator [off]

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

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

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

[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测试

1. 文件IO测试

[root@RedHat test]# sysbench --test=fileio help

sysbench v0.4.8:  multi-threaded system evaluation benchmark

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,fastmmap,slowmmap} [sync]

--file-extra-flags=STRING  additional flags to use on opening 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 poss ible (0- don't merge) [0]

--file-rw-ratio=N             reads/writes ratio for combined test [1.5]

[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

测试案例:

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

可以获取读写速度~

[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw prepare (准备测试文件)

sysbench v0.4.8:  multi-threaded system evaluation benchmark

128 files, 4096Kb each, 512Mb total

Creating files for the test...

[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw run (运行测试)

sysbench v0.4.8:  multi-threaded system evaluation benchmark

Running the test with following options:

Number of threads: 2

Extra file open flags: 0

128 files, 4Mb each

512Mb total file size

Block size 16Kb

Number of random requests for random IO: 10000

Read/Write ratio for combined random IO test: 1.50

Periodic FSYNC enabled, calling fsync() each 100 requests.

Calling fsync() at the end of test, Enabled.

Using synchronous I/O mode

Doing random r/w test

Threads started!

Done.

Operations performed:  6000 Read, 4000 Write, 12800 Other = 22800 Total

Read 93.75Mb  Written 62.5Mb  Total transferred 156.25Mb  (3.2979Mb/sec)

211.07 Requests/sec executed

Test execution summary:

total time:                          47.3783s

total number of events:              10000

total time taken by event execution: 36.6912

per-request statistics:

min:                            0.0000s

avg:                            0.0037s

max:                            0.2687s

approx.  95 percentile:         0.0230s

Threads fairness:

events (avg/stddev):           5000.0000/180.00

execution time (avg/stddev):   18.3456/0.19

[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw cleanup (清除测试文件)

sysbench v0.4.8:  multi-threaded system evaluation benchmark

Removing test files...

[root@RedHat test]#

2. CPU性能测试

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

[root@RedHat ~]# sysbench --test=cpu help

sysbench v0.4.8:  multi-threaded system evaluation benchmark

cpu options:

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

[root@RedHat ~]#

参数解析

参数名

描述

--cpu-max-prime=N

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

测试案例

[root@RedHat ~]# sysbench --test=cpu --cpu-max-prime=20000 run

sysbench v0.4.8:  multi-threaded system evaluation benchmark

Running the test with following options:

Number of threads: 1

Doing CPU performance benchmark

Threads started!

Done.

Maximum prime number checked in CPU test: 20000

Test execution summary:

total time:                          124.1761s

total number of events:              10000

total time taken by event execution: 123.3658

per-request statistics:

min:                            0.0051s

avg:                            0.0123s

max:                            0.1908s

approx.  95 percentile:         0.0171s

Threads fairness:

events (avg/stddev):           10000.0000/0.00

execution time (avg/stddev):   123.3658/0.00

[root@RedHat ~]#

3.内存性能测试

[root@RedHat ~]# sysbench --test=memory help

sysbench v0.4.8:  multi-threaded system evaluation benchmark

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]

[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;

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

4.线程性能测试

[root@RedHat ~]# sysbench --test=threads help

sysbench v0.4.8:  multi-threaded system evaluation benchmark

threads options:

--thread-yields=N      number of yields to do per request [1000]

--thread-locks=N       number of locks per thread [8]

[root@RedHat ~]#

参数名

描述

--thread-yields=N

内存块大小,默认为1K

--thread-locks=N

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

测试案例

[root@RedHat test]# sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run

sysbench v0.4.8:  multi-threaded system evaluation benchmark

Running the test with following options:

Number of threads: 64

Doing thread subsystem performance test

Thread yields per test: 100 Locks used: 2

Threads started!

Done.

Test execution summary:

total time:                          24.8159s

total number of events:              10000

total time taken by event execution: 1575.5529

per-request statistics:

min:                            0.0002s

avg:                            0.1576s

max:                            2.0173s

approx.  95 percentile:         0.5627s

Threads fairness:

events (avg/stddev):           156.2500/12.62

execution time (avg/stddev):   24.6180/0.08

[root@RedHat test]#

5互斥体性能测试

[root@RedHat ~]# sysbench --test=mutex help

sysbench v0.4.8:  multi-threaded system evaluation benchmark

mutex options:

--mutex-num=N        total size of mutex array [4096]

--mutex-locks=N      number of mutex locks to do per thread [50000]

--mutex-loops=N      number of empty loops to do inside mutex lock [10000]

[root@RedHat ~]#

参数名

描述

--mutex-num=N

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

--mutex-locks=N

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

--mutex-loops=N

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

测试案例

[root@RedHat test]# sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run

sysbench v0.4.8:  multi-threaded system evaluation benchmark

Running the test with following options:

Number of threads: 16

Doing mutex performance test

Threads started!

Done.

Test execution summary:

total time:                          0.0482s

total number of events:              16

total time taken by event execution: 0.2271

per-request statistics:

min:                            0.0015s

avg:                            0.0142s

max:                            0.0312s

approx.  95 percentile:         0.0126s

Threads fairness:

events (avg/stddev):           1.0000/0.00

execution time (avg/stddev):   0.0142/0.01

[root@RedHat test]#

6 OLTP测试

不做分析了

参考资料:

http://sysbench.sourceforge.net/

http://blog.csdn.net/qiudakun/article/details/6891136

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

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

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

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

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

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

  3. mysql sysbench基准测试

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

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

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

  5. Flume FileChannel优化(扩展)实践指南

    本文系微博运维数据平台(DIP)在Flume方面的优化扩展经验总结,在使用Flume FileChannel的场景下将吞吐率由10M/s~20M/s提升至80M/s~90M/s,分为四个部分进行介绍: ...

  6. JMH--一款由OpenJDK开发的基准测试工具

    什么是JMH JMH 是 OpenJDK 团队开发的一款基准测试工具,一般用于代码的性能调优,精度甚至可以达到纳秒级别,适用于 java 以及其他基于 JVM 的语言.和 Apache JMeter ...

  7. Linux下一种简单易行的cpu benchmark方法

    用Linux自带的bc计算器计算pi值的一种benchmark手段   其实很简单,就是一行命令. time echo “scale=5000; 4*a(1)” | bc -l -q time是计时程 ...

  8. Ext4 ReiserFS Btrfs 等7种文件系统性能比拼

    2009年02月04日     为了满足广大群众的热切需求,今天做了 Ext2.Ext3.Ext4.XFS.JFS.ReiserFS 和 Btrfs 的全面性能测试,对比结果如下:     本次测试所 ...

  9. 用systemtap对sysbench IO测试结果的分析1

    http://www.actionsky.com/docs/archives/171  2016年5月6日  黄炎 近期在一些简单的sysbench IO测试中, 遇到了一些不合常识的测试结果. 从结 ...

随机推荐

  1. gcc -L -l的使用

    -l参数就是用来指定程序要链接的库,-l参数紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so ...

  2. Java程序性能分析工具Java VisualVM(Visual GC)—程序员必备利器

    VisualVM 是一款免费的\集成了多个JDK 命令行工具的可视化工具,它能为您提供强大的分析能力,对 Java 应用程序做性能分析和调优.这些功能包括生成和分析海量数据.跟踪内存泄漏.监控垃圾回收 ...

  3. 封装Socket.BeginReceive/EndReceive支持Timeout简介

    .NET中的Socket类提供了网络通信常用的方法,分别提供了同步和异步两个版本,其中异步的实现是基于APM异步模式实现,即BeginXXX/EndXXX的方式.异步方法由于其非阻塞的特性,在需考虑程 ...

  4. (转)url重写

    使用URLRewriter.dll后,根本不需要使用任何代码,我之前做的项目就是用的做URL重写的,其实不是进化,其实表面上看是.html扩展名而已,当然你还可以用其他的任意扩展名下面是你的配置 &l ...

  5. 生成getter()、setter()方法去掉变量前缀

    当定义的变量名有前缀但是不想在生成它的getter()和setter方法的时候让前缀出现,比如今天项目的部分代码: public class Crime { private UUID mId; //标 ...

  6. 爆炸!iOS资源大礼包(持续更新...)

    今天为大家整理了一些关于iOS学习的干货,献给正在奋斗的你们,首先声明一下,在整理的过程中参考了大量的博客和文章,知识的分享终究会增值,在此表示感谢,希望这篇文章给大家带来帮助. 基础部分: C语言教 ...

  7. 深入理解REST与Servlet架构的区别

    本身这个比较是个伪命题,因为 RESTful Service是一个软件架构“风格”, 而servlet是java 服务端的一种技术 之所以把它们拿出来比较,是由于它们代表了两个时代的技术风格与架构.下 ...

  8. POJ 3273 Monthly Expense(二分查找+边界条件)

    POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...

  9. uva 371 - Ackermann Functions

    #include <cstdio> int main() { long int F, S, I, Count, Value, Max, J; while(scanf("%ld % ...

  10. javascript学习教程之---如何从一个tab切换到banner幻灯片的转换

    一个简单的tab切换代码: <!doctype html> <html> <head> <meta charset="utf-8"> ...