标签:iperf performance
iperf是一款网络性能测试工具,不紧可以测试TCP,还可以测试UDP,包括检测网络带宽,自由设置MSS大小,tcp nodelay,tcp windows 大小,最新的iperf3.0版本甚至加上禁止tcp slow start的功能。
一般系统默认安装的都是iperf的旧版本,最近版本请到官网下载:https://iperf.fr/iperf-download.php,由于我是ubuntu的系统,所以就下载deb的包来安装。
查看iperf3的帮助信息如下:
# iperf3 -h 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 -A, --affinity n/n,m set CPU affinity -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 -C, --congestion <algo> set TCP congestion control algorithm (Linux and FreeBSD only) -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‘ -L, --flowlabel N set the IPv6 flow label (only supported on Linux) -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
因为iperf是基于server/client的情况下探测网络吞吐量的,所以你必须要有一个server监听着某一个端口,然后在client上测试,iperf的团队很贴心,已经给我们免费提供了全球几个点的server供大家免费测试:https://iperf.fr/iperf-servers.php
由于我是日本的ec2, 所以就用亚洲的那台机器做测试,服务器地址是:iperf.it-north.net,Speed是1Gbit/s,端口是TCP/UDP 5200 - 5209,只支持ipv4,当然如果你想用自己的服务器做server,官网也提供了一个脚本供你使用:
#!/bin/bash /bin/sleep 10 /usr/bin/killall iperf3 /bin/sleep 0.1 /usr/bin/killall -9 iperf3 /bin/sleep 0.1 if [ `ps -C iperf3 | wc -l` = "1" ] then /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5200 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5201 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5202 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5203 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5204 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5205 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5206 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5207 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5208 -D >/dev/null 2>&1 /usr/bin/sudo -u nobody /usr/bin/iperf3 -s -p 5209 -D >/dev/null 2>&1 fi
下面我们看客户端测试案例:
测试服务器的总的带宽。
-p #指定服务器的端口。
-f # format格式,可以是kKmMgG, A就是adaptive,类似于ls -h, 友好显示。
-N # nodelay,禁用Nagle‘s algorithm。
-O #禁用tcp slow start,-O 3表示 忽略前三次请求。
-V #显示详细信息。
-P #建立多少连接到server,默认是一个。
下面例子可以看到默认MSS是1448byte,前一秒钟属于慢启动拥塞窗口是570KBytes,之后就一直稳定在2.48MBytes,Summary Results:显示了服务器和客户端的带宽大小,消耗的cpu比例。
# iperf3 -c iperf.it-north.net -p 5205 -f A -N -O 3 -V iperf 3.1.2 Linux shanker 3.13.0-83-generic #127-Ubuntu SMP Fri Mar 11 00:25:37 UTC 2016 x86_64 Time: Fri, 15 Apr 2016 07:34:58 GMT Connecting to host iperf.it-north.net, port 5205 Cookie: shanker.1460705698.652529.7f4273b01f TCP MSS: 1448 (default) [ 4] local 172.31.23.95 port 56056 connected to 82.200.209.194 port 5205 Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, omitting 3 seconds, 10 second test [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 2.95 MBytes 2.95 MBytes/sec 0 570 KBytes (omitted) [ 4] 1.00-2.00 sec 12.4 MBytes 12.4 MBytes/sec 0 2.48 MBytes (omitted) [ 4] 2.00-3.00 sec 17.5 MBytes 17.4 MBytes/sec 0 2.48 MBytes (omitted) [ 4] 0.00-1.00 sec 18.8 MBytes 18.7 MBytes/sec 0 2.48 MBytes [ 4] 1.00-2.00 sec 16.2 MBytes 16.2 MBytes/sec 0 2.48 MBytes [ 4] 2.00-3.00 sec 18.8 MBytes 18.8 MBytes/sec 0 2.48 MBytes [ 4] 3.00-4.00 sec 17.5 MBytes 17.5 MBytes/sec 0 2.48 MBytes [ 4] 4.00-5.00 sec 17.5 MBytes 17.5 MBytes/sec 0 2.48 MBytes [ 4] 5.00-6.00 sec 18.8 MBytes 18.8 MBytes/sec 0 2.48 MBytes [ 4] 6.00-7.00 sec 17.5 MBytes 17.5 MBytes/sec 0 2.48 MBytes [ 4] 7.00-8.00 sec 17.5 MBytes 17.5 MBytes/sec 0 2.48 MBytes [ 4] 8.00-9.00 sec 17.5 MBytes 17.5 MBytes/sec 0 2.48 MBytes [ 4] 9.00-10.00 sec 18.8 MBytes 18.8 MBytes/sec 0 2.48 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 179 MBytes 17.9 MBytes/sec 0 sender [ 4] 0.00-10.00 sec 181 MBytes 18.1 MBytes/sec receiver CPU Utilization: local/sender 2.7% (0.3%u/2.4%s), remote/receiver 4.0% (0.3%u/3.8%s) iperf Done.
对TCP Slow Start 和 Congestion Avoidance感兴趣的可以配合watch, ss观察一下一个启动过程:
Every 1.0s: ss -ani dst localhost Fri Apr 15 07:44:46 2016 Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 130966 127.0.0.1:60332 127.0.0.1:5205 cubic wscale:7,7 rto:204 rtt:4/2 mss:65483 cwnd:76 ssthresh:40 send 9953.4Mbps unacked:2 rcv_space:43690 tcp ESTAB 0 0 127.0.0.1:60331 127.0.0.1:5205 cubic wscale:7,7 rto:208 rtt:8/10 ato:40 mss:21888 cwnd:10 ssthresh:40 send 218.9Mbps rcv_space:43690 tcp ESTAB 0 0 ::ffff:127.0.0.1:5205 ::ffff:127.0.0.1:60331 cubic wscale:7,7 rto:208 rtt:8/10 ato:40 mss:21888 cwnd:10 send 218.9Mbps rcv_space:43690 tcp ESTAB 0 0 ::ffff:127.0.0.1:5205 ::ffff:127.0.0.1:60332 cubic wscale:7,7 rto:216 rtt:4/2 ato:40 mss:21888 cwnd:10 send 437.8Mbps rcv_rtt:4 rcv_space:16253034 tcp TIME-WAIT 0 0 ::ffff:127.0.0.1:5205 ::ffff:127.0.0.1:60329
可以加上-w参数指定发送的tcp传输窗口大小,加上-P 基本可以测算出来你的网站可以支持多少客户端并发,感觉这个测试一个网站的网站的并发性能也是可以的。
# iperf3 -c localhost -p 5205 -f A -N -O3 -w 5K Connecting to host localhost, port 5205 [ 4] local 127.0.0.1 port 60479 connected to 127.0.0.1 port 5205 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 231 MBytes 231 MBytes/sec 0 25.0 KBytes (omitted) [ 4] 1.00-2.00 sec 233 MBytes 233 MBytes/sec 0 25.0 KBytes (omitted) [ 4] 2.00-3.00 sec 232 MBytes 232 MBytes/sec 0 25.0 KBytes (omitted) [ 4] 0.00-1.00 sec 231 MBytes 231 MBytes/sec 0 25.0 KBytes [ 4] 1.00-2.00 sec 233 MBytes 233 MBytes/sec 0 25.0 KBytes [ 4] 2.00-3.00 sec 231 MBytes 231 MBytes/sec 0 25.0 KBytes [ 4] 3.00-4.00 sec 232 MBytes 232 MBytes/sec 0 25.0 KBytes [ 4] 4.00-5.00 sec 235 MBytes 235 MBytes/sec 0 25.0 KBytes [ 4] 5.00-6.00 sec 234 MBytes 234 MBytes/sec 0 25.0 KBytes [ 4] 6.00-7.00 sec 234 MBytes 234 MBytes/sec 0 25.0 KBytes [ 4] 7.00-8.00 sec 237 MBytes 237 MBytes/sec 0 25.0 KBytes [ 4] 8.00-9.00 sec 237 MBytes 237 MBytes/sec 0 25.0 KBytes [ 4] 9.00-10.00 sec 235 MBytes 235 MBytes/sec 0 25.0 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 2.28 GBytes 234 MBytes/sec 0 sender [ 4] 0.00-10.00 sec 2.29 GBytes 235 MBytes/sec receiver iperf Done.
-M #可以更改MSS的值
Attempt to set the TCP maximum segment size (MSS). The MSS is usually the MTU - 40 bytes for the TCP/IP header. For ethernet, the MSS is 1460 bytes (1500 byte MTU).
官方解释是尝试去设置MSS的值,不知道为啥我在我的系统里测试的时候默认值是21888,但是当我尝试更改为30000的时候就没法运行,难道这就是尝试的意思?还请明白的给我留言解释一下。
# iperf3 -c localhost -p 5205 -f A -V iperf 3.1.2 Linux shanker 3.13.0-83-generic #127-Ubuntu SMP Fri Mar 11 00:25:37 UTC 2016 x86_64 Time: Fri, 15 Apr 2016 08:29:21 GMT Connecting to host localhost, port 5205 Cookie: shanker.1460708961.252601.6c573c0715 TCP MSS: 21888 (default) [ 4] local 127.0.0.1 port 60516 connected to 127.0.0.1 port 5205 Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, omitting 0 seconds, 10 second test [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 2.80 GBytes 2.79 GBytes/sec 0 3.31 MBytes [ 4] 1.00-2.00 sec 2.79 GBytes 2.79 GBytes/sec 0 3.31 MBytes [ 4] 2.00-3.00 sec 2.83 GBytes 2.83 GBytes/sec 0 3.31 MBytes [ 4] 3.00-4.00 sec 2.83 GBytes 2.83 GBytes/sec 0 3.31 MBytes [ 4] 4.00-5.00 sec 2.85 GBytes 2.85 GBytes/sec 0 3.31 MBytes [ 4] 5.00-6.00 sec 2.80 GBytes 2.80 GBytes/sec 0 3.31 MBytes [ 4] 6.00-7.00 sec 2.85 GBytes 2.85 GBytes/sec 0 3.31 MBytes [ 4] 7.00-8.00 sec 2.86 GBytes 2.86 GBytes/sec 0 3.31 MBytes [ 4] 8.00-9.00 sec 2.87 GBytes 2.87 GBytes/sec 0 3.31 MBytes [ 4] 9.00-10.00 sec 2.84 GBytes 2.84 GBytes/sec 0 3.31 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 28.3 GBytes 2.83 GBytes/sec 0 sender [ 4] 0.00-10.00 sec 28.3 GBytes 2.83 GBytes/sec receiver CPU Utilization: local/sender 49.6% (1.0%u/48.5%s), remote/receiver 5.0% (0.4%u/4.6%s) iperf Done.
观察完服务器的各项指标,即可配合tcp_rmem, tcp_wmem, tcp_mem参数来调整优化服务器网络性能。以后文章会写详细写到调整tcp网络性能。
Enjoy Yourself!
本文出自 “天涯海阁” 博客,请务必保留此出处http://shanker.blog.51cto.com/1189689/1764216
标签:iperf performance
原文地址:http://shanker.blog.51cto.com/1189689/1764216