Iperf 是一個 TCP/IP 和 UDP/IP 的性能測量工具,可以提供網絡吞吐率信息,以及震動、丟包率、最大段和最大傳輸單元大小等統計信息;從而可以幫助咱們測試網絡性能,定位網絡瓶頸。html
1.服務端服務器
iperf -s -w 1m
2.客戶端網絡
iperf -c 192.168.43.1 -t 60 -i 2 -P 5 -w 1m
參數的含義:併發
-s (server) 開啓服務器socket
-c (client) 指定服務端主機IP工具
-t 測試時長。默認10秒post
-i 數據統計間隔,以秒爲單位。 client 顯示的是發送速率 , server端顯示的是接收速率,最好加 i 參數進行速率跟蹤性能
-p (小寫)指定服務器端使用的端口或客戶端所鏈接的端口測試
-P (大寫)發包併發線程數url
-w 設置TCP窗口大小,默認是8KB。若是窗口過小,有可能丟包
-u 使用udp協議。測試htb的時候最好用udp,udp通訊開銷小,測試的帶寬更準確
-b 指定發送帶寬,默認是1Mbit/s。與-u 選項相關,千兆鏈路使用90%容量進行測試就能夠了: -u -b 900M 。在測試qos的時候,這是最有用的參數。
-l 緩衝區大小,默認是8KB,#iperf -c 222.35.11.23 -l 16
通常來講,咱們在作性能測試的時候須要指定包長,不一樣的包長會獲得不一樣的吞吐量,經過 -l 指定,而使用 -b 指定帶寬
--------------------------------------------------------------------------------------------------------------------------------
若是在測試中想知道兩臺機器見最大的鏈接速度。用scp拷一個文件應該是最容易的方法。可是不許確。 iperf 這個小工具就是專門用來幹這個的。結果相對來講準確一些。使用起來也很方便。
首先在兩臺機器上都安裝iperf
$ sudo apt-get install iperf
而後在須要測試的一臺機器上 啓動 iperf 監聽
$ iperf -s ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------
而後在另一臺機器上鍊接過去
$ iperf -c 192.168.1.10 ------------------------------------------------------------ Client connecting to 192.168.1.10, TCP port 5001 TCP window size: 18.6 KByte (default) ------------------------------------------------------------ [ 3] local 192.168.1.9 port 60611 connected with 192.168.1.10 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0-10.0 sec 112 MBytes 93.5 Mbits/sec
能夠看到 鏈接速率是 93.5Mbps 局域網通常達不到全速。
另外還有個小工具 用來查看實時的傳輸速率 httperf
$ sudo apt-get install httperf $ httperf httperf --client=0/1 --server=localhost --port=80 --uri=/ --send-buffer=4096 --recv-buffer=16384 --num-conns=1 --num-calls=1 httperf: warning: open file limit > FD_SETSIZE; limiting max. # of open files to FD_SETSIZE Maximum connect burst length: 0 Total: connections 1 requests 1 replies 1 test-duration 0.001 s Connection rate: 1081.0 conn/s (0.9 ms/conn, <=1 concurrent connections) Connection time [ms]: min 0.9 avg 0.9 max 0.9 median 0.5 stddev 0.0 Connection time [ms]: connect 0.2 Connection length [replies/conn]: 1.000 Request rate: 1081.0 req/s (0.9 ms/req) Request size [B]: 62.0 Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples) Reply time [ms]: response 0.7 transfer 0.0 Reply size [B]: header 284.0 content 177.0 footer 0.0 (total 461.0) Reply status: 1xx=0 2xx=1 3xx=0 4xx=0 5xx=0 CPU time [s]: user 0.00 system 0.00 (user 0.0% system 432.4% total 432.4%) Net I/O: 552.1 KB/s (4.5*10^6 bps) Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0 Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0
能夠看到目前的網絡IO 是 552.1KB/s 大約等於 4.5Mbps