LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > Linux教程 >

sysbench使用总结

时间:2013-08-14 13:57来源:开源中国社区 编辑:moooofly 点击:
sysbench 是一款多线程系统压测工具。可以根据影响数据库服务器性能的各种因素来评估系统的性能。可以用来测试文件I/O,操作系统调度器,内存分配和传输速度,POSIX 线程,以及数据
sysbench 是一款多线程系统压测工具。可以根据影响数据库服务器性能的各种因素来评估系统的性能。可以用来测试文件I/O,操作系统调度器,内存分配和传输速度,POSIX 线程,以及数据库服务器等。sysbench 支持 Lua 脚本语言以实现更加灵活的设置。属于全能型的测试工具。

以下内容参考自《高性能 MySQL 》的第二章。

1. CPU 基准测试
测试内容:测试计算素数知道某个最大值所需的时间。
[root@Betty ~]# cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.40
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6584.95
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 3
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]
执行结果:
[root@Betty ~]# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 0.4.12:  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:                          25.6727s
    total number of events:              10000
    total time taken by event execution: 25.6696
    per-request statistics:
         min:                                  2.56ms
         avg:                                  2.57ms
         max:                                  5.36ms
         approx.  95 percentile:               2.57ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   25.6696/0.00
2. 文件 I/O 基准测试
用于测试系统在不同 I/O 负载下的性能。
a. 准备阶段
生成测试用的数据文件,要求生成的数据文件至少要比内存大,否则数据由于被操作系统缓存而无法体现 I/O 密集型工作负载。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G prepare  
sysbench 0.4.12:  multi-threaded system evaluation benchmark

128 files, 81920Kb each, 10240Mb total
Creating files for the test...
查看生成的文件,共 128 个文件块(80M * 128):
[root@Betty ~]# ll
total 10498016
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.0
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.1
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.10
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.100
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.109
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.11
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.110
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.119
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.12
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.120
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.127
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.13
...
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.19
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.2
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.20
...
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.98
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.99
b. 运行阶段
读取前一步生成的数据文件进行测试。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Initializing random number generator from timer.


Extra file open flags: 0
128 files, 80Mb each
10Gb 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:  25981 Read, 17320 Write, 55424 Other = 98725 Total
Read 405.95Mb  Written 270.62Mb  Total transferred 676.58Mb  (2.255Mb/sec)
  144.32 Requests/sec executed

Test execution summary:
    total time:                          300.0315s
    total number of events:              43301
    total time taken by event execution: 176.0072
    per-request statistics:
         min:                                  0.01ms
         avg:                                  4.06ms
         max:                                 76.53ms
         approx.  95 percentile:              13.04ms

Threads fairness:
    events (avg/stddev):           43301.0000/0.00
    execution time (avg/stddev):   176.0072/0.00
c. 清除阶段
删除第一步生成的测试文件。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Removing test files...
3. OLTP 基准测试
测试内容:模拟事务处理系统的工作负载。使用一张超过百万行记录的表。
a. 生成表
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
查看 MySQL 数据库内容:
mysql> show tables;      
+----------------+
| Tables_in_test |
+----------------+
| sbtest         | 
+----------------+
1 row in set (0.00 sec)

mysql> 
mysql> 
mysql> select count(*) from sbtest;
+----------+
| count(*) |
+----------+
|  1000000 | 
+----------+
1 row in set (0.19 sec)
b. 运行测试
8 线程并发、只读模式、测试时长为 60s 。
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 --db-driver=mysql --mysql-socket=/tmp/mysql.sock run  
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only 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 7 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            1442434
        write:                           0
        other:                           206062
        total:                           1648496
    transactions:                        103031 (1717.12 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 1442434 (24039.63 per sec.)
    other operations:                    206062 (3434.23 per sec.)

Test execution summary:
    total time:                          60.0023s
    total number of events:              103031
    total time taken by event execution: 479.5035
    per-request statistics:
         min:                                  1.49ms
         avg:                                  4.65ms
         max:                               3493.99ms
         approx.  95 percentile:               2.41ms

Threads fairness:
    events (avg/stddev):           12878.8750/1194.34
    execution time (avg/stddev):   59.9379/0.01
测试结果信息中包括:
  • 总的事务数/每秒事务数
  • 时间统计信息(最小、平均、最大响应时间、95% 百分比响应时间)
  • 线程公平性统计信息,用于表示模拟负载的公平性
c. 删除表
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --db-driver=mysql --mysql-socket=/tmp/mysql.sock cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Dropping table 'sbtest'...
Done.

转载请保留固定链接: https://linuxeye.com/Linux/1894.html

------分隔线----------------------------
标签:sysbench
栏目列表
推荐内容