Netperf是惠普公司开发的一个网络性能Benchmark。
Currently, its focus is on bulk data transfer and request/response performance using either TCP or UDP, and the Berkeley Sockets interface.
Netperf is a benchmark that can be used to measure the performance of many different types of networking. It provides tests for both unidirectional throughput, and end-to-end latency.
安装Netperf
https://github.com/HewlettPackard/netperf
1.下载需要的版本Netperf,以当前的最新版2.7.0为例:
1  | wget https://github.com/HewlettPackard/netperf/archive/refs/tags/netperf-2.7.0.zip  | 
2.解压缩
1  | unzip netperf-2.7.0.zip  | 
3.进入源码目录
1  | cd netperf-netperf-2.7.0/  | 
4.执行配置程序
1  | ./configure  | 
5.编译和安装
1  | make -j5 && make install  | 
6.查看版本
1  | [root@hgs netperf-netperf-2.7.0]# netperf -V  | 
使用Netperf
netperf的命令行选项分为两大类:全局命令行选项和测试相关选项,两者之间使用--分割。
1  | netperf <global> -- <test-specific>  | 
全局命令行选项:
-H name|ip,family (*):指定服务端地址-l testlen:指定测试的持续时间,默认为10秒。<0则表示字节数,或者请求/响应的事务数。-t testname:指定测试的类型,默认为TCP_STREAM。-P 0|1:是否显示测试Banner。1表示显示,0表示不显示。
1  | MIGRATED TCP STREAM TEST from (null) (::) port 0 AF_INET6 to localhost (::1) port 0 AF_INET6  | 
-f G|M|K|g|m|k|x:指定输出的单位。例如,G表示2^30bytes/s,g表示10^9bits/s
测试相关选项:
-m:指定每次发送的消息大小
应用实例
批量数据传输
1.启动服务端
1  | [root@hgs1 netperf-netperf-2.7.0]# netserver  | 
2.启动客户端
1  | [root@hgs2 netperf-netperf-2.7.0]# netperf -H 192.168.0.28  | 
 1.服务端使用的socket接收缓冲区大小为87380字节
 2.客户端使用的socket发送缓冲区大小为16384字节
 3.一次发送的测试消息大小为16384字节
 4.测试的持续时间为10秒
 5.网络吞吐率为$9368.98Mbps\approx 1.09GB/s$