使用iPerf测试网络吞吐量

在测试网络吞吐量时,我们常见的方式都是通过远程拷贝一个文件来大致验证网络吞吐量,但是这种方式可能会受到磁盘自身吞吐量影响,所以我们采取 iperf 命令行工具可以避开受到其他因素影响。该工具可以在Linux 和 Windows 下通用。

一、iPerf 工具下载

  • CentOS 安装
# CentOS默认 yum 源没有iperf,epel yum 源库中存在
yum install epel-release
yum update
yum install iperf
  • Windows 安装 (直接在官方网站下载即可)
https://iperf.fr/iperf-download.php

在这里插入图片描述

二、iPerf 工具使用

iPerf 需要两台机器,一台充当客户端,一台充当服务端。客户端连接上服务测试。

1、TCP 服务端客户端测试
  • 在第一台机器上以服务端模式启动
# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
  • 在第二台机器上以客户端方式连接测试
# iperf3 -c 192.168.6.160
Connecting to host 192.168.6.160, port 5201
[  4] local 192.168.1.192 port 20886 connected to 192.168.6.160 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  7.63 MBytes  64.0 Mbits/sec   56   32.5 KBytes       
[  4]   1.00-2.00   sec  8.26 MBytes  69.3 Mbits/sec   22   39.6 KBytes       
[  4]   2.00-3.00   sec  7.52 MBytes  63.1 Mbits/sec   35   29.7 KBytes       
 ......      
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  71.6 MBytes  60.0 Mbits/sec  430             sender
[  4]   0.00-10.00  sec  71.3 MBytes  59.8 Mbits/sec                  receiver

iperf Done.
2、UDP 服务端客户端测试
  • 服务端依旧加 -s 启动,客户端加上 -u 参数代表使用udp协议,可以测试使用 udp 连接能实现的最大吞吐量
# 加上 -u 参数可以
# iperf3 -c 192.168.6.160 -u 
Connecting to host 192.168.6.160, port 5201
[  4] local 192.168.1.192 port 38898 connected to 192.168.6.160 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  
......
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  1.24 MBytes  1.04 Mbits/sec  0.289 ms  1/897 (0.11%)  
[  4] Sent 897 datagrams

iperf Done.

1.05Mbits/sec远低于TCP测试中观察到的值,这是因为默认情况下,iperf 对UDP带宽限制为每秒1 Mbits/sec。如果需要测试UDP网络速度,可以加 -b 参数设置带宽,将数字设置为双方硬件设置端口的最大带宽限制。

# iperf3 -c 192.168.6.160 -u -b 100m
Connecting to host 192.168.6.160, port 5201
[  4] local 192.168.1.192 port 63338 connected to 192.168.6.160 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  10.3 MBytes  86.6 Mbits/sec  7479  
[  4]   1.00-2.00   sec  11.4 MBytes  95.6 Mbits/sec  8253  
[  4]   2.00-3.00   sec  11.4 MBytes  95.6 Mbits/sec  8254  
......
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec   113 MBytes  94.6 Mbits/sec  0.016 ms  1346/81703 (1.6%)  
[  4] Sent 81703 datagrams

iperf Done.

3、Windows 使用

Windows 也是基于命令行使用,可以跟Linux混合测试,使用方式一致。从官网下载好的文件解压放进 C:\Windows 即可。
在这里插入图片描述

三、iPerf 参数选项

Usage: iperf [-s|-c host] [options]
       iperf [-h|--help] [-v|--version]

Server or Client:
  -p, --port      #         server port to listen on/connect to
  -f, --format    [kmgKMG]  format to report: Kbits, Mbits, KBytes, MBytes
  -i, --interval  #         seconds between periodic bandwidth reports
  -F, --file name           xmit/recv the specified file
  -B, --bind      <host>    bind to a specific interface
  -V, --verbose             more detailed output
  -J, --json                output in JSON format
  --logfile f               send output to a log file
  -d, --debug               emit debugging output
  -v, --version             show version information and quit
  -h, --help                show this message and quit
Server specific:
  -s, --server              run in server mode
  -D, --daemon              run the server as a daemon
  -I, --pidfile file        write PID file
  -1, --one-off             handle one client connection then exit
Client specific:
  -c, --client    <host>    run in client mode, connecting to <host>
  -u, --udp                 use UDP rather than TCP
  -b, --bandwidth #[KMG][/#] target bandwidth in bits/sec (0 for unlimited)
                            (default 1 Mbit/sec for UDP, unlimited for TCP)
                            (optional slash and packet count for burst mode)
  -t, --time      #         time in seconds to transmit for (default 10 secs)
  -n, --bytes     #[KMG]    number of bytes to transmit (instead of -t)
  -k, --blockcount #[KMG]   number of blocks (packets) to transmit (instead of -t or -n)
  -l, --len       #[KMG]    length of buffer to read or write
                            (default 128 KB for TCP, 8 KB for UDP)
  --cport         <port>    bind to a specific client port (TCP and UDP, default: ephemeral port)
  -P, --parallel  #         number of parallel client streams to run
  -R, --reverse             run in reverse mode (server sends, client receives)
  -w, --window    #[KMG]    set window size / socket buffer size
  -M, --set-mss   #         set TCP/SCTP maximum segment size (MTU - 40 bytes)
  -N, --no-delay            set TCP/SCTP no delay, disabling Nagle's Algorithm
  -4, --version4            only use IPv4
  -6, --version6            only use IPv6
  -S, --tos N               set the IP 'type of service'
  -Z, --zerocopy            use a 'zero copy' method of sending data
  -O, --omit N              omit the first n seconds
  -T, --title str           prefix every output line with this string
  --get-server-output       get results from server
  --udp-counters-64bit      use 64-bit counters in UDP test packets

[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-

iperf3 homepage at: http://software.es.net/iperf/
Report bugs to:     https://github.com/esnet/iperf
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值