netperf 工具使用

一、安装

1,下载

liunx下载地址:ftp://ftp.netperf.org/netperf/

windows版下载地址:ftp://ftp.netperf.org/netperf/misc/

这里我下载版本:netperf-2.6.0.tar.gz

2,安装

1
2
3
4
5
6
[root@localhost home]# tar -zxvf netperf-2.6.0.tar.gz
[root@localhost home]# cd netperf-2.6.0/
[root@localhost netperf-2.6.0]# ./configure
[root@localhost netperf-2.6.0]# make&& make install
[root@localhost ~]# netperf -V
Netperf version 2.6.0

二、netperf介绍

Netperf是一种网络性能的测量工具,可以测试基于TCP或UDP吞吐、响应速率。Netperf包括Clien和Server端。Server端主要用来实现监听工作,Client端进行测试。根据流量传输方式可分为以下三种:

1)单方向最大吞吐传输大量数据。

2)双方向交互传输数据,对于tcp为单连接。

3)针对tcp,每个连接交互传输数据。

三、Netperf服务端

Netperf服务端使用命令为netserver。netserver默认监听端口为12865。netserver可选项较少,常用-p指定监听端口。-h可以查看可选项。

1,启动服务器

1
2
[root@localhost ~]# netserver
Starting netserver with host'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC

2,指定监听端口

1
2
[root@localhost tmp]# netserver -p 1180
Starting netserver with host'IN(6)ADDR_ANY' port '1180' and family AF_UNSPEC

四、netperf客户端

Netperf客户端使用命令就是netperf。netperf使用语法:

netperf <全局选项> – <特指选项>

这里举例介绍几种常见使用场景来演示netperf使用:

1,测试tcp吞吐

1
2
3
4
5
6
7
8
[root@localhost ~]# netperf -t TCP_STREAM -H 192.168.0.221 -l 10 -P 1180
MIGRATED TCP STREAM TEST from 0.0.0.0(0.0.0.0) port 0 AF_INET to 192.168.0.221 () 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    10.00   4586.58

测试结果:吞吐为4.5G/s。

-t: 指定进行的测试类型,包括TCP_STREAM,UDP_STREAM,TCP_RR,TCP_CRR,UDP_RR。可以省略,省略即为TCP_STEAM。

-H:指定远程主机,即netserver服务器地址。

-l: 指定时间。

-p:指定netserver监听端口,可以省略,省略即为默认端口12865。

2,测试UDP吞吐

1
2
3
4
5
6
7
8
[root@localhost ~]# netperf -t UDP_STREAM -H 192.168.0.221 -l 10
MIGRATED UDP STREAM TEST from 0.0.0.0(0.0.0.0) port 0 AF_INET to 192.168.0.221 () port 0 AF_INET
Socket Message  Elapsed      Messages               
Size   Size     Time         Okay Errors   Throughput
bytes  bytes    secs            #      #  10^6bits/sec

212992  65507   10.00       78233      0   4099.59
212992           10.00       74263           3891.55

测试结果:

第一行表示本地吞吐4.0G/s,第二行表示接收端吞吐只有3.8G/s。

3,测试tcp交互响应速率,类似http长连接或客户端对数据库服务器读取存储

1
2
3
4
5
6
7
8
9
[root@localhost ~]# netperf -t TCP_RR -H 192.168.0.221 -l 10 -- -r 256,2048
MIGRATED TCP REQUEST/RESPONSE TEST from0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.0.221 () port 0 AF_INET : firstburst 0
Local /Remote
Socket Size   Request Resp.   Elapsed  Trans.
Send  Recv   Size     Size   Time     Rate        
bytes Bytes  bytes    bytes  secs.    per sec  

16384 87380  256      2048   10.00    6020.25  
16384 87380

测试结果:第一行显示:每秒达6k响应。第二行只是显示服务器端信息。

-r:指定客户端发送数据大小和服务器端响应数据大小。例子中客户端每次发送tcp数据256字节,服务器每次回复2048字节。

4,测试udp交互响应速率,与tcp交互类似

1
2
3
4
5
6
7
8
9
[root@localhost ~]# netperf -t UDP_RR -H 192.168.0.221 -l 10 -- -r 256,2048
MIGRATED UDP REQUEST/RESPONSE TEST from0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.0.221 () port 0 AF_INET : firstburst 0
Local /Remote
Socket Size   Request Resp.   Elapsed  Trans.
Send  Recv   Size     Size   Time     Rate        
bytes Bytes  bytes    bytes  secs.    per sec  

212992 212992 256      2048   10.00    5385.92  
212992 212992

5,针对tcp,每次交互都重新建立tcp连接,类似http短连接交互过程

1
2
3
4
5
6
7
8
9
[root@localhost ~]# netperf -t TCP_CRR -H 192.168.0.221 -l 10 -- -r 128,1024
MIGRATED TCP Connect/Request/Response TESTfrom 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.0.221 () 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  128      1024   10.00    2623.44  
16384 87380

测试结果:比没有每次建连接响应速率少一半。

6,其他选项

参数说明
-s size设置本地系统的socket发送与接收缓冲大小
-S size设置远端系统的socket发送与接收缓冲大小
-m size设置本地系统发送测试分组的大小
-M size设置远端系统接收测试分组的大小
-D设置TCP_NODELAY选项
-r req,resp设置request和reponse分组的大小

官方用户手册:http://www.netperf.org/svn/netperf2/trunk/doc/netperf.pdf

Licensed under CC BY-NC-SA 4.0