netperf 網絡性能測試


Netperf是一種網絡性能的測量工具,主要針對基於TCP或UDP的傳輸。Netperf根據應用的不同,可以進行不同模式的網絡性能測試,即批量數據傳輸(bulk data transfer)模式和請求/應答(request/reponse)模式。

工作原理

Netperf工具以client/server方式工作。server端是netserver,用來偵聽來自client端的連接,client端是netperf,用來向server發起網絡測試.在client與server之間,首先建立一個控制連接,傳遞有關測試配置的信息,以及測試的結果:在控制連接建立並傳遞了測試配置信息以后,client與server之間會再建立一個測試連接,進行來回傳遞特殊的流量模式,以測試網絡的性能

軟件安裝

  1. 下載安裝Netperf工具
下載鏈接:ftp://ftp.netperf.org/netperf/ [root@xiesshavip001 ~]# wget ftp://ftp.netperf.org/netperf/netperf-2.7.0.tar.gz
  1. 安裝依賴包gcc cc
[root@xiesshavip001 ~]# yum install gcc cc -y
  1. 解壓安裝
[root@xiesshavip001 ~]# tar -zxvf netperf-2.7.0.tar.gz [root@xiesshavip001 netperf-2.7.0]# ./configure [root@xiesshavip001 netperf-2.7.0]# make && make install

命令參數介紹

命令行參數包括如下選項:

-H host :指定遠端運行netserver的server IP地址。 -l testlen:指定測試的時間長度(秒) -t testname:指定進行的測試類型,包括TCP_STREAM,UDP_STREAM,TCP_RR,TCP_CRR,UDP_RR -s size 設置本地系統的socket發送與接收緩沖大小 -S size 設置遠端系統的socket發送與接收緩沖大小 -m size 設置本地系統發送測試分組的大小 -M size 設置遠端系統接收測試分組的大小 -D 對本地與遠端系統的socket設置TCP_NODELAY選項

netperf 網絡測試

  1. TCP_STREAM Netperf缺省情況下進行TCP批量傳輸,即-t TCP_STREAM。測試過程中,netperf向netserver發送批量的TCP數據分組,以確定數據傳輸過程中的吞吐量:
[root@xiesshavip002 ~]# netserver # 服務端啟動netserver 服務 Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC [root@xiesshavip001 ~]# netperf -H 192.168.130.20 -l 60 MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 87380 16384 16384 60.01 935.66 [root@xiesshavip001 ~]# [root@xiesshavip001 ~]# netperf -H 192.168.130.20 -l 60 -- -m 10240 # 修改發送的包的大小 MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 87380 16384 10240 60.02 937.58 [root@xiesshavip001 ~]#
  1. UDP_STREAM UDP_STREAM用來測試進行UDP批量傳輸時的網絡性能。注意:此時測試分組的大小不得大於socket的發送與接收緩沖大小,否則netperf會報出錯提示:
[root@xiesshavip001 ~]# netperf -t UDP_STREAM -H 192.168.130.20 -l 10 MIGRATED UDP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET Socket Message Elapsed Messages Size Size Time Okay Errors Throughput bytes bytes secs # # 10^6bits/sec 212992 65507 10.01 131286 0 6874.75 212992 10.01 1 0.05 [root@xiesshavip001 ~]# [root@xiesshavip001 ~]# netperf -t UDP_STREAM -H 192.168.130.20 -l 10 -- -m 300000 # 超過socket的發送與接收緩沖大212992 MIGRATED UDP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET send_data: data send error: Message too long (errno 90) netperf: send_omni: send_data failed: Message too long [root@xiesshavip001 ~]#
  1. TCP_RR TCP_RR方式的測試對象是多次TCP request和response的交易過程
[root@xiesshavip001 ~]# netperf -t TCP_RR -H 192.168.130.20 MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET : first burst 0 Local /Remote Socket Size Request Resp. Elapsed Trans. Send Recv Size Size Time Rate bytes Bytes bytes bytes secs. per sec 16384 87380 1 1 10.00 8228.63 16384 87380 [root@xiesshavip001 ~]#

我們可以通過測試相關的參數來改變request和response分組的大小,TCP_RR方式下的參數如下表所示:

參數	           說明
-r req,resp 設置request和reponse分組的大小 -s size 設置本地系統的socket發送與接收緩沖大小 -S size 設置遠端系統的socket發送與接收緩沖大小 -D 對本地與遠端系統的socket設置TCP_NODELAY選項
[root@xiesshavip001 ~]# netperf -t TCP_RR -H 192.168.130.20 -- -r 64 64 MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET : first burst 0 Local /Remote Socket Size Request Resp. Elapsed Trans. Send Recv Size Size Time Rate bytes Bytes bytes bytes secs. per sec 16384 87380 64 64 10.00 8143.22 16384 87380 [root@xiesshavip001 ~]#
  1. TCP_CRR 與TCP_RR不同,TCP_CRR為每次交易建立一個新的TCP連接。
[root@xiesshavip001 ~]# netperf -t TCP_CRR -H 192.168.130.20 MIGRATED TCP Connect/Request/Response TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET Local /Remote Socket Size Request Resp. Elapsed Trans. Send Recv Size Size Time Rate bytes Bytes bytes bytes secs. per sec 16384 87380 1 1 10.00 899.38 # 數值明顯比TCP_RR值小 16384 87380 [root@xiesshavip001 ~]#
  1. UDP_RR UDP_RR方式使用UDP分組進行request/response的交易過程
[root@xiesshavip001 ~]# netperf -t UDP_RR -H 192.168.130.20 MIGRATED UDP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.130.20 () port 0 AF_INET : first burst 0 Local /Remote Socket Size Request Resp. Elapsed Trans. Send Recv Size Size Time Rate bytes Bytes bytes bytes secs. per sec 212992 212992 1 1 10.00 8425.86 212992 212992 [root@xiesshavip001 ~]#

netperf --help

[root@xiesshavip001 ~]# netperf --help netperf: invalid option -- '-' Usage: netperf [global options] -- [test options] Global options: -a send,recv Set the local send,recv buffer alignment -A send,recv Set the remote send,recv buffer alignment -B brandstr Specify a string to be emitted with brief output -c [cpu_rate] Report local CPU usage -C [cpu_rate] Report remote CPU usage -d Increase debugging output -D time,[units] * Display interim results at least every time interval using units as the initial guess for units per second A negative value for time will make heavy use of the system's timestamping functionality -f G|M|K|g|m|k Set the output units -F lfill[,rfill]* Pre-fill buffers with data from specified file -h Display this text -H name|ip,fam * Specify the target machine and/or local ip and family -i max,min Specify the max and min number of iterations (15,1) -I lvl[,intvl] Specify confidence level (95 or 99) (99) and confidence interval in percentage (10) -j Keep additional timing statistics -l testlen Specify test duration (>0 secs) (<0 bytes|trans) -L name|ip,fam * Specify the local ip|name and address family -o send,recv Set the local send,recv buffer offsets -O send,recv Set the remote send,recv buffer offset -n numcpu Set the number of processors for CPU util -N Establish no control connection, do 'send' side only -p port,lport* Specify netserver port number and/or local port -P 0|1 Don't/Do display test headers -r Allow confidence to be hit on result only -s seconds Wait seconds between test setup and test start -S Set SO_KEEPALIVE on the data connection -t testname Specify test to perform -T lcpu,rcpu Request netperf/netserver be bound to local/remote cpu -v verbosity Specify the verbosity level -W send,recv Set the number of send,recv buffers -v level Set the verbosity level (default 1, min 0) -V Display the netperf version and exit -y local,remote Set the socket priority -Y local,remote Set the IP_TOS. Use hexadecimal. -Z passphrase Set and pass to netserver a passphrase For those options taking two parms, at least one must be specified; specifying one value without a comma will set both parms to that value, specifying a value with a leading comma will set just the second parm, a value with a trailing comma will set just the first. To set each parm to unique values, specify both and separate them with a comma. * For these options taking two parms, specifying one value with no comma will only set the first parms and will leave the second at the default value. To set the second value it must be preceded with a comma or be a comma-separated pair. This is to retain previous netperf behaviour. [root@xiesshavip001 ~]#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM