sysbench服务器性能测试

转载:原文出处 https://blog.51cto.com/u_13972012/6000395

一、sysbench简介

sysbench是一款开源的​ ​多线程​​​ ​性能测试​​工具,可以执行cpu/内存/线程/IO/数据库等方面的性能测试,包含以下几种测试:

cpu性能
磁盘IO性能
调度程序性能
内存分配及传输速度
POSIX线程性能
数据库性能(OLTP基准测试)数据库目前支持MySQL/PostgreSQL/Oracle

二、开源网站

https://github.com/akopytov/sysbench

三、配置参数详解

[root@server1 home]# sysbench --help

Usage:

  sysbench [options]... [testname] [command]
General options(常用选项):
  --threads=N                     //创建测试线程的数目。默认为1                
  --events=N                      //设置期望执行的时间总数。默认是0,不限制
  --time=N                        //最大执行时间,单位是s。默认是0,不限制。               
  --forced-shutdown=STRING        //超过max-time强制中断。默认是off。  
  --thread-stack-size=SIZE        //每个线程的堆栈大小。默认是32k。
  --rate=N                        //平均事物速率。0表示不限速
  --report-interval=N             //以秒为单位定期报告具有指定间隔的统计信息。0禁用中间报告
  --report-checkpoints=[LIST,...] //转储全部统计数据并在指定时间点重置所有计数器。参数是一个以逗号分隔的值列表,表示从测试开始到必须执行报告检查点所经过的时间(以秒为单位)。默认情况下报表检查点是关闭的。
  --debug[=on|off]                //打印更多的调试信息,默认关闭
  --validate[=on|off]             //在可能的情况下执行验证检查,默认关闭
  --help[=on|off]                 //获取help帮助,以获取参数使用方式
  --version[=on|off]              //查看当前版本信息
  --config-file=FILENAME          //包含命令行选项的文件

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        //日志详细级别 {5 - debug, 0 - 仅critical messages}  默认值 3
  --percentile=N       //延时统计(latency statistics)中,需要计算的百分比 (1-100)。设置为0表示禁用百分比值计算。 Use the special
  --histogram[=on|off] //在报告中打印延迟直方图,默认关闭

General database options(常用数据库选项):

  --db-driver=STRING  //设置程序使用的数据驱动。默认值mysql;
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
  --db-debug[=on|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]             //使用SSL连接,默认关闭
  --mysql-ssl-cipher=STRING        //为SSL连接使用特定的密码
  --mysql-compression[=on|off]     //使用压缩,默认关闭
  --mysql-debug[=on|off]           //跟踪所有客户端库调用信息,默认关闭
  --mysql-ignore-errors=[LIST,...] //要忽略的错误列表,或"all" [1213,1020,1205]
  --mysql-dry-run[=on|off]         试运行,假装所有MySQL客户端API调用都是成功的,而不执行它们,默认关闭

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

四、开始测试

4.1 cpu性能测试

常用参数:

​​--cpu-max-prime: 素数生成数量的上限 (默认值10000)​​

​​--threads: 线程数(默认值1)​​

​​--time: 运行时长,单位秒​​

​​--events: event上限次数,默认值为0,若设置100,则表示当完成100次event后,即使时间还有剩,也停止运行


执行命令进行cpu测试,cpu测试主要是进行素数的加法运算,下图中指定了最大的质数发生器数量为20000,我的测试服务器(1C)执行时间大约为9.9s:

//素数上限2万,默认10秒,2个线程
sysbench --test=cpu --cpu-max-prime=20000 --threads=2 run
Running the test with following options:

Number of threads: 2           //指定线程数为1(默认值)

Initializing random number generator from current time

Prime numbers limit: 20000     //每个线程产生的素数上限均为2万个

Initializing worker threads...

Threads started!

CPU speed:

    events per second:   387.24  //所有线程每秒完成了 387.24次event

General statistics:

    total time:                          10.0046s   //共耗时10秒

    total number of events:              3875       //10秒内所有线程一共完成了3875次event

Latency (ms):

         min:                                    2.12     // 完成1次event的最少耗时2.12毫秒

         avg:                                    5.15     // 所有event的平均耗时5.15毫秒

         max:                                   25.78     // 完成1次event的最多耗时25.78毫秒

         95th percentile:                       14.73     // 95%次event在14.73秒毫秒内完成

         sum:                                 19956.33    // 所有线程的耗时总和(每个线程耗时10秒,2个线程叠加耗时就是20秒)

Threads fairness:

    events (avg/stddev):           1937.5000/1.50  // 平均每个线程完成 1937次event,标准差为1.5

    execution time (avg/stddev):   9.9782/0.0     // 每个线程平均耗时9.9秒,标准差为0
event:完成了几轮的素数计算;

stddev(标准差):在相同时间内,多个线程分别完成的素数计算次数是否稳定,如果数值越低,则表示多个线程的结果越接近(越稳定)。该参数对于单线程无意义。

性能指标:

如果有2台服务器进行cpu性能对比,当素数上限和线程数一致时:
相同时间,比较event
相同event,比较时间

4.2 线程测试

常用参数:

​​--thread-yields:每个请求产生多少线程,默认值100​​

​​--thread-locks: 每个线程锁的数量,默认值8​​

​​--num-threads:  发送请求线程的数量​​
// 64个测试线程请求,每个线程请求产生100个数量,每个线程的锁数量为2
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:

Number of threads: 64    //指定线程数为64

Initializing random number generator from current time

Initializing worker threads...

Threads started!

General statistics:

    total time:                          10.0072s     //共耗时10秒

    total number of events:              46303        //10秒内所有线程一共完成了46303次event


Latency (ms):

         min:                                    0.19     // 完成1次event的最少耗时0.19毫秒

         avg:                                   13.83     // 所有event的平均耗时13.83毫秒

         max:                                 4636.20     // 完成1次event的最多耗时4636毫秒

         95th percentile:                       36.89     // 95%次event在36.89毫秒内完成

         sum:                               640152.82     // 所有线程的耗时总和(每个线程耗时10秒,64个线程叠加耗时就是64秒(1分04s)


Threads fairness:

    events (avg/stddev):           723.4844/1075.89       // 平均每个线程完成 723次event,标准差为1075

    execution time (avg/stddev):   10.0024/0.00            // 每个线程平均耗时10秒,标准差为0
性能指标:

线程并发执行,循环响应信号量花费的时间越少越好。

4.3 磁盘IO性能测试

常用参数:

​​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 //使用额外的标志来打开文件{sync,dsync,direct} 。默认为空​​
​​file-fsync-freq=N       // 当请求数达到多少时执行fsync()刷新,默认100,0代表过程中不执行​​
​​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的性能测试都需要做prepare,run,cleanup这三步,准备数据,跑测试,删除数据。在准备阶段创建测试所需数据,在清理阶段删除这些数据。

// 准备测试数据
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
// 磁盘IO压测测试(指定最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读。)
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:

Number of threads: 16

Initializing random number generator from current time

Extra file open flags: (none)

128 files, 24MiB each

3GiB total file size

Block size 16KiB

Number of IO requests: 0

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

Initializing worker threads...

Threads started!

File operations:

    reads/s:                      11466.89    //读操作耗时/s
 
    writes/s:                     7644.56     //写操作耗时/s

    fsyncs/s:                     24661.17    //fsyncs操作耗时/s

Throughput:

    read, MiB/s:                  179.17      //读的速度/s
  
    written, MiB/s:               119.45      //写的速度/s

General statistics:

    total time:                          10.0054s   //共耗时时间/s

    total number of events:              435984     //共完成的event总数

Latency (ms):

         min:                                    0.00   //最小耗时

         avg:                                    0.37   //平均耗时
 
         max:                                   80.65   //最大耗时

         95th percentile:                        1.86   //95% event操作耗时

         sum:                               159664.15   //所有线程的耗时总和

Threads fairness:

    events (avg/stddev):           27249.0000/364.02  //平均每个线程完成events数/标准差

    execution time (avg/stddev):   9.9790/0.00        //平均每个线程执行时间/标准差
// 清除测试数据
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup
性能指标:

1)衡量磁盘io性能,一般主要看以下几个指标:

IOPS:每秒读/写次数,单位为次(计数)
吞吐量:每秒的读写数据量,单位为MB/s
时延:I/O 操作的发送时间到接收确认所经过的时间

2)不同场景下read/s, writes/s, readMiB/s和writtent MiB/s越大越好

4.4 内存测试

常用参数:

​​memory-block-size=SIZE 测试时内存块大小 [1K]​​

​​memory-total-size=SIZE 传输数据总大小 [100G]​​

​​memory-scope=STRING 内存访问范围{global,local}。默认是global​​

​​memory-oper=STRING 内存操作类型 {read, write, none} [write]​​

​​memory-access-mode=STRING 存储器存取方式 {seq:顺序,rnd:随机}[默认:seq]​​

sysbench内存性能测试,主要是针对不同大小的块进行连续读写或者随机读写操作。在内存性能测试中,events指的是读/写一个内存块。

// 指定本次测试整个过程是在内存中传输 3G 的数据量,每个 block 大小为 8K,存储器存取方式为随机
sysbench --test=memory --memory-block-size=8k --memory-total-size=3G  --memory-access-mode=rnd  run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:

Number of threads: 1    //指定默认线程1

Initializing random number generator from current time

Running memory speed test with the following options:

  block size: 8KiB     #block块大小8k

  total size: 3072MiB  #总大小8G

  operation: write     #内存操作类型(写)

  scope: global        #内存访问范围global

Initializing worker threads...

Threads started!

Total operations: 393216 (112796.84 per second)  //每秒处理大小

3072.00 MiB transferred (881.23 MiB/sec)         //每秒传输量(881/s)

General statistics:

    total time:                          3.4843s   //总耗时3.4s

    total number of events:              393216    //总events数,即读写一个内存块


Latency (ms):

         min:                                    0.00   //最小耗时,这里等于0是因为内存块太小,返回的结果数值精度不够

         avg:                                    0.01   //平均耗时

         max:                                   14.63   //最大耗时

         95th percentile:                        0.01   //95%events耗时范围

         sum:                                 3301.64   //所有线程总耗时

Threads fairness:

    events (avg/stddev):           393216.0000/0.00   //平均每个线程完成events数/标准差

    execution time (avg/stddev):   3.3016/0.00        //平均每个线程执行时间/标准差
性能指标:

以不同块的大小传输一定得数量的数据吞吐量越大越好。
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值