侧边栏壁纸
博主头像
liveJQ博主等级

沒有乐趣,何来开始

  • 累计撰写 146 篇文章
  • 累计创建 60 个标签
  • 累计收到 2 条评论

Linux 网络测速

liveJQ
2022-01-01 / 0 评论 / 1 点赞 / 1,063 阅读 / 7,732 字 / 正在检测是否收录...
广告 广告

Iperf3

适用范围:同一区域内的任意目标

十分流行且方便使用的网络吞吐量测试工具,支持TCP/UDP/SCTP协议。测试时,需要分别在两端建立测试点,即C/S架构的模式。

在测试前,需要确保 Server 端的防火墙放行5201端口。

CentOS 7 放行 5201 端口

[root@sz-sh-test ~]# firewall-cmd --zone=public --add-port=5201/tcp --permanent && firewall-cmd --reload
[root@sz-sh-test ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192 ens224 ens256
  sources: 
  services: dhcpv6-client http https ssh
  ports: 5201/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

Ubuntu 20.04 放行 5201 端口

root@sh-sz-test:~# ufw allow 5201 && ufw reload
root@sh-sz-test:~# ufw status
Status: active

To                         Action      From
--                         ------      ----                         
22/tcp                     ALLOW       Anywhere                                                
5201                       ALLOW       Anywhere                                  
22/tcp (v6)                ALLOW       Anywhere (v6)                         
5201 (v6)                  ALLOW       Anywhere (v6)             

开始使用

基础测试

Server

root@sh-sz-test:~# iperf3 -s
root@sh-sz-test:~# iperf3 -s -p 5201

Client

root@sh-sz-test:~# iperf3 -c Server的IP地址
root@sh-sz-test:~# iperf3 -c Server的IP地址 -4 -i 1 -t 10 -f m -B Client的IP地址

上面分别有两行命令,执行效果相同,后一行只是添加了被省略的默认参数。默认使用 TCP 协议;默认测试 Client 的上传,Server 的下载(Client 加 -R 参数后则测试下载)。

进阶测试

进阶测试主要是方便某些特殊需求。例如:添加连接时的用户验证、测试其他网络接口、使用其他协议、指定显示更大的带宽单位(Gbps)、指定间隔和总测试时间、指定总测试数据量、使用IPv6等等。

常见错误

服务端未启动(未监听)

iperf3: error - unable to connect to server: Connection refused

服务端防火墙未开放监听端口(客户端或没有错误输出)

iperf3: error - unable to connect to server: no route to host

or

iperf3: error - unable to send control message: Bad file descriptor

除了放行监听端口外,最简单的办法是临时关闭防火墙(不推荐)。

#Ubuntu 20.04
ufw disable

#CentOS 7
systemctl stop firewalld

iperf 默认指的是 iperf2。这里建议使用 iperf3,它比 iperf2 更轻量,而且默认开启 TCP 重传和 CWND 拥塞报告,对于提高测试结果的准确度和故障排除都有一定帮助。无论使用 iperf2 还是 iperf3,都应该避免使用较旧的版本,多多少少会有些未知的 BUG 。

Bench

适用范围:通用

涵盖了系统参数信息,网络测试也比较全面。

测试前请先安装 wget

wget -qO- repo.livejq.top/livejq/rmscripts/raw/branch/master/SpeedTest/bench.sh | bash

测试结果样例:

-------------------- A Bench.sh Script By Teddysun -------------------
 Version            : v2022-06-01
 Usage              : wget -qO- bench.sh | bash
----------------------------------------------------------------------
 CPU Model          : Intel(R) Xeon(R) CPU           L5630  @ 2.13GHz
 CPU Cores          : 8 @ 2133.409 MHz
 CPU Cache          : 12288 KB
 AES-NI             : Enabled
 VM-x/AMD-V         : Disabled
 Total Disk         : 72.1 GB (1.8 GB Used)
 Total Mem          : 7.6 GB (4.1 GB Used)
 Total Swap         : 7.9 GB (0 Used)
 System uptime      : 1 days, 22 hour 37 min
 Load average       : 0.08, 0.15, 0.22
 OS                 : CentOS Linux release 7.9.2009 (Core)
 Arch               : x86_64 (64 Bit)
 Kernel             : 3.10.0-1160.el7.x86_64
 TCP CC             : cubic
 Virtualization     : VMware
 Organization       : AS134196 ANYUN INTERNET TECHNOLOGY (HK) CO.,LIMITED
 Location           : Shenzhen / CN
 Region             : Guangdong
----------------------------------------------------------------------
 I/O Speed(1st run) : 78.1 MB/s
 I/O Speed(2nd run) : 101 MB/s
 I/O Speed(3rd run) : 72.4 MB/s
 I/O Speed(average) : 83.8 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    54.41 Mbps        352.26 Mbps         24.35 ms    
 Dallas, US       54.44 Mbps        42.07 Mbps          221.82 ms   
 Montreal, CA     54.53 Mbps        42.52 Mbps          254.98 ms   
 Paris, FR        54.51 Mbps        45.42 Mbps          255.92 ms   
 Amsterdam, NL    54.44 Mbps        0.72 Mbps           276.68 ms   
 Shanghai, CN     54.64 Mbps        356.28 Mbps         33.61 ms    
 Nanjing, CN      54.56 Mbps        357.19 Mbps         23.38 ms    
 Guangzhou, CN    54.79 Mbps        333.40 Mbps         5.38 ms     
 Hongkong, CN     5.07 Mbps         3.47 Mbps           11.96 ms    
 Seoul, KR        54.47 Mbps        40.67 Mbps          49.06 ms    
 Singapore, SG    54.49 Mbps        42.71 Mbps          190.11 ms   
 Tokyo, JP        54.53 Mbps        43.35 Mbps          57.97 ms    
----------------------------------------------------------------------
 Finished in        : 6 min 39 sec
 Timestamp          : 2022-06-22 19:37:48 CST
----------------------------------------------------------------------

Superbench

适用范围:通用

这是仿照上面那个写的,效果差不多。另外还生成了外链,可以分享你的测试结果。

测试前请先安装 wget

wget -qO- repo.livejq.top/livejq/rmscripts/raw/branch/master/SpeedTest/superbench.sh | bash

测试结果样例:

Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : Intel(R) Xeon(R) CPU           L5630  @ 2.13GHz
 CPU Cores            : 8 Cores 2133.409 MHz x86_64
 CPU Cache            : 12288 KB 
 OS                   : CentOS 7.9.2009 (64 Bit) VMware
 Kernel               : 3.10.0-1160.el7.x86_64
 Total Space          : 1.8 GB / 73.0 GB 
 Total RAM            : 4239 MB / 7820 MB (1512 MB Buff)
 Total SWAP           : 0 MB / 8063 MB
 Uptime               : 1 days 22 hour 23 min
 Load Average         : 0.00, 0.02, 0.05
 TCP CC               : cubic
 ASN & ISP            : AS134196, Cloudie Limited
 Organization         : Shenzhen ESIN Technology Co., Ltd
 Location             : Shenzhen, China / CN
 Region               : Guangdong
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 7.4 MB/s
 I/O Speed( 1.0GB )   : 31.8 MB/s
 I/O Speed( 1.0GB )   : 37.7 MB/s
 Average I/O Speed    : 25.6 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    54.47 Mbit/s      373.41 Mbit/s       24.86 ms    
 Fast.com         0.00 Mbit/s       0 Mbit/s            -           
 Nanjing 5G   CT  54.44 Mbit/s      353.47 Mbit/s       25.18 ms    
 Hefei 5G     CT  54.45 Mbit/s      357.27 Mbit/s       23.91 ms    
 Guangzhou 5G CT  54.64 Mbit/s      374.72 Mbit/s       6.98 ms     
 Shanghai 5G  CU  54.64 Mbit/s      358.00 Mbit/s       33.94 ms    
 Wuxi 5G      CM  54.29 Mbit/s      371.71 Mbit/s       39.76 ms    
 Hefei 5G     CM  54.48 Mbit/s      364.10 Mbit/s       28.46 ms    
----------------------------------------------------------------------
 Finished in  : 7 min 14 sec
 Timestamp    : 2022-06-22 19:24:50 GMT+8
 Results      : ./superbench.log
----------------------------------------------------------------------
 Share result:
 · https://www.speedtest.net/result/c/3ce5ee7d-5f1d-46b1-bad9-d5f795c57db4
 · https://paste.ubuntu.com/p/NhMQjW4KKm/
----------------------------------------------------------------------

Superspeed

适用范围:中国大陆

这是将 SpeedTest 测速集成在一个脚本上,精选了一些国内三线节点进行的测试。

测试前请先安装 curl

bash <(curl -Lso- repo.livejq.top/livejq/rmscripts/raw/branch/master/SpeedTest/superspeed.sh)

测试结果样例:

———————————————————SuperSpeed 全面测速版——————————————————
       bash <(curl -Lso- repo.livejq.top/livejq/rmscripts/raw/branch/master/SpeedTest/superspeed.sh)
       全部节点列表: https://repo.livejq.top/livejq/rmscripts/raw/branch/master/SpeedTest/ServerList.md
       节点更新: 2020/04/09  | 脚本更新: 2020/04/09
——————————————————————————————————————————————————————————
  测速类型:    1. 三网测速    2. 取消测速
               3. 电信节点    4. 联通节点    5. 移动节点
               6. 详细三网测速
  请输入数字选择测速类型: 3
——————————————————————————————————————————————————————————
ID    测速服务器信息       上传/Mbps   下载/Mbps   延迟/ms
3633  电信|上海      ↑ 49.13     ↓ 48.63     32.38   
29071 电信|四川成都    ↑ 50.00     ↓ 49.18     38.25   
17145 电信|安徽合肥5G  ↑ 48.75     ↓ 48.49     26.98   
26352 电信|江苏南京5G  ↑ 48.59     ↓ 48.07     25.30   
5396  电信|江苏苏州5G  ↑ 48.95     ↓ 48.81     25.58   
5317  电信|江苏连云港5G ↑ 48.34     ↓ 48.73     27.65   
23844 电信|湖北武汉    ↑ 48.68     ↓ 48.08     21.06   
29353 电信|湖北武汉5G  ↑ 48.69     ↓ 49.04     24.70   
3973  电信|甘肃兰州    ↑ 47.99     ↓ 49.27     49.37   
——————————————————————————————————————————————————————————
  测试完成, 本次测速耗时: 6 分 29 秒
  当前时间: 2022-01-16 10:35:47

Yabs

适用范围:除中国大陆以外

比较综合的测试脚本,除了能测试上传和下载速度外,还能输出设备参数和硬盘IO性能等,而且机器的性能测试结果还能展示在Geekbench Browser上在线浏览。

测试前请先安装 curl

bash -c "$(curl -L https://github.com/masonr/yet-another-bench-script/raw/master/yabs.sh)"

测试结果样例:

# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
#              Yet-Another-Bench-Script              #
#                     v2021-12-28                    #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #

2022年 01月 08日 星期六 20:57:55 CST

Basic System Information:
---------------------------------
Processor  : Intel(R) Xeon(R) CPU           L5630  @ 2.13GHz
CPU cores  : 16 @ 1600.000 MHz
AES-NI     : ✔ Enabled
VM-x/AMD-V : ✔ Enabled
RAM        : 11.6 GiB
Swap       : 5.9 GiB
Disk       : 925.2 GiB

fio Disk Speed Tests (Mixed R/W 50/50):
---------------------------------
Block Size | 4k            (IOPS) | 64k           (IOPS)
  ------   | ---            ----  | ----           ---- 
Read       | 662.00 KB/s    (165) | 8.94 MB/s      (139)
Write      | 695.00 KB/s    (173) | 9.43 MB/s      (147)
Total      | 1.35 MB/s      (338) | 18.37 MB/s     (286)
           |                      |                     
Block Size | 512k          (IOPS) | 1m            (IOPS)
  ------   | ---            ----  | ----           ---- 
Read       | 28.87 MB/s      (56) | 31.83 MB/s      (31)
Write      | 30.93 MB/s      (60) | 34.56 MB/s      (33)
Total      | 59.81 MB/s     (116) | 66.40 MB/s      (64)

iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider        | Location (Link)           | Send Speed      | Recv Speed     
                |                           |                 |                
Clouvider       | London, UK (10G)          | 150 Mbits/sec   | 91.2 Mbits/sec 
Online.net      | Paris, FR (10G)           | 240 Mbits/sec   | 114 Mbits/sec  
WorldStream     | The Netherlands (10G)     | busy            | 65.6 Mbits/sec 
WebHorizon      | Singapore (400M)          | 25.9 Mbits/sec  | 198 Mbits/sec  
Clouvider       | NYC, NY, US (10G)         | 218 Mbits/sec   | 96.3 Mbits/sec 
Velocity Online | Tallahassee, FL, US (10G) | 54.5 Mbits/sec  | 70.0 Mbits/sec 
Clouvider       | Los Angeles, CA, US (10G) | 324 Mbits/sec   | 101 Mbits/sec  
Iveloz Telecom  | Sao Paulo, BR (2G)        | busy            | 50.6 Mbits/sec 

Geekbench 5 Benchmark Test:
---------------------------------
Test            | Value                         
                |                               
Single Core     | 385                              
Multi Core      | 3169                              
Full Test       | https://browser.geekbench.com/v5/cpu/1205482

总结

虽然指明了适用范围,但以上测试方法可以任意使用。供应商给的带宽与实际跑的往往会有一定出入,需要结合测试目的来选择测试方法,这也是为什么需要给出适用范围的原因。通常,使用 Iperf3 的端到端测试是最准确的(前提是必须保证两端带宽都满足测试带宽的要求),有条件的建议优先使用这种方法。

相关资料

  1. Iperf3 Download
  2. Bench
  3. Superbench
  4. Superspeed
  5. Yabs
1

评论区