Linux网络性能测试工具

speedtest

speedtest 是一个较为知名的工具,Python 写的。

安装

如果配置了 pip 工具,可以通过 pip/pip3 来安装

1
pip3 install speedtest-cli

也可以直接下载到本地后赋执行权限

1
2
3
4
# 需要安装 wget ,同时该网址可能需要代理访问
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py

chmod +x speedtest-cli

简单使用

1
2
3
4
./speedtest-cli --secure

# 或利用python来执行文件
python speedtest-cli --secure

注意,这里需要添加 --secure 参数,即使用 HTTPS 代替 HTTP 来访问 speedtest.net 网站;

否则会报错如下:

1
2
Cannot retrieve speedtest configuration
ERROR: HTTP Error 403: Forbidden

这样就可以得到一个上下行的速度测试结果。其他参数可以通过 --help 参数来查看帮助信息。

测试样例和结果如下:

1
2
3
4
5
6
7
8
9
10
11
[root@zabbix-proxy ~]# ./speedtest-cli --secure
Retrieving speedtest.net configuration...
Testing from China Telecom (xx.xxx.xxx.xx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by China Unicom 5G (ShangHai) [601.81 km]: 31.032 ms
Testing download speed................................................................................
Download: 1.61 Mbit/s
Testing upload speed................................................................................................
Upload: 2.49 Mbit/s

注意事项

1. 执行时需要添加 --secure 参数

这里需要添加 --secure 参数,即使用 HTTPS 代替 HTTP 来访问 speedtest.net 网站;

否则会报错如下:

1
2
Cannot retrieve speedtest configuration
ERROR: HTTP Error 403: Forbidden

2. 该工具使用 HTTP 协议来进行测试

该工具使用 Python 写的,speedtest-cli 可以直接打开查看,

大概过程是获取测试 IP 附近的几个站点,然后分别构造 HTTP 请求来进行上传和下载测试,通过 v=s/t 的方式计算上传和下载的速度。

值得注意的是,如果当前环境中有对 HTTP 协议进行限速,那么会对该测试的结果有影响。

同时,反过来,如果在测试过程中,发现结果与实际情况相差很多,也可以猜测是否有安全设备对 HTTP 协议进行限制。这时可以找其他工具来对比测试。

参考链接

Install Speedtest-cli On a CentOS / RHEL / Fedora Linux To Check Internet Speed

iperf3

iperf 是一个基于 TCP/IP 和 UDP/IP 的网络性能测试工具,可以测试带宽,网络延迟抖动和数据包丢失率,用一个名词就是 QoS(服务质量)。有 TCP 和 UDP 两种模式来测试。

iperf 是服务器/客户端模式的应用,所以测试时需要两台服务器,分别安装 iperf/iperf3,一台作为服务端,一台作为客户端进行测试。

主要功能

(1)TCP方面

  1. 测试网络带宽;
  2. 报告MSS/MTU值的大小,在Windows上不支持;
  3. 支持通过套接字缓冲区修改TCP窗口大小;

(2)UDP方面(对UDP应用的关注点不是传输数据有多快,而是它的丢包率和延时指标)

  1. 可以设置指定带宽的UDP数据流;
  2. 可以统计网络抖动值、丢包数等;
  3. 支持多播测试;

这里因为安装的 CentOS7 默认源中只有 iperf3,所以就以该版本来说。

注意,iperf 和 iperf3 有部分参数不一样,尤其是双向测试的参数,客户端与服务端版本不一样时,客户端访问服务端时需要使用服务端支持的参数。

安装

基本默认源中都有 iperf/iperf3,但是不同的操作系统可能默认带的版本不一样。

注意:最好服务端和客户端使用版本一致。如果不一致,注意查看两端支持的参数。

1
2
3
4
5
# CentOS7
yum install -y iperf3

# Debian
apt-get install iperf3

安装完成后,查看版本

1
iperf3 -v

查看参数

1
iperf3 --help

iperf 与 iperf3 各自有一些不同的特性,具体请查看帮助文档和支持的参数。

简单使用

主要参数:

  • 服务端使用参数 -s

  • 客户端使用参数 -c

使用上,客户端主要用于发起连接会话。

服务端启动

1
iperf3 -s

iperf3 服务端无论使用 TCP 还是 UDP 都仅需要这个一个参数就可以,iperf 启动 UDP 则需要添加 -u

其他一些参数,请查看帮助。

客户端启动测试

1
iperf3 -c 10.11.0.20

10.11.0.20 是服务端 IP 地址。

如果使用 UDP 协议测试,iperf3 只需要在客户端添加 -u 参数即可。

1
iperf3 -c 10.11.0.20 -u

测试网络带宽

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
# 客户端
[root@zabbix ~]# iperf3 -c 10.11.0.20
Connecting to host 10.11.0.20, port 5201
[ 4] local 10.2.8.9 port 46060 connected to 10.11.0.20 port 5201
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 1008 MBytes 8.45 Gbits/sec 299 1.17 MBytes
[ 4] 1.00-2.00 sec 926 MBytes 7.77 Gbits/sec 1716 1.18 MBytes
[ 4] 2.00-3.00 sec 1006 MBytes 8.44 Gbits/sec 2007 1.09 MBytes
[ 4] 3.00-4.00 sec 1.02 GBytes 8.80 Gbits/sec 669 1.25 MBytes
[ 4] 4.00-5.00 sec 905 MBytes 7.59 Gbits/sec 3532 1.06 MBytes
[ 4] 5.00-6.00 sec 1.05 GBytes 9.01 Gbits/sec 339 967 KBytes
[ 4] 6.00-7.00 sec 994 MBytes 8.34 Gbits/sec 1939 1.41 MBytes
[ 4] 7.00-8.00 sec 1.00 GBytes 8.60 Gbits/sec 468 1011 KBytes
[ 4] 8.00-9.00 sec 971 MBytes 8.15 Gbits/sec 1939 1.39 MBytes
[ 4] 9.00-10.00 sec 885 MBytes 7.42 Gbits/sec 4247 1.24 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 9.61 GBytes 8.26 Gbits/sec 17155 sender
[ 4] 0.00-10.00 sec 9.61 GBytes 8.25 Gbits/sec receiver

iperf Done.

# 客户端之后服务端也会有结果打印

# 服务端
[root@zabbix-proxy ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.11.1.66, port 46058
[ 5] local 10.2.8.5 port 5201 connected to 10.11.1.66 port 46060
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-1.00 sec 968 MBytes 8.12 Gbits/sec
[ 5] 1.00-2.00 sec 920 MBytes 7.72 Gbits/sec
[ 5] 2.00-3.00 sec 1006 MBytes 8.44 Gbits/sec
[ 5] 3.00-4.00 sec 1.03 GBytes 8.81 Gbits/sec
[ 5] 4.00-5.00 sec 904 MBytes 7.59 Gbits/sec
[ 5] 5.00-6.00 sec 1.05 GBytes 9.02 Gbits/sec
[ 5] 6.00-7.00 sec 992 MBytes 8.32 Gbits/sec
[ 5] 7.00-8.00 sec 1.00 GBytes 8.60 Gbits/sec
[ 5] 8.00-9.00 sec 972 MBytes 8.16 Gbits/sec
[ 5] 9.00-10.00 sec 887 MBytes 7.44 Gbits/sec
[ 5] 10.00-10.04 sec 39.1 MBytes 8.45 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec sender
[ 5] 0.00-10.04 sec 9.61 GBytes 8.22 Gbits/sec receiver

测试 UDP 丢包和延迟抖动

对UDP 测试来说的关注点不是传输数据有多快,而是它的丢包率和延时指标。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 客户端添加 -u 参数即可进行简单测试
[root@zabbix ~]# iperf3 -c 10.11.0.20 -u
Connecting to host 10.11.0.20, port 5201
[ 4] local 10.2.8.9 port 50273 connected to 10.11.0.20 port 5201
[ ID] Interval Transfer Bandwidth Total Datagrams
[ 4] 0.00-1.00 sec 116 KBytes 950 Kbits/sec 82
[ 4] 1.00-2.00 sec 129 KBytes 1.05 Mbits/sec 91
[ 4] 2.00-3.00 sec 127 KBytes 1.04 Mbits/sec 90
[ 4] 3.00-4.00 sec 129 KBytes 1.05 Mbits/sec 91
[ 4] 4.00-5.00 sec 127 KBytes 1.04 Mbits/sec 90
[ 4] 5.00-6.00 sec 129 KBytes 1.05 Mbits/sec 91
[ 4] 6.00-7.00 sec 127 KBytes 1.04 Mbits/sec 90
[ 4] 7.00-8.00 sec 129 KBytes 1.05 Mbits/sec 91
[ 4] 8.00-9.00 sec 127 KBytes 1.04 Mbits/sec 90
[ 4] 9.00-10.00 sec 129 KBytes 1.05 Mbits/sec 91
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 1.24 MBytes 1.04 Mbits/sec 0.012 ms 0/897 (0%)
[ 4] Sent 897 datagrams

iperf Done.

虚线下的内容关注后面2个字段 Jitter,Lost/Total

  • Jitter 列表示抖动时间,或者称为传输延迟;
  • Lost/Total 列表示丢失的数据报和总的数据报数量,后面的0%是平均丢包的比率;

同时Datagrams 列显示的是总共传输数据报的数量。

同样,服务端也会有结果打印,有更为详细的 UDP丢包和延迟信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.11.1.66, port 49904
[ 5] local 10.2.8.5 port 5201 connected to 10.11.1.66 port 50273
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 5] 0.00-1.00 sec 116 KBytes 950 Kbits/sec 0.010 ms 0/82 (0%)
[ 5] 1.00-2.00 sec 129 KBytes 1.05 Mbits/sec 0.011 ms 0/91 (0%)
[ 5] 2.00-3.00 sec 127 KBytes 1.04 Mbits/sec 0.010 ms 0/90 (0%)
[ 5] 3.00-4.00 sec 129 KBytes 1.05 Mbits/sec 0.010 ms 0/91 (0%)
[ 5] 4.00-5.00 sec 127 KBytes 1.04 Mbits/sec 0.010 ms 0/90 (0%)
[ 5] 5.00-6.00 sec 129 KBytes 1.05 Mbits/sec 0.008 ms 0/91 (0%)
[ 5] 6.00-7.00 sec 127 KBytes 1.04 Mbits/sec 0.010 ms 0/90 (0%)
[ 5] 7.00-8.00 sec 129 KBytes 1.05 Mbits/sec 0.007 ms 0/91 (0%)
[ 5] 8.00-9.00 sec 127 KBytes 1.04 Mbits/sec 0.009 ms 0/90 (0%)
[ 5] 9.00-10.00 sec 129 KBytes 1.05 Mbits/sec 0.012 ms 0/91 (0%)
[ 5] 10.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.012 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.012 ms 0/897 (0%)

注意事项

1. iperf3 服务端不支持--bidir

开始测试时,因环境原因,服务端使用的是 CentOS7.6 (iperf 3.1.7),而客户端使用的是 Debian(iperf 3.11),默认安装的 iperf3 小版本不一致,3.11 版本支持双向测试参数 --bidir,但是 3.1.7 版本不支持该参数,开始时没有注意两端支持的参数,客户端直接使用时报错。随后发现服务端不支持该参数。

可以通过 -R 参数进行反向测试。

2. iperf 与 iperf3 的双向测试参数不同

iperf 双向测试使用的参数为 -d--dualtest;

iperf3 支持的双向测试参数为 --bidir;

注意查看帮助信息。

参考链接

网络性能评估工具Iperf详解(可测丢包率)

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2023 ligongzhao
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信