关于磁盘和网络的性能的问题

背景

一般我们在两种场景下关心磁盘的性能:

  • pc 机拷贝文件时
  • 服务器运行有磁盘 io 的服务时

在 pc 机上,windows 下有各种磁盘跑分工具,一搜就有。

在服务器上,也有一系列工具。

概念

  • iops
  • throughput
  • latency
  • capacity
  • 块存储和文件系统

关于 iops、throughput、latency 之间的关系,可以直接认为 throughput = iops * 块大小。 latency 是另一个方面的参数。

关于一些概念的基本认识,可以参考 这篇文章

还可以参考文章:
参考1参考2

工具

块存储的测试可以使用 fio,使用方式可以参考 aliyun 磁盘性能测试

其他测试工具可以使用 dd、sysbench 等,可以参考 How to Benchmark Hard Disks in Linux

可以使用 iostat、iotop 等方式进行磁盘 io 观测

之前用 sysbench 做了阿里云 ECS 自带的磁盘,结果如下:

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
sysbench 1.0.18 (using system LuaJIT 2.1.0-beta3)

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


Extra file open flags: (none)
128 files, 16MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 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
Initializing worker threads...

Threads started!


File operations:
reads/s: 2897.98
writes/s: 1931.98
fsyncs/s: 6182.45

Throughput:
read, MiB/s: 45.28
written, MiB/s: 30.19

General statistics:
total time: 10.0192s
total number of events: 110225

Latency (ms):
min: 0.00
avg: 0.09
max: 25.22
95th percentile: 0.45
sum: 9979.91

Threads fairness:
events (avg/stddev): 110225.0000/0.00
execution time (avg/stddev): 9.9799/0.00

还可以参考的文章
fio 官方文档
一个腾讯用户的fio使用记录

感性数据

对于 hdd 而言,延迟大约为 10ms,throughput 在 100MB ~ 500MB
对于 ssd 而言,延迟大约为 1ms,throughput 可达到 500MB ~ 2000MB

容量上
常见的 hdd 目前基本都在 1TB 以上,高的可达到 10TB
常见的 ssd 容量有 128GB、256GB、512GB、1TGB

提升性能

提升 ssd 性能的好方式是: 换更高性能的设备
提升 hdd 性能的好方式是: 组 raid ,可以参考 使用lvm实现raid能力

监控

磁盘性能的监控,可以使用 prometheus 的 node exporter ,可以参考 简单的集群监控方案

其他

  • 关于网络 io 的性能,可以使用 iperf
    • 另外,百度的 dperf 也可以参考下
  • cpu 的性能测试比较复杂,可以参考 这个文档

iperf 测试

  • centos安装 iperf

    1
    rpm -ih ftp://ftp.pbone.net/mirror/archive.fedoraproject.org/fedora/linux/updates/24/x86_64/i/iperf3-3.1.3-1.fc24.x86_64.rpm
  • 一台机器上跑server端

    1
    iperf3 -s -p 8800
  • 另一台机器跑 client 端

    1
    iperf3 -c 172.24.33.3 -p 8800
  • 结果如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    [  4] local 172.24.33.4 port 39594 connected to 172.24.33.3 port 8800
    [ ID] Interval Transfer Bandwidth Retr Cwnd
    [ 4] 0.00-1.00 sec 236 MBytes 1.98 Gbits/sec 1315 543 KBytes
    [ 4] 1.00-2.00 sec 96.9 MBytes 813 Mbits/sec 1471 549 KBytes
    [ 4] 2.00-3.00 sec 117 MBytes 981 Mbits/sec 1845 168 KBytes
    [ 4] 3.00-4.00 sec 139 MBytes 1.16 Gbits/sec 2251 433 KBytes
    [ 4] 4.00-5.00 sec 111 MBytes 931 Mbits/sec 1891 298 KBytes
    [ 4] 5.00-6.00 sec 123 MBytes 1.03 Gbits/sec 1370 414 KBytes
    [ 4] 6.00-7.00 sec 117 MBytes 979 Mbits/sec 1860 93.3 KBytes
    [ 4] 7.00-8.00 sec 108 MBytes 905 Mbits/sec 1766 614 KBytes
    [ 4] 8.00-9.00 sec 109 MBytes 917 Mbits/sec 1141 614 KBytes
    [ 4] 9.00-10.00 sec 111 MBytes 927 Mbits/sec 1782 1.41 KBytes
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval Transfer Bandwidth Retr
    [ 4] 0.00-10.00 sec 1.24 GBytes 1.06 Gbits/sec 16692 sender
    [ 4] 0.00-10.00 sec 1.23 GBytes 1.06 Gbits/sec receiver

    iperf Done.

    这是阿里云下某规格机器的内网带宽,大概 1Gbits/s

  • 测试一下 udp

    1
    iperf3 -c 172.24.33.3 -p 8800 -u
  • 额 结果不大懂了

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Accepted connection from 172.24.33.3, port 50166
    [ 5] local 172.24.33.4 port 8800 connected to 172.24.33.3 port 48329
    [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
    [ 5] 0.00-1.00 sec 116 KBytes 950 Kbits/sec 0.006 ms 0/116 (0%)
    [ 5] 1.00-2.00 sec 128 KBytes 1.05 Mbits/sec 0.007 ms 0/128 (0%)
    [ 5] 2.00-3.00 sec 128 KBytes 1.05 Mbits/sec 0.003 ms 0/128 (0%)
    [ 5] 3.00-4.00 sec 128 KBytes 1.05 Mbits/sec 0.005 ms 0/128 (0%)
    [ 5] 4.00-5.00 sec 128 KBytes 1.05 Mbits/sec 0.004 ms 0/128 (0%)
    [ 5] 5.00-6.00 sec 128 KBytes 1.05 Mbits/sec 0.005 ms 0/128 (0%)
    [ 5] 6.00-7.00 sec 128 KBytes 1.05 Mbits/sec 0.004 ms 0/128 (0%)
    [ 5] 7.00-8.00 sec 128 KBytes 1.05 Mbits/sec 0.006 ms 0/128 (0%)
    [ 5] 8.00-9.00 sec 128 KBytes 1.05 Mbits/sec 0.005 ms 0/128 (0%)
    [ 5] 9.00-10.00 sec 128 KBytes 1.05 Mbits/sec 0.005 ms 0/128 (0%)
    [ 5] 10.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.005 ms 0/0 (0%)
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
    [ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.005 ms 0/1268 (0%)
  • 抓了下 udp 包

    1
    tcpdump "udp port 8800" -vv
  • 发现全是报错

    1
    2
    3
    4
    00:22:50.287602 IP (tos 0x0, ttl 64, id 38886, offset 0, flags [+], proto UDP (17), length 1500)
    172.24.33.3.35427 > iZj6c50uwswovavwjj5dqoZ.sunwebadmin: UDP, bad length 8192 > 1472
    00:22:50.287677 IP (tos 0x0, ttl 64, id 38887, offset 0, flags [+], proto UDP (17), length 1500)
    172.24.33.3.35427 > iZj6c50uwswovavwjj5dqoZ.sunwebadmin: UDP,
  • 查了下,发现是包大小限制了,可以参考这个

  • iperf 默认的 udp 包大小是 8k, 可以通过 -l 修改

  • 修改大小为 1k

    1
    iperf3 -c 172.24.33.3 -p 8800 -u -l 1024
  • 虽然抓包没问题了,但是结果还是不大行,原因未知,回头再看吧

    • 似乎只能看 udp 的丢包率

文档直通车


Love is the only force capable of transforming an enemy into a friend.
Martin Luther King Jr.