【原创】sysbench 使用总结

  1. 云栖社区>
  2. 博客>
  3. 正文

【原创】sysbench 使用总结

摩云飞 2016-05-11 13:49:55 浏览1888
展开阅读全文
      sysbench 是一款多线程系统压测工具。可以根据影响数据库服务器性能的各种因素来评估系统的性能。可以用来测试文件I/O,操作系统调度器,内存分配和传输速度,POSIX 线程,以及数据库服务器等。sysbench 支持 Lua 脚本语言以实现更加灵活的设置。属于全能型的测试工具。 

========= 我是分割线 ========== 

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

1. CPU 基准测试 

测试内容:测试计算素数知道某个最大值所需的时间。 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
[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 ~]#
执行结果: 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[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
 
[root@Betty ~]#

2. 文件 I/O 基准测试 

用于测试系统在不同 I/O 负载下的性能。 

a. 准备阶段 
      生成测试用的数据文件,要求生成的数据文件至少要比内存大,否则数据由于被操作系统缓存而无法体现 I/O 密集型工作负载。 
1
2
3
4
5
6
[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...
[root@Betty ~]#
查看生成的文件,共 128 个文件块(80M * 128): 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[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
[root@Betty ~]#

b. 运行阶段 
读取前一步生成的数据文件进行测试。 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[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
 
[root@Betty ~]#

c. 清除阶段 
删除第一步生成的测试文件。 
1
2
3
4
5
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark
 
Removing test files...
[root@Betty ~]#


3. OLTP 基准测试 

测试内容:模拟事务处理系统的工作负载。使用一张超过百万行记录的表。

a. 生成表 

1
2
3
4
5
6
[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'...
[root@Betty ~]#

查看 MySQL 数据库内容: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)
 
mysql>

b. 运行测试
8 线程并发、只读模式、测试时长为 60s 。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[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
 
[root@Betty ~]#
测试结果信息中包括: 
  • 总的事务数/每秒事务数
  • 时间统计信息(最小、平均、最大响应时间、95% 百分比响应时间
  • 线程公平性统计信息,用于表示模拟负载的公平性

c. 删除表 
1
2
3
4
5
6
[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.
[root@Betty ~]#


网友评论

登录后评论
0/500
评论
摩云飞
+ 关注