Sysbench简介和测试

来源:互联网 发布:linkin 大数据 编辑:程序博客网 时间:2024/05/21 14:07

一、sysbench简介
sysbench是一个模块化的、跨平台、开源的多线程基准测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试,主要用于评估测试各种不同系统参数下的数据库负载情况,数据库目前支持MySQL/Oracle/PostgreSQL;
它主要包括以下几种方式的测试:   
1. cpu              处理器性能
2. threads      线程调度器性能  
3. mutex         互斥锁性能
4. memory     内存分配及传输速度   
5. fileio            文件IO性能   
6. oltp              数据库性能(OLTP基准测试) 


二、语法以及注意点
sysbench  参数(N个)  执行类型
sysbench --项 =值...  run/prepare/clearup
当执行完毕后clearup,以免文件堆积。


三、测试
测试环境如下
系统      :Centos6.5
数据库  :MySQL 5.6.25
工具      :Sysbench 0.5

1,CPU
测试计算素数直到某个最大值所需要的时间。
[root@localhost sysbench]# sysbench --test=cpu --cpu-max-prime=2000 run

Maximum prime number checked in CPU test: 200000

Test execution summary:
    total time:                          286.5703s
    total number of events:              10000
    total time taken by event execution: 285197.4463
    per-request statistics:
         min:                                109.67ms
         avg:                              28519.74ms
         max:                              36760.02ms
         approx.  95 percentile:           31751.56ms

Threads fairness:
    events (avg/stddev):           9.7656/0.81
    execution time (avg/stddev):   278.5131/6.05

我们只需要关心测试的总时间(total time)即可。


2,THREADS
测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用。
[root@localhost sysbench]# sysbench --test=threads --num-threads=64 run 
Number of threads: 64

Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.

Test execution summary:
    total time:                          4.5845s
    total number of events:              10000
    total time taken by event execution: 291.9995
    per-request statistics:
         min:                                  0.76ms
         avg:                                 29.20ms
         max:                                152.71ms
         approx.  95 percentile:              71.11ms

Threads fairness:
    events (avg/stddev):           156.2500/5.81
    execution time (avg/stddev):   4.5625/0.02

3,MUTEX
测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。
[root@localhost sysbench]#sysbench --test=mutex --num-threads=16 --mutex-num=2048  --mutex-locks=1000000 --mutex-loops=5000 run

Number of threads: 16

Doing mutex performance test
Threads started!
Done.

Test execution summary:
    total time:                          3.6123s
    total number of events:              16
    total time taken by event execution: 57.6636
    per-request statistics:
         min:                               3580.79ms
         avg:                               3603.98ms
         max:                               3610.94ms
         approx.  95 percentile:         10000000.00ms

Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   3.6040/0.01

4,MEMORY
内存的连续读写性能
[root@localhost sysbench]# sysbench --test=memory --memory-block-size=8K --memory-total-size=2G  --num-threads=16 run
上面这条语句指定了整个测试过程中,传输2G的数据量,每个block的大小为8K(大写的K)。 测试结果如下所示,我们最关心的是吞吐量(8030.45MB/sec),和后面的磁盘io 测试结果比较可知,内存的连续读写比磁盘的连续读写快十几倍。

Number of threads: 16

Doing memory operations speed test
Memory block size: 8K

Memory transfer size: 2048M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 262144 (1027897.89 ops/sec)

2048.00 MB transferred (8030.45 MB/sec)

Test execution summary:
    total time:                          0.2550s
    total number of events:              262144
    total time taken by event execution: 3.1911
    per-request statistics:
         min:                                  0.00ms
         avg:                                  0.01ms
         max:                                 29.55ms
         approx.  95 percentile:               0.00ms

Threads fairness:
    events (avg/stddev):           16384.0000/926.14
    execution time (avg/stddev):   0.1994/0.02

5,FILEIO
文件IO(fileio)基准测试可以测试系统在不同IO负载下的性能。这对于比较不同的硬盘驱动器,不同的RAID 卡,不同的RAID 模式,都很有帮助。可以根据测试结果调整IO子系统。文件IO基准测试模拟了很多InnoDB 的IO特性。
测试的第一步是准备(Prepare)阶段,生成测试用到的数据文件,生成的数据文件至少要比内存大。 如果文件中的数据能完全放入内存中,则操作系统 缓存大部分的数据,导致测试结果无法体现IO密集型的工作负载。
(1),准备数据,通过下面的命令创建一个数据集:
[root@localhost sysbench]# sysbench --test=fileio --file-total-size=40G prepare
这个命令会在当前工作目录下创建测试文件,后续的运行(run)阶段将通过读写这些文件进行测试。 第二步就是运行(run)阶段,针对不同的IO 类型有不同的测试选项:
    seqwr 顺序写入
    seqrewr 顺序重写
    seqrd 顺序读取
    rndrd 随机读取
    rndwr 随机写入
    rndrw 混合随机读/写
(2),执行测试,下面的命令运行文件I/O混合随机读/写基准测试:
[root@localhost sysbench]# sysbench --test=fileio --file-total-size=40G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run

Extra file open flags: 0
128 files, 240Mb each
30Gb total file size
Block size 16Kb
Number of random requests for random IO: 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
Threads started!
Time limit exceeded, exiting...
Done.

Operations performed:  15900 Read, 10600 Write, 33842 Other = 60342 Total
Read 248.44Mb  Written 165.62Mb  Total transferred 414.06Mb  (1.3802Mb/sec)
   88.33 Requests/sec executed

Test execution summary:
    total time:                          300.0074s
    total number of events:              26500
    total time taken by event execution: 164.1563
    per-request statistics:
         min:                                  0.01ms
         avg:                                  6.19ms
         max:                                315.51ms
         approx.  95 percentile:              15.83ms

Threads fairness:
    events (avg/stddev):           26500.0000/0.00
    execution time (avg/stddev):   164.1563/0.00

输出结果中包含了大量的信息。和IO子系统密切相关的包括每秒请求数和总吞吐量。在上述例子中, 每秒请求数是88.33 Requests/sec , 吞吐量是1.3802Mb/sec 。另外,时间信息也非常有用, 尤其是大约95%的时间分布。这些数据对于评估磁盘性能十分有用。
测试完成以后,运行清除(cleanup)操作删除第一步生成的测试文件。
sysbench --test=fileio --fil-total-size=30G cleanup

6,OLTP
下面来看最重要也是最复杂的测试————oltp。oltp 基准测试模拟了一个简单的事物处理系统的工作负载。
常用参数:
mysql
--mysql-host=STRONG
数据库主机

--mysql-user=STRING   
数据库用户名

--mysql-password=STRING   
数据库用户名密码

--mysql-socket=STRING   
数据库连接套接字路径

--mysql-db=STRING   
数据库名

--oltp-table-count=N         
测试表的个数。

--oltp-table-size=N        
表的数据行数

--oltp-test-mode=STRING    
用以指定测试模式,取值有(simeple,complex,nontrx),默认是complex。不同模式会执行不同的语句
simeple: 简单模式,执行简单的select
complex: Advanced transactional,在事务中,包含多表连接/多种范围的增删改查,复杂的SQL
nontrx : Non-transactional,无事务,简单的增删改查

--oltp-nontrx-mode=STRING   
查询类型对于非事务执行模式,取值有(select, update, insert, delete)
oltp-test-mode区别是oltp-nontrx-mode指定操作类型,oltp-test-mode则是操作模式,oltp-test-mode范围比oltp-nontrx-mode
如果要使用select,oltp-read-only参数要设置为on

--oltp-read-only=[on|off]  
只读模式。Update,delete,insert语句不可执行。默认是off

--num-threads=N
表示N个并发线程连接

--max-time=STRING   
执行最大时间(秒),
如果我们需要测试并发条件下,事务执行效率(每秒执行的事务数)和所需时间,就不用设定;
如果我们需要测试在时间范围内,事务执行的效率(每秒执行的事务数),就设定执行时间。

postgresql
--pgsql-host=STRING
数据库地址  

--pgsql-port=N        
数据库端口

--pgsql-user=STRING
用户

--pgsql-password=STRING
密码

--pgsql-db=STRING
使用数据库名称

测试结果解读
OLTP test statistics:
  queries performed:
    read:                            938224    -- 读总数
    write:                           268064    -- 写总数
    other:                           134032    -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
    total:                           1340320    -- 全部总数
  transactions:                        67016  (1116.83 per sec.)    -- 总事务数(每秒事务数)
  deadlocks:                           0      (0.00 per sec.)    -- 发生死锁总数
  read/write requests:                 1206288 (20103.01 per sec.)    -- 读写总数(每秒读写次数)
  other operations:                    134032 (2233.67 per sec.)    -- 其他操作总数(每秒其他操作次数)

General statistics:    -- 一些统计结果
  total time:                          60.0053s    -- 总耗时
  total number of events:              67016    -- 共发生多少事务数
  total time taken by event execution: 479.8171s    -- 所有事务耗时相加(不考虑并行因素)
  response time:    -- 响应时长统计
     min:                                  4.27ms    -- 最小耗时
     avg:                                  7.16ms    -- 平均耗时
     max:                                 13.80ms    -- 最长耗时
     approx.  99 percentile:               9.88ms    -- 超过99%平均耗时

(1) 简单测试一个100W数据的表,执行16各并发连接,默认混合读写
在指定db下创建数据
[root@localhost sysbench]# sysbench --test=tests/db/oltp.lua --oltp-table-size=1000000 --mysql-db=test --mysql-user=root prepare
执行测试
[root@localhost sysbench]# sysbench --test=tests/db/oltp.lua --oltp-table-size=1000000 --mysql-db=test --mysql-user=root  --num-threads=16 run > /tmp/sysbench1.log
#16个并发线程的连接

Number of threads: 16

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
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            26225724
        write:                           9366330
        other:                           3746532
        total:                           39338586
    transactions:                        1873266 (2601.71 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 35592054 (49432.47 per sec.)
    other operations:                    3746532 (5203.42 per sec.)

Test execution summary:
    total time:                          720.0136s
    total number of events:              1873266
    total time taken by event execution: 11506.8251
    per-request statistics:
         min:                                  2.37ms
         avg:                                  6.14ms
         max:                                400.48ms
         approx.  95 percentile:              14.90ms

Threads fairness:
    events (avg/stddev):           117079.1250/275.62
    execution time (avg/stddev):   719.1766/0.01

如上所示,结果中包含三部分信息
总的事务数、每秒事务数;
时间统计信息(最小,平均,最大响应时间,以及95%百分比响应时间);
线程公平性统计信息;
我们可以根据时间段内每秒的事务数(就是经常说是TPS)来优化数据库。

(2)测试一个30个300W数据的表,执行50个并发连接,默认混合读写
在指定db下创建数据
[root@localhost sysbench]# sysbench --test=tests/db/oltp.lua --oltp_table_count=30 --oltp-table-size=1000000 --mysql-db=test --mysql-user=root prepare
执行测试
[root@localhost sysbench]# sysbench --test=tests/db/oltp.lua --oltp_table_count=30 --oltp-table-size=1000000 --mysql-db=test --mysql-user=root  --num-threads=50 run > /tmp/sysbench1.log


0 0
原创粉丝点击