linux网络性能测试工具 iperf

本文详细介绍了如何使用iperf工具测试网络的TCP和UDP带宽、延时、丢包和抖动,提供了具体操作步骤和实例,帮助用户有效评估网络质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于要测试另一个IDC给的带宽是否给足了,所以要从一个机房打10G的流量到测试IDC。之初 采用多线程下载工具,多进程方法下载,可是不理想,跑量达不到要求。
Iperf是一个网络性能测试工具。可以测试TCP和UDP带宽质量,可以测量最大TCP带宽,具有多种参数和UDP特性,可以报告 带宽,延迟抖动和数据包丢失.

服务器上架,首要的是进行操作系统安装,然后进行联通性测试和网络质量测试。我们曾经有过教训,一个服务器上的业务一直不正常,技术人员排查了好久,在应用和系统上一直没有找到问题,最后发现是一根质量低劣的成品网络线,造成网络质量极差从而引起系统无法正常工作。

网络质量的指标,主要有以下几个:

  • 带宽(throughput),网络的吞吐率,端到端之间可以传输的最大速率。比如服务器之间的千兆网络带宽是1000Mbps,或者用户adsl上网速率是 2Mbps。
  • 延时(latency),数据包从本地传输到对端之间需要的时间,一般是来回的时间。如果延时过大,就会觉得网络慢,特别是一些交互性强的应用。比如延时超过300ms,通过ssh就会明显感到服务器响应比较慢,跟不上键盘输入的速度。延时一方面和两地之间的传输距离有关,比如中美之间通过海底光缆传输半个地球,来回距离加起来最起码4万公里,光速是30万公里每秒,所以理论延时最起码是130ms,再加上光缆需要转接和绕路,以及其他损耗,所以中美之间网络延时最好的时候也在170ms左右。延时另外一个原因是网络带宽的占用率,如果占用率高,则延时也高,比如天朝的特色,电信和网通之间,互相掐架,互联带宽很小,网络瓶颈,造成互相之间延时很高。很多时候,同一个城市的网通到电信,比到美国去绕一圈还要慢。延时的其他原因,是cpu处理跟不上等。
  • 丢包(loss),由于线路带宽占用过高,数据包从一端到另外一端传输的途中,会产生丢失。丢包率是网络的一个重要指标,一旦产生丢包,说明网络带宽不足,系统会自动重传,导致继续劣化,所以丢包率超过10%以后,网络质量会迅速劣化。
  • 抖动(jitter),如果延时不稳定,忽快忽慢,网络就存在抖动。抖动这个指标,在VOIP,视频会议等场合,是一个非常重要的指标,如果产生抖动,往往声音和图像也会抖动,无法听清楚或者看清楚。
各种应用,对上述指标的敏感性不一,比如http等应用,往往只对带宽和延时敏感,而游戏类应用,对延时、丢包、带宽敏感,及时语音和视频对上述几个指标都比较敏感。

普通用户测试网络质量的工具,通常的有:

1、ping

谁最常用的一个测试网络质量的一个工具,在各种操作系统、网络设备中一般都自带该工具。ping可以测试网络的延时、丢包率,优点是使用方便,不用安装。

ping的缺陷也比较明显:

  • 测试的时候,仅仅发送很小的负载icmp包,无法测试真实负载下的网络质量,比如单位里的网络平时是正常的,但是开一个迅雷下载,就很糟糕了。
  • 测试的指标单一,对于带宽、抖动无法测试

2、下载工具,可以测试带宽

这里介绍一个优秀的网络质量测试工具iperf,这个工具在我们的 asterisk 网络电话项目中,立下了汗马功劳。iperf 可以测试真实载荷下的网络质量,可以测试端到端的网络质量,可以测试一定吞吐率下的丢包、抖动。


先介绍下安装
如果是centos 的话。添加第三方的源(rpmforge)就可以直接yum
yum -y install iperf
当然也可以用源码包编 译安装 。官方站: http://sourceforge.net/projects/iperf/
tar xvf iperf-xxx.tar
cd iperf
./configure
make
make install

用法:

root@ubuntu:~# iperf -h

Usage: iperf [-s|-c host][options]

      iperf [-h|--help] [-v|--version]

 

Client/Server:

  -f,--format   [kmKM]  format to report: Kbits, Mbits, KBytes, MBytes

  -i,--interval       seconds between periodic bandwidth reports

  -l, --len      #[KM]   length of buffer to read or write (default 8 KB)

  -m,--print_mss         print TCP maximum segment size (MTU - TCP/IP header)

  -o,--output   <filename> output the report or errormessage to this specified file

  -p,--port           server port to listen on/connect to

  -u, --udp               useUDP rather than TCP

  -w,--window   #[KM]   TCP window size (socket buffer size)

  -B,--bind     <host>  bind to <host>, an interface ormulticast address

  -C,--compatibility     for use with older versions does not sent extra msgs

  -M, --mss            set TCP maximum segment size (MTU - 40 bytes)

  -N,--nodelay           set TCP no delay, disabling Nagle's Algorithm

  -V,--IPv6Version       Set the domain to IPv6

 

Server specific:

  -s,--server            run in server mode

  -U,--single_udp        run in single threaded UDP mode

  -D,--daemon            run the server as a daemon

 

Client specific:

  -b, --bandwidth#[KM]   for UDP, bandwidth to send at in bits/sec

                          (default 1 Mbit/sec, implies -u)

  -c,--client   <host>   runin client mode, connecting to<host>

  -d,--dualtest          Do a bidirectional test simultaneously

  -n, --num      #[KM]   number of bytes to transmit (instead of -t)

  -r,--tradeoff          Do a bidirectional test individually(单独进行双向传输测试)

  -t,--time           time in seconds to transmit for (default 10 secs)

  -F, --fileinput<name>  input the data to be transmitted from a file

  -I,--stdin             input the data to be transmitted from stdin

  -L, --listenport#      port to receive bidirectional tests back on

  -P,--parallel       number of parallel client threads to run

  -T, --ttl            time-to-live, for multicast (default 1)

  -Z,--linux-congestion <algo>  set TCP congestioncontrol algorithm (Linux only)

 

Miscellaneous:

  -x, --reportexclude[CDMSV]  exclude C(connection) D(data) M(multicast) S(settings) V(server)reports

  -y, --reportstyleC     report as a Comma-Separated Values

  -h,--help              print this message and quit

  -v,--version           print version information and quit

 

[KM] Indicates options thatsupport a K or M suffix for kilo- or mega-

 

The TCP window size optioncan be set by the environment variable

TCP_WINDOW_SIZE. Most otheroptions can be set by an environment variable

IPERF_<longoption name>, such as IPERF_BANDWIDTH.

 

Report bugs to<iperf-users@lists.sourceforge.net>


一般的网络传输,使用 tcp 测试(普通网络应用),测试传输带宽

语音服务器应该使用 udp 方式 (-u 选项),主要用于voip,视频会议,一些游戏

 

使用范例

1.     测试最大的TCP bandwidth

Server

root@ubuntu:~# iperf -s -p 5800 -M 1460 -i 1
WARNING: attempt to set TCP maximum segment size to 1460, but got 536
------------------------------------------------------------
Server listening on TCP port 5800
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 192.168.102.205 port 5800 connected with 192.168.102.205 port 37792
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0- 1.0 sec   886 MBytes  7.43 Gbits/sec
[  4]  1.0- 2.0 sec   939 MBytes  7.88 Gbits/sec
[  4]  2.0- 3.0 sec   845 MBytes  7.09 Gbits/sec
[  4]  3.0- 4.0 sec   850 MBytes  7.13 Gbits/sec
[  4]  4.0- 5.0 sec   846 MBytes  7.10 Gbits/sec
[  4]  5.0- 6.0 sec   893 MBytes  7.49 Gbits/sec
[  4]  6.0- 7.0 sec   710 MBytes  5.96 Gbits/sec
[  4]  7.0- 8.0 sec   658 MBytes  5.52 Gbits/sec
[  4]  8.0- 9.0 sec   757 MBytes  6.35 Gbits/sec
[  4]  9.0-10.0 sec   838 MBytes  7.03 Gbits/sec
[  4]  0.0-10.0 sec  8.03 GBytes  6.89 Gbits/sec
WARNING: attempt to set TCP maximum segment size to 1460, but got 536
------------------------------------------------------------
Client connecting to 192.168.102.205, TCP port 5800
TCP window size:  160 KByte (default)
------------------------------------------------------------
[  4] local 192.168.102.205 port 37793 connected with 192.168.102.205 port 5800
[  5] local 192.168.102.205 port 5800 connected with 192.168.102.205 port 37793
[  4]  0.0- 1.0 sec  1.02 GBytes  8.72 Gbits/sec
[  5]  0.0- 1.0 sec  1.02 GBytes  8.73 Gbits/sec
[  4]  1.0- 2.0 sec  1.21 GBytes  10.4 Gbits/sec
[  5]  1.0- 2.0 sec  1.21 GBytes  10.4 Gbits/sec
[  4]  2.0- 3.0 sec   902 MBytes  7.57 Gbits/sec
[  5]  2.0- 3.0 sec   902 MBytes  7.57 Gbits/sec
[  4]  3.0- 4.0 sec   908 MBytes  7.62 Gbits/sec
[  5]  3.0- 4.0 sec   908 MBytes  7.62 Gbits/sec
[  4]  4.0- 5.0 sec   717 MBytes  6.02 Gbits/sec
[  5]  4.0- 5.0 sec   718 MBytes  6.02 Gbits/sec
[  4]  5.0- 6.0 sec  1.27 GBytes  10.9 Gbits/sec
[  5]  5.0- 6.0 sec  1.27 GBytes  10.9 Gbits/sec
[  4]  6.0- 7.0 sec  1.04 GBytes  8.90 Gbits/sec
[  5]  6.0- 7.0 sec  1.04 GBytes  8.90 Gbits/sec
[  4]  7.0- 8.0 sec   896 MBytes  7.51 Gbits/sec
[  5]  7.0- 8.0 sec   896 MBytes  7.52 Gbits/sec
[  4]  8.0- 9.0 sec  1.31 GBytes  11.2 Gbits/sec
[  5]  8.0- 9.0 sec  1.31 GBytes  11.2 Gbits/sec
[  4]  9.0-10.0 sec  1.29 GBytes  11.1 Gbits/sec
[  4]  0.0-10.0 sec  10.5 GBytes  9.00 Gbits/sec
[  5]  9.0-10.0 sec  1.29 GBytes  11.1 Gbits/sec
[  5]  0.0-10.0 sec  10.5 GBytes  8.99 Gbits/sec

Client

root@ubuntu:~# iperf -c 192.168.102.205 -p 5800 -M 1460 -m -i 1 -r
WARNING: attempt to set TCP maximum segment size to 1460, but got 536
WARNING: attempt to set TCP maximum segment size to 1460, but got 536
bind failed: Address already in use
------------------------------------------------------------
Client connecting to 192.168.102.205, TCP port 5800
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.102.205 port 37792 connected with 192.168.102.205 port 5800
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec   887 MBytes  7.44 Gbits/sec
[  3]  1.0- 2.0 sec   940 MBytes  7.88 Gbits/sec
[  3]  2.0- 3.0 sec   844 MBytes  7.08 Gbits/sec
[  3]  3.0- 4.0 sec   850 MBytes  7.13 Gbits/sec
[  3]  4.0- 5.0 sec   846 MBytes  7.10 Gbits/sec
[  3]  5.0- 6.0 sec   893 MBytes  7.49 Gbits/sec
[  3]  6.0- 7.0 sec   709 MBytes  5.95 Gbits/sec
[  3]  7.0- 8.0 sec   658 MBytes  5.52 Gbits/sec
[  3]  8.0- 9.0 sec   757 MBytes  6.35 Gbits/sec
[  3]  9.0-10.0 sec   838 MBytes  7.03 Gbits/sec
[  3]  0.0-10.0 sec  8.03 GBytes  6.90 Gbits/sec
[  3] MSS size 1448 bytes (MTU 1500 bytes, ethernet)

 

2.     测试packetloss

 双向测试

Server

root@ubuntu:~# iperf -s -i 1 -u
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[  3] local 192.168.102.205 port 5001 connected with 192.168.102.205 port 47287
------------------------------------------------------------
Client connecting to 192.168.102.205, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[  5] local 192.168.102.205 port 43917 connected with 192.168.102.205 port 5001
[  4] local 192.168.102.205 port 5001 connected with 192.168.102.205 port 43917
[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
[  3]  0.0- 1.0 sec  59.2 MBytes   497 Mbits/sec   0.001 ms  298/42519 (0.7%)
[  3]  1.0- 2.0 sec  58.4 MBytes   490 Mbits/sec   0.001 ms    0/41682 (0%)
[  3]  2.0- 3.0 sec  58.4 MBytes   490 Mbits/sec   0.004 ms    0/41663 (0%)
[  3]  3.0- 4.0 sec  58.0 MBytes   487 Mbits/sec   0.004 ms    0/41383 (0%)
[  3]  4.0- 5.0 sec  58.0 MBytes   486 Mbits/sec   0.000 ms    0/41354 (0%)
[  3]  5.0- 6.0 sec  58.7 MBytes   493 Mbits/sec   0.002 ms    0/41895 (0%)
[  3]  6.0- 7.0 sec  57.8 MBytes   485 Mbits/sec   0.000 ms    0/41247 (0%)
[  3]  7.0- 8.0 sec  58.0 MBytes   487 Mbits/sec   0.002 ms    0/41395 (0%)
[  3]  8.0- 9.0 sec  58.0 MBytes   486 Mbits/sec   0.002 ms    0/41366 (0%)
[  3]  0.0-10.0 sec   583 MBytes   489 Mbits/sec   0.001 ms  297/416234 (0.071%)   #在client到server方向有packet loss
[  3]  0.0-10.0 sec  1 datagrams received out-of-order
[SUM]  0.0-10.0 sec   642 MBytes   539 Mbits/sec

Client

root@ubuntu:~# iperf -c 192.168.102.205 -i 1 -u -t 10 -b 500m -d
------------------------------------------------------------
Client connecting to 192.168.102.205, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[  3] local 192.168.102.205 port 47287 connected with 192.168.102.205 port 5001
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  59.6 MBytes   500 Mbits/sec
[  3]  1.0- 2.0 sec  58.4 MBytes   490 Mbits/sec
[  3]  2.0- 3.0 sec  58.4 MBytes   490 Mbits/sec
[  3]  3.0- 4.0 sec  58.0 MBytes   487 Mbits/sec
[  3]  4.0- 5.0 sec  58.0 MBytes   486 Mbits/sec
[  3]  5.0- 6.0 sec  58.7 MBytes   492 Mbits/sec
[  3]  6.0- 7.0 sec  57.8 MBytes   485 Mbits/sec
[  3]  7.0- 8.0 sec  58.0 MBytes   487 Mbits/sec
[  3]  8.0- 9.0 sec  58.0 MBytes   486 Mbits/sec
[  3]  9.0-10.0 sec  58.5 MBytes   491 Mbits/sec
[  3]  0.0-10.0 sec   584 MBytes   489 Mbits/sec
[  3] Sent 416235 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec   583 MBytes   489 Mbits/sec   0.001 ms  297/416234 (0.071%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order

上面客户端测试结果包括带宽、抖动、丢包:

[  3] Server Report:
[  3]  0.0-10.0 sec   583 MBytes   489 Mbits/sec   0.001 ms  297/416234 (0.071%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order


单向测试

server

root@ubuntu:~# iperf -s -i 1 -u
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[  3] local 192.168.102.205 port 5001 connected with 192.168.102.205 port 41641
[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
[  3]  0.0- 1.0 sec  58.3 MBytes   489 Mbits/sec   0.002 ms    0/41608 (0%)
[  3]  1.0- 2.0 sec  58.7 MBytes   493 Mbits/sec   0.000 ms    0/41894 (0%)
[  3]  2.0- 3.0 sec  58.8 MBytes   493 Mbits/sec   0.001 ms    0/41939 (0%)
[  3]  3.0- 4.0 sec  58.2 MBytes   488 Mbits/sec   0.000 ms    0/41539 (0%)
[  3]  4.0- 5.0 sec  58.2 MBytes   488 Mbits/sec   0.000 ms    0/41521 (0%)
[  3]  5.0- 6.0 sec  58.5 MBytes   491 Mbits/sec   0.001 ms    0/41720 (0%)
[  3]  6.0- 7.0 sec  58.2 MBytes   488 Mbits/sec   0.000 ms    0/41497 (0%)
[  3]  7.0- 8.0 sec  58.2 MBytes   488 Mbits/sec   0.006 ms    0/41483 (0%)
[  3]  8.0- 9.0 sec  58.4 MBytes   490 Mbits/sec   0.003 ms    0/41673 (0%)
[  3]  9.0-10.0 sec  58.4 MBytes   490 Mbits/sec   0.005 ms    0/41690 (0%)
[  3]  0.0-10.0 sec   584 MBytes   490 Mbits/sec   0.007 ms    0/416565 (0%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order
client

root@ubuntu:~# iperf -c 192.168.102.205 -i 1 -u -t 10 -b 500m
------------------------------------------------------------
Client connecting to 192.168.102.205, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  224 KByte (default)
------------------------------------------------------------
[  3] local 192.168.102.205 port 41641 connected with 192.168.102.205 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  58.3 MBytes   489 Mbits/sec
[  3]  1.0- 2.0 sec  58.7 MBytes   492 Mbits/sec
[  3]  2.0- 3.0 sec  58.8 MBytes   493 Mbits/sec
[  3]  3.0- 4.0 sec  58.2 MBytes   488 Mbits/sec
[  3]  4.0- 5.0 sec  58.3 MBytes   489 Mbits/sec
[  3]  5.0- 6.0 sec  58.5 MBytes   490 Mbits/sec
[  3]  6.0- 7.0 sec  58.2 MBytes   488 Mbits/sec
[  3]  7.0- 8.0 sec  58.2 MBytes   488 Mbits/sec
[  3]  8.0- 9.0 sec  58.4 MBytes   490 Mbits/sec
[  3]  9.0-10.0 sec  58.4 MBytes   490 Mbits/sec
[  3]  0.0-10.0 sec   584 MBytes   490 Mbits/sec
[  3] Sent 416566 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec   584 MBytes   490 Mbits/sec   0.006 ms    0/416565 (0%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order



http://blog.sina.com.cn/s/blog_68f770d90100xdyt.html

http://blog.youkuaiyun.com/yanheven1/article/details/17303905


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值