【原创】sysbench 使用总结

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:
      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 ~] #


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
5月前
|
SQL 关系型数据库 MySQL
MySQL必知必会—读书笔记
MySQL必知必会—读书笔记
|
12月前
|
关系型数据库 MySQL
Sysbench使用之二fileio
源码编译的安装步骤如下
|
存储 关系型数据库 MySQL
|
关系型数据库 MySQL 数据库
|
SQL 关系型数据库 MySQL
|
SQL 关系型数据库 MySQL
|
SQL Oracle 关系型数据库
|
SQL 存储 安全
mysql必知必会读书笔记
mysql必知必会读书笔记
mysql必知必会读书笔记