Sysbench 测试 CPU

参数

  • –threads=10:线程数:10,默认为1
  • –time=300:持续时间:5min,300s,默认为 10
  • –events=N:限制执行的event的个数,0表示不限制,默认为 0

模拟场景

模拟多线程竞争场景

1
2
# 模拟 10 个线程 5分钟 内的基准测试,模拟多线程切换问题
$ sysbench --threads=10 --time=300 threads run

基准测试

相同 event ,比较完成时间

1
2
# 并发线程数1个,每个线程每回计算素数个数为1000个,此次测试最大events数为100000
$ sysbench --test=cpu  --threads=1  --max-requests=100000 --cpu-max-prime=1000 run

相同时间 比较 event

1
2
# 并发线程数1个,每个线程每回计算素数个数为100000个,此次测试最长时间为20s
$ sysbench --test=cpu  --threads=1 --events=0 --time=20 run

返回

 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
$ sysbench --test=cpu  --threads=1 --events=0 --time=20 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 1        # 测试线程数
Initializing random number generator from current time


Prime numbers limit: 10000  # 每个线程每回计算素数个数

Initializing worker threads...

Threads started!

CPU speed:
    events per second:  1041.50

General statistics:
    total time:                          20.0007s    # 测试总耗时
    total number of events:              20832       # 所有线程总共event个数

Latency (ms):
         min:                                    0.71 # 一次 event 最小响应时间
         avg:                                    0.96 # 所有 event 平均相应时间
         max:                                    9.32 # 一次 event 最大响应时间
         95th percentile:                        2.66 # 耗时前 95% event 响应时间
         sum:                                19980.18 # 总共用时

Threads fairness:
    events (avg/stddev):           20832.0000/0.00  # 每个线程完成event数/标准差
    execution time (avg/stddev):   19.9802/0.00     # 每个线程平均总耗时/标准差

Sysbench 测试 Memory

参数

  • –memory-block-size,指定每次传输的内存块大小,默认值为1K;
  • –memory-total-size,指定最大传输总量,默认值为100G;
  • –memory-scope,指定内存访问范围,默认值为global;
  • –memory-hugetlb,指定是否为hugetlb池分配内存,默认值为否;
  • –memory-oper,指定内存操作类型,默认值为写;
  • –memory-access-mode,指定内存访问方式,默认值为顺序。

测试

固定时间,比较操作次数

1
2
$ sysbench  memory --threads="$threads" --memory-block-size="4k" \
--time=20 --memory-oper="read" --memory-total-size=0 run

固定大小比较操作时间

1
2
$ sysbench  memory --threads="$threads" --memory-block-size="4k" \
--max-time=0 --memory-oper="read" --memory-total-size=50G run

返回

 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
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 8 # 线程数
Initializing random number generator from current time


Running memory speed test with the following options:
  block size: 4KiB
  total size: 0MiB
  operation: read
  scope: global

Initializing worker threads...

Threads started!

Total operations: 411293964 (20563104.49 per second) # 总共/每秒 执行的 event 个数

1606617.05 MiB transferred (80324.63 MiB/sec)        # 总共/每秒 传输的大小


General statistics:
    total time:                          20.0000s
    total number of events:              411293964

Latency (ms):
         min:                                    0.00   # event 最低响应时间
         avg:                                    0.00   # event 平均响应时间
         max:                                   12.02   # event 最大响应时间
         95th percentile:                        0.00   # 前 95% 平均响应时间
         sum:                                78557.93

Threads fairness:
    events (avg/stddev):           51411745.5000/426653.81
    execution time (avg/stddev):   9.8197/0.02