iperf,netperf,sockperf网络性能测试实战

1.2性能测试工具iPerf和Netperf使用介绍 对比可以看出同一时间段内主机1与主机2、主机1与主机3的带宽接近,不过主机1与主机2、主机1与主机3之间的带宽都不稳定,不同时间段的带宽相差比较大。场景二 UDP测试。 阅读详情
AI摘要

博客介绍了常用网络性能测试工具,如iperf、netperf和sockperf。iperf可测网络带宽和延迟,支持TCP和UDP协议;netperf能进行不同模式的网络性能测试;sockperf基于套接字API,可测试高性能系统的延迟和吞吐量。运行测试时需注意防火墙等影响。

目录


网络PPS(每秒传输数据包数)、网络带宽和网络时延是衡量云服务器网络性能的重要指标,测试网络性能可以帮助您提高网络的稳定性、延迟和吞吐量,从而为您提供更好的用户体验和应用程序性能。

常用网络性能测试工具包括iperf,netperf,jperf(iperf的图形化版本),sockperf等。运行网络测试时,注意系统防火墙、安全组等影响,可以添加放行规则或者关闭防火墙后进行测试。

1. iperf(3)测试网络带宽和质量

iperf可用于测试两个计算机之间的网络带宽和延迟。它是一个开源项目,提供了用于Windows、Linux和其他操作系统的版本。通过在两台计算机之间运行iPerf服务器和客户端,您可以测量它们之间的网络性能。iPerf客户端发送数据流到服务器,并且服务器测量接收到的数据量和速度。支持在TCP和UDP协议上运行

iperf包括iperf2和iperf3两个版本。

官网
https://iperf.fr/

1.1 安装使用

# Ubuntu安装
$ sudo apt-get update
$ sudo apt-get install iperf
$ sudo apt-get install iperf3

# CentOS安装
$ sudo yum install epel-release
$ sudo yum install iperf
$ sudo yum install iperf3
1.1.1 参数说明
$ 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
  --forceflush              force flushing output at every interval
  -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)
  --fq-rate #[KMG]          enable fair-queuing based socket pacing in
                            bits/sec (Linux only)
  -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, dynamic or 1 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常用参数中文说明:
(1)-s,–server:iperf服务器模式,默认启动的监听端口为5201,eg:iperf -s
(2)-c,–client host:iperf客户端模式,host是server端地址,eg:iperf -c 222.35.11.23
(3)-i,–interval:指定每次报告之间的时间间隔,单位为秒,eg:iperf3 -c 192.168.12.168 -i 2
(4)-p,–port:指定服务器端监听的端口或客户端所连接的端口,默认是5001端口。
(5)-u,–udp:表示采用UDP协议发送报文,不带该参数表示采用TCP协议。
(6)-l,–len:设置读写缓冲区的长度,(default 128 KB for TCP, dynamic or 1 for UDP)。通常测试 PPS 的时候该值为16,测试BPS时该值为1400。
(7)-b,–bandwidth [K|M|G]:指定UDP模式使用的带宽,单位bits/sec,默认值是1 Mb/s。
(8)-t,–time:指定数据传输的总时间,即在指定的时间内,重复发送指定长度的数据包。默认10秒。
(9)-A:CPU亲和性,可以将具体的iperf3进程绑定对应编号的逻辑CPU,避免iperf进程在不同的CPU间调度。

通用参数(Server端和Client端共用):
 (1)-f,–format [k|m|g|K|M|G]:指定带宽输出单位,“[k|m|g|K|M|G]”分别表示以Kb, Mb, Gb, KBytes, MBytes,GBytes显示输出结果,默认Mb,eg:iperf3 -c 192.168.12.168 -f M
(2)-p,–port:指定服务器端监听的端口或客户端所连接的端口,默认是5001端口。
(3)-i,–interval:指定每次报告之间的时间间隔,单位为秒,eg:iperf3 -c 192.168.12.168 -i 2
(4)-F:指定文件作为数据流进行带宽测试。例如:iperf3 -c 192.168.12.168 -F web-ixdba.tar.gz

Server端专用参数:
(1)-s,–server:iperf服务器模式,默认启动的监听端口为5201,eg:iperf -s
(2)-c,–client host:如果iperf运行在服务器模式,并且用-c参数指定一个主机,那么iperf将只接受指定主机的连接。此参数不能工作于UDP模式。
(3)-D:Unix平台下将Iperf作为后台守护进程运行。在Win32平台下,Iperf将作为服务运行。
(4)-R:卸载Iperf服务(仅用于Windows)。
(5)-o:重定向输出到指定文件(仅用于Windows)。
(6)-P,–parallel:服务器关闭之前保持的连接数。默认是0,这意味着永远接受连接。

Client端专用参数:
(1)-c,–client host:iperf客户端模式,host是server端地址,eg:iperf -c 222.35.11.23
(2)-u,–udp:表示采用UDP协议发送报文,不带该参数表示采用TCP协议。
(3)-b,–bandwidth [K|M|G]:指定UDP模式使用的带宽,单位bits/sec,默认值是1 Mbit/sec。
(4)-t,–time:指定数据传输的总时间,即在指定的时间内,重复发送指定长度的数据包。默认10秒。
(5)-l,–len:设置读写缓冲区的长度,(default 128 KB for TCP, dynamic or 1 for UDP)。通常测试 PPS 的时候该值为16,测试BPS时该值为1400。
(6)-n,–num [K|M|G]:指定传输数据包的字节数,例如:iperf3 -c 192.168.12.168 –n 100M
(7)-P,–parallel:指定客户端与服务端之间使用的线程数。默认是1个线程。需要客户端与服务器端同时使用此参数。
(8)-w,–window:指定套接字缓冲区大小,在TCP方式下,此设置为TCP窗口的大小。在UDP方式下,此设置为接受UDP数据包的缓冲区大小,用来限制可以接收数据包的最大值
(9)-B,–bind:用来绑定一个主机地址或接口,这个参数仅用于具有多个网络接口的主机。在UDP模式下,此参数用于绑定和加入一个多播组。
(10)-M,–mss:设置TCP最大信息段的值
(11)-N,–nodelay:设置TCP无延时
(12)-V:绑定一个IPv6地址。
(13)-d,–dualtest:运行双测试模式。将使服务器端反向连接到客户端,使用-L参数中指定的端口(或默认使用客户端连接到服务器端的端口)。使用参数-r以运行交互模式。
(14)-L,–listenport:指定服务端反向连接到客户端时使用的端口。默认使用客户端连接至服务端的端口。
(15)-r,–tradeoff:往复测试模式。当客户端到服务器端的测试结束时,服务器端反向连接至客户端。当客户端连接终止时,反向连接随即开始。如果需要同时进行双向测试,请尝试-d参数。

1.2 测试

准备两台机器,网络可达,分别安装iperf。注意添加系统防火墙规则或者关闭防火墙。如果是云环境,添加对应的安全组规则、防护墙规则放行。

1.2.1 测试TCP吞吐量
# Server端开启iperf的服务器模式,指定TCP端口:
$ iperf3 -s -i 1 -p 10000
-----------------------------------------------------------
Server listening on 10000
-----------------------------------------------------------

# Client端启动iperf的客户端模式,连接服务端。ip为server端地址
$ iperf3 -c 172.16.0.9 -i 1 -t 60 -p 10000
Connecting to host 172.16.0.9, port 10000
[  4] local 172.16.0.2 port 42756 connected to 172.16.0.9 port 10000
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  68.0 MBytes   570 Mbits/sec  3298   4.24 KBytes
[  4]   1.00-2.00   sec  48.1 MBytes   404 Mbits/sec  2077   4.24 KBytes
...
[  4]  57.00-58.00  sec  48.1 MBytes   403 Mbits/sec  2046   5.66 KBytes
[  4]  58.00-59.00  sec  49.1 MBytes   412 Mbits/sec  1990   4.24 KBytes
[  4]  59.00-60.00  sec  40.1 MBytes   336 Mbits/sec  1653   11.3 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-60.00  sec  2.85 GBytes   408 Mbits/sec  126933             sender
[  4]   0.00-60.00  sec  2.85 GBytes   407 Mbits/sec                  receiver

iperf Done.


# 测试4线程TCP吞吐量,如果没有指定发送方式,iperf客户端只会使用单线程。
$ iperf3 -c 172.16.0.9 -i 1 -P 4 -t 60 -p 10000
Connecting to host 172.16.0.9, port 10000
[  4] local 172.16.0.2 port 42764 connected to 172.16.0.9 port 10000
[  6] local 172.16.0.2 port 42766 connected to 172.16.0.9 port 10000
[  8] local 172.16.0.2 port 42768 connected to 172.16.0.9 port 10000
[ 10] local 172.16.0.2 port 42770 connected to 172.16.0.9 port 10000
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  29.5 MBytes   247 Mbits/sec  1905   4.24 KBytes
[  6]   0.00-1.00   sec  17.0 MBytes   143 Mbits/sec  249   63.6 KBytes
[  8]   0.00-1.00   sec  13.6 MBytes   114 Mbits/sec  676   2.83 KBytes
[ 10]   0.00-1.00   sec  7.88 MBytes  66.1 Mbits/sec  462   2.83 KBytes
...
[SUM]  59.00-60.00  sec  43.8 MBytes   368 Mbits/sec  2866
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-60.00  sec   836 MBytes   117 Mbits/sec  49435             sender
[  4]   0.00-60.00  sec   834 MBytes   117 Mbits/sec                  receiver
[  6]   0.00-60.00  sec   834 MBytes   117 Mbits/sec  53454             sender
[  6]   0.00-60.00  sec   833 MBytes   116 Mbits/sec                  receiver
[  8]   0.00-60.00  sec   627 MBytes  87.7 Mbits/sec  38115             sender
[  8]   0.00-60.00  sec   626 MBytes  87.6 Mbits/sec                  receiver
[ 10]   0.00-60.00  sec   618 MBytes  86.4 Mbits/sec  39273             sender
[ 10]   0.00-60.00  sec   617 MBytes  86.3 Mbits/sec                  receiver
[SUM]   0.00-60.00  sec  2.85 GBytes   408 Mbits/sec  180277             sender
[SUM]   0.00-60.00  sec  2.84 GBytes   407 Mbits/sec                  receiver

iperf Done.


# 进行上下行带宽测试(双向传输)
$ iperf3 -c 172.16.0.9 -i 1 -d -t 60 -p 10000
send_parameters:
{
        "tcp":  true,
        "omit": 0,
        "time": 60,
        "parallel":     1,
        "len":  131072,
        "client_version":       "3.1.7"
}
Connecting to host 172.16.0.9, port 10000
SNDBUF is 16384, expecting 0
RCVBUF is 87380, expecting 0
Congestion algorithm is cubic
[  4] local 172.16.0.2 port 42774 connected to 172.16.0.9 port 10000
tcpi_snd_cwnd 3 tcpi_snd_mss 1448 tcpi_rtt 96
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  67.6 MBytes   567 Mbits/sec  2708   4.24 KBytes
tcpi_snd_cwnd 2 tcpi_snd_mss 1448 tcpi_rtt 36
...
[  4]  58.00-59.00  sec  48.7 MBytes   408 Mbits/sec  2095   5.66 KBytes
tcpi_snd_cwnd 3 tcpi_snd_mss 1448 tcpi_rtt 104
send_results
{
        "cpu_util_total":       2.346862,
        "cpu_util_user":        0.094838,
        "cpu_util_system":      2.270644,
        "sender_has_retransmits":       1,
        "congestion_used":      "cubic",
        "streams":      [{
                        "id":   1,
                        "bytes":        3065514464,
                        "retransmits":  126989,
                        "jitter":       0,
                        "errors":       0,
                        "packets":      0
                }]
}
get_results
{
        "cpu_util_total":       5.909981,
        "cpu_util_user":        1.167991,
        "cpu_util_system":      4.745647,
        "sender_has_retransmits":       -1,
        "congestion_used":      "cubic",
        "streams":      [{
                        "id":   1,
                        "bytes":        3064309728,
                        "retransmits":  -1,
                        "jitter":       0,
                        "errors":       0,
                        "packets":      0
                }]
}
[  4]  59.00-60.00  sec  48.4 MBytes   406 Mbits/sec  1757   4.24 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-60.00  sec  2.85 GBytes   409 Mbits/sec  126989             sender
[  4]   0.00-60.00  sec  2.85 GBytes   409 Mbits/sec                  receiver

iperf Done.

结果说明:

  • Interval表示时间间隔。
  • Transfer表示时间间隔里面转输的数据量。
  • Bandwidth是时间间隔里的传输速率。
1.2.2 测试UDP吞吐量

带宽测试通常采用UDP模式,因为能测出极限带宽、时延抖动、丢包率。在进行测试时,首先以链路理论带宽作为数据发送速率进行测试,例如,从客户端到服务器之间的链路的理论带宽为100Mbps,先用-b 100M进行测试,然后根据测试结果(包括实际带宽,时延抖动和丢包率),再以实际带宽作为数据发送速率进行测试,会发现时延抖动和丢包率比第一次好很多,重复测试几次,就能得出稳定的实际带宽。

# Server端开启iperf的服务器模式,指定UDP端口:
$ iperf3 -s -i 1 -p 10001
-----------------------------------------------------------
Server listening on 10001
-----------------------------------------------------------

# Client端启动iperf的客户端模式,连接服务端
$ iperf3 -u -c 172.16.0.9 -b 100m -t 60 -p 10001
Connecting to host 172.16.0.9, port 10001
[  4] local 172.16.0.2 port 46011 connected to 172.16.0.9 port 10001
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  10.8 MBytes  90.3 Mbits/sec  7799
...
[  4]  58.00-59.00  sec  11.9 MBytes   100 Mbits/sec  8640
[  4]  59.00-60.00  sec  11.9 MBytes  99.9 Mbits/sec  8625
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-60.00  sec   714 MBytes  99.8 Mbits/sec  0.001 ms  133914/517118 (26%)
[  4] Sent 517118 datagrams

iperf Done.

# 测试多线程UDP吞吐量
$ iperf3 -u -c 172.16.0.9 -b 5m -P 4 -t 60 -p 10001

# 进行上下行带宽测试(双向传输)
$ iperf3 -u -c 172.16.0.9 -b 100M -d -t 60 -p 10001

结果说明:

  • jitter为抖动,在连续传输中的平滑平均值差。
  • Lost为丢包数量。
  • Total Datagrams为包数量。

说明:
在网络性能测试中,“jitter”(抖动)是指网络数据包到达目的地的时间之间的变化量。换句话说,它是网络延迟的变化量,通常以毫秒(ms)为单位。抖动表示数据包到达的不稳定性,即使平均延迟很低,高抖动也可能导致网络连接出现问题。
在iPerf中,当执行UDP测试时,抖动是一个重要的指标之一,它能帮助评估网络连接的质量。UDP测试通常会更加关注抖动,因为UDP协议本身不提供丢失数据包的重新传输机制,而且应用程序可能对数据到达的时间敏感。
通过测量抖动,您可以了解到数据包到达目的地的时间变化范围。较低的抖动表示网络连接的稳定性较高,而较高的抖动可能会导致数据包的丢失或延迟增加。
因此,在进行网络性能测试时,特别是对于实时或延迟敏感的应用程序(如VoIP或视频流),监测和评估抖动是非常重要的。

2. netperf测试网络带宽和PPS

Netperf是一种网络性能的测量工具(由惠普公司开发的,测试网络栈。即测试不同类型的网络性能的benchmark工具)主要针对基于TCP或UDP的传输。Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求/应答(request/reponse)模式。Netperf测试结果所反映的是一个系统能够以多快的速度向另外一个系统发送数据,以及另外一个系统能够以多块的速度接收数据。

netperf官网:
http://www.netperf.org/netperf/
https://github.com/HewlettPackard/netperf

2.1 安装

准备至少两台机器,分别安装netperf。

# 源码编译安装
# ubuntu安装依赖
$ sudo apt-get install automake texinfo

$ wget -O netperf-2.7.0.tar.gz -c  https://codeload.github.com/HewlettPackard/netperf/tar.gz/netperf-2.7.0
$ tar xf netperf-2.7.0.tar.gz
$ cd netperf-netperf-2.7.0/
# 编译
$ ./autogen.sh && ./configure
# 安装
$ sudo make && sudo make install

2.2 参数说明

# 查看帮助信息。更多帮助信息通过man netserver/netperf查看

$ netserver -h

Usage: netserver [options]

Options:
    -h                Display this text
    -D                Do not daemonize
    -d                Increase debugging output
    -f                Do not spawn chilren for each test, run serially
    -L name,family    Use name to pick listen address and family for family
    -N                No debugging output, even if netperf asks
    -p portnum        Listen for connect requests on portnum.
    -4                Do IPv4
    -6                Do IPv6
    -v verbosity      Specify the verbosity level
    -V                Display version information and exit
    -Z passphrase     Expect passphrase as the first thing received

$ netperf -h

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

2.3 测试场景及指标说明

2.3.1 测试模式
  • TCP_STREAM:client端向server端发送批量TCP数据。
  • UDP_STREAM:client端向server端发送批量UDP数据。
  • TCP_RR和TCP_CRR:前者是在同一个连接中进行多次request和response请求(并发),后者(新建)是每次请求新建一个连接(HTTP)。
  • UDP_RR:使用UDP进行request和response请求。
2.3.2 测试场景及性能指标
指标监控

sar命令监控网络指标,运行sar -n DEV 1如下:

# 安装sar命令,CentOS
$ sudo yum install sysstat
# 安装sar命令,Ubuntu
$ sudo apt-get install sysstat
# 监控网络性能指标
$ sar -n DEV 1
Linux 3.10.0-1160.21.1.el7.x86_64 (i-HKDvtZ7t2)         03/22/2024      _x86_64_        (4 CPU)

11:30:11 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
11:30:12 AM      eth0 646796.00      2.00  27160.40      0.39      0.00      0.00      0.00
11:30:12 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

字段解释:

  • rxpck:每秒收包数,单位pps
  • txpck:每秒发包数,单位pps
  • rxkB/s:接收带宽
  • txkB:发送带宽
测试场景及性能指标

测试场景:

测试场景客户端运行命令命令SAR监控指标
UDP 64netperf -t UDP_STREAM -H <server ip> -l 100 – -m 64 -R 1 &PPS
TCP 1440netperf -t TCP_STREAM -H <server ip> -l 100 – -m 1440 -R 1 &带宽
TCP RRnetperf -t TCP_RR -H <server ip> -l 100 – -r 32,128 -R 1 &PPS

性能指标:

指标说明
1440字节 TCP 收发带宽(Mbits/秒)表示通过 TCP 进行批量数据传输时的数据传输吞吐量,能反映网络极限带宽能力(可能会存在丢包)。
64字节 UDP 收发 PPS(包/秒)表示通过 UDP 进行批量数据传输时的数据传输吞吐量,能反映网络极限转发能力(可能会存在丢包)。
TCP-RR(次/秒)表示在 TCP 长链接中反复进行 Request/Response 操作的交易吞吐量,能反映 TCP 不丢包网络转发能力。

2.4 操作步骤

TCP带宽测试可以采用多流模型:

  • 当测试TCP发送带宽时,采用一对多模型,即保证接收端能力足够。
  • 当测试TCP接收带宽时,采用多对一模型,即保证发送端能力足够。
2.4.1 测试发包性能

以下测试为1台客户端,1台服务端。为了测试出最大发包性能,可以增加服务端(增加netserver进程或者机器)。

# server端
$ pkill netserver && pkill netperf
$ netserver
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC

# client端根据测试场景执行对应命令。客户端可以增减netperf进程,直到客户端发包性能不再增加。
# UDP 64测试发包pps。测试时长100s,发送测试分组的大小为64,也可设置为1进行测试。
$ netperf -t UDP_STREAM -H 172.16.0.9 -l 100 -- -m 64 -R 1 &
# TCP 1440测试发包带宽
$ netperf -t TCP_STREAM -H 172.16.0.9 -l 100 -- -m 1440 -R 1 &
# TCP_RR测试TCP不丢包转发能力,记录pps
$ netperf -t TCP_RR -H 172.16.0.9 -l 100 -- -r 32,128 -R 1 &     

# 在客户端执行sar命令,根据测试的场景记录对应的指标
$ sar -n DEV 1
Linux 3.10.0-1127.19.1.el7.x86_64 (i-uCoeT1mjZ)         03/22/2024      _x86_64_        (2 CPU)

12:25:01 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
12:25:02 PM      eth0  11444.00  11444.00   1095.23   1095.23      0.00      0.00      0.00
12:25:02 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
2.4.2 测试收包性能

以下测试为1台客户端,1台服务端。为了测试出最大收包性能,可以增加客户端(增加netperf进程或者机器)。

# server端
$ pkill netserver && pkill netperf
$ netserver
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC

# client端根据测试场景执行对应命令。客户端可以增减netperf进程,指导服务端收包性能不再增加。
# UDP 64测试发包pps。测试时长100s,发送测试分组的大小为64,也可设置为1进行测试。
$ netperf -t UDP_STREAM -H 172.16.0.9 -l 100 -- -m 64 -R 1 &
# TCP 1440测试发包带宽
$ netperf -t TCP_STREAM -H 172.16.0.9 -l 100 -- -m 1440 -R 1 &
# TCP_RR测试TCP不丢包转发能力,记录pps
$ netperf -t TCP_RR -H 172.16.0.9 -l 100 -- -r 32,128 -R 1 &     

# 在客户端执行sar命令,根据测试的场景记录对应的指标
$ sar -n DEV 1
Linux 3.10.0-1127.19.1.el7.x86_64 (i-uCoeT1mjZ)         03/22/2024      _x86_64_        (2 CPU)

12:25:01 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
12:25:02 PM      eth0  11444.00  11444.00   1095.23   1095.23      0.00      0.00      0.00
12:25:02 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

客户端启用多个netperf的脚本:

#!/bin/bash
count=$1
for ((i=1;i<=count;i++))
do
    echo "Instance:$i-------"
    # -H 后填写服务器 IP 地址;
    # -l 后为测试时间,为了防止 netperf 提前结束,因此时间设为 10000;
    netperf -t UDP_STREAM -H <server ip> -l 10000 -- -m 64 -R 1 &
done

参考资料:
阿里云ECS网络性能测试最佳实践
华为云网络性能测试方法
腾讯云netperf测试云服务器网络性能

3. socketperf测试网络带宽和时延

sockperf是基于套接字API的网络基准测试实用程序,旨在测试高性能系统的性能(延迟和吞吐量)。下面使用socketperf测试网络时延。

3.1 安装

# CentOS镜像源安装
$ sudo yum install sockperf
$ sudo apt-get install sockperf

# 通过源码安装
# Ubuntu安装依赖
$ sudo apt-get install libtool
# CentOS安装依赖
$ sudo yum install -y autoconf automake libtool gcc-c++

$ wget https://github.com/Mellanox/sockperf/archive/refs/tags/3.8.tar.gz
$ tar xf 3.8.tar.gz
$ cd sockperf-3.8/
$ sudo ./autogen.sh
$ sudo ./configure
$ sudo make && sudo make install

命令解析:

sockperf -h
sockperf is a tool for testing network latency and throughput.
version 3.8-no.git

Usage: sockperf <subcommand> [options] [args]
Type: 'sockperf <subcommand> --help' for help on a specific subcommand.
Type: 'sockperf --version' to see the program version number.

Available subcommands:
   help (h ,?)          Display list of supported commands.
   under-load (ul)      Run sockperf client for latency under load test.
   ping-pong (pp)       Run sockperf client for latency test in ping pong mode.
   playback (pb)        Run sockperf client for latency test using playback of predefined traffic, based on timeline and message size.
   throughput (tp)      Run sockperf client for one way throughput test.
   server (sr)          Run sockperf as a server.

For additional information visit our website http://github.com/mellanox/sockperf , see README file, or Type 'sockperf <subcommand> --help'.

通过man sockperf可以查看更详细的介绍。

3.2 测试网络带宽

# 测试机1运行如下命令启动服务
$ sockperf sr --tcp --daemonize

# 测试机2运行
$ sockperf tp -i 172.16.0.9 --tcp -t 30 -m 1440 --full-log=result.json
sockperf: == version #3.6-no.git ==
sockperf[CLIENT] send on:
[ 0] IP = 172.16.0.9      PORT = 11111 # TCP
sockperf: Warmup stage (sending a few dummy messages)...
sockperf: Starting test...
sockperf: Test end (interrupted by timer)
sockperf: Test ended
sockperf: Total of 1580358 messages sent in 30.000 sec

sockperf: NOTE: test was performed, using msg-size=1440. For getting maximum throughput consider using --msg-size=1472
sockperf: Summary: Message Rate is 52678 [msg/sec]
sockperf: Summary: BandWidth is 72.342 MBps (578.738 Mbps)

3.3 测试网络时延

准备两台机器,网络可达,分别安装sockperf。

# 测试机1运行如下命令启动服务
$ sockperf sr --tcp --daemonize

# 测试机2运行
$ sockperf pp -i 172.16.0.9 --tcp -t 30 -m 14 --full-log=result.json
sockperf: == version #3.8-no.git ==
sockperf[CLIENT] send on:sockperf: using recvfrom() to block on socket(s)

[ 0] IP = 172.16.0.9      PORT = 11111 # TCP
sockperf: Warmup stage (sending a few dummy messages)...
sockperf: Starting test...
sockperf: Test end (interrupted by timer)
sockperf: Test ended
sockperf: [Total Run] RunTime=30.000 sec; Warm up time=400 msec; SentMessages=379885; ReceivedMessages=379884
sockperf: ========= Printing statistics for Server No: 0
sockperf: [Valid Duration] RunTime=29.550 sec; SentMessages=373920; ReceivedMessages=373920
sockperf: ====> avg-latency=39.491 (std-dev=18.407, mean-ad=4.211, median-ad=3.914, siqr=2.671, cv=0.466, std-error=0.030, 99.0% ci=[39.413, 39.569])
sockperf: # dropped messages = 0; # duplicated messages = 0; # out-of-order messages = 0
sockperf: Summary: Latency is 39.491 usec
sockperf: Total 373920 observations; each percentile contains 3739.20 observations
sockperf: ---> <MAX> observation = 4097.089
sockperf: ---> percentile 99.999 = 1990.656
sockperf: ---> percentile 99.990 =  744.546
sockperf: ---> percentile 99.900 =  130.858
sockperf: ---> percentile 99.000 =   64.290
sockperf: ---> percentile 90.000 =   44.510
sockperf: ---> percentile 75.000 =   41.040
sockperf: ---> percentile 50.000 =   38.170
sockperf: ---> percentile 25.000 =   35.697
sockperf: ---> <MIN> observation =   27.761

3.4 结果分析

查看上述结果数据,示例如下图所示。

  • 以avg-latency开头的结果数据表示平均时延,单位为us。

  • 以percentile 99.000开头的结果数据表示99分位时延,单位为us。

参考资料:
阿里云ECS网络性能测试最佳实践

iperf 网络性能测试工具 iperf是一款网络性能测试工具, 可以测试通过网络连接的最大带宽。主要用于测试 TCP 和 UDP 带宽性能,它可以帮助你测量不同类型和大小的网络环境中的网络吞吐量。 阅读详情

相关推荐

iperf —— 网络性能测试工具,编译、安装、使用笔记

文章目录1. 背景2. 编译2.1 下载2.2 编译3. 安装4. 使用5. 参考 1. 背景 为了测试嵌入式SOC的网络性能,需要一个能够测试带宽、抖动、丢包率等参数的工具,在linux系统中常用iperf,其在嵌入式linux中是否好用,我们继续探索。 iperf命令 是一个网络性能测试工具。 iperf可以测试TCP和UDP带宽质量。 iperf可以测量最大TCP带宽,具有多种参数和UDP特性。 iperf可以报告带宽,延迟抖动和数据包丢失。 利用iperf这些特性,可以用来测试一些网络设备如路由

汽车电子软件领域知识分享 6983

网络性能测试的必备工具:iperf详解与实践

iperf是一个开源网络性能测试工具,它能够测量带宽、吞吐量、延迟和丢包率等网络性能指标。本文将介绍iperf的常用命令和选项,并给出Windows和Linux平台的配置示例。

伤心的辣条 2万+

Netperf网络性能测试:从原理到实战的完整指南

网络性能测试是评估和优化网络基础设施的关键环节,它通过量化带宽、延迟、吞吐量等核心指标,帮助工程师诊断瓶颈、验证配置和规划容量。其原理基于客户端-服务器模型,通过模拟真实的数据流模式来测量网络链路的极限性能。这项技术的价值在于为网络优化、硬件选型和故障排查提供客观、可重复的数据依据,广泛应用于数据中心、云计算、金融交易和高性能计算等场景。本文以经典的Netperf工具为例,深入解析其TCP_STREAM和TCP_RR测试模型,并通过实战演示如何部署、调优及解读结果,其中涉及**TCP窗口**调整和**缓冲区

weixin_30781107的博客 403

网络性能评估工具Iperf详解(可测丢包率)

网络性能评估工具Iperf详解(可测丢包率) 一、网络性能评估工具Iperf 网络性能评估主要是监测网络带宽的使用率,将网络带宽利用最大化是保证网络性能的基础,但是由于网络设计不合理、网络存在安全漏洞等原因,都会导致网络带宽利用率不高。要找到网络带宽利用率不高的原因,就需要对网络传输进行监控,此时就需要用到一些网络性能评估工具,而Iperf就是这样一款网络带宽测试工具,本节将详细介绍一下Iperf...

bingyu的博客 12万+

TCP/UDP协议栈性能测试实战:iperf3、netperf与sockperf工具详解

网络性能测试是链路评估与故障排查的关键环节,其核心原理是通过构造标准流量,测量吞吐量、丢包率、延迟和抖动等基础指标。这些数据能直接反映协议栈、网卡驱动及内核参数的真实表现,为云主机选型、容器网络调优、专线验收和中间件压测提供量化依据。在众多测试工具中,iperf3 以简单易用成为带宽验证的首选,netperf 适合批量回归测试,而 sockperf 则专注于延迟与每秒消息数场景。掌握这三种工具的组合使用,并理解多线程、缓冲区、拥塞控制及 UDP 小包等关键参数的影响,即可快速定位网络瓶颈。本文围绕 TCP/

weixin_32244597的博客 296

Linux系统性能压测实战:从CPU、内存到网络的全链路工具与工程实践

在系统性能优化领域,精准的测量是避免“盲人摸象”的关键。性能压测的核心原理在于通过模拟特定负载,量化系统在CPU、内存、磁盘IO、网络及HTTP等维度的处理能力与瓶颈。其技术价值在于将性能评估从经验猜测转变为数据驱动的科学决策,是保障系统稳定性、可扩展性和用户体验的基石。典型应用场景包括新服务上线前的容量规划、架构变更后的性能回归测试、以及生产环境突发性能问题的根因定位。本文聚焦于Linux环境,深入解析以stress-ng、fio、iperf3、wrk为代表的压测工具矩阵,并结合perf、iostat等分

weixin_34032792的博客 380

Linux 系统性能压测工具全景指南(含工程实战)

在讨论工具之前,我们先明确一个核心问题:压测的核心价值是什么?真实工程场景中,“系统慢”的排查往往陷入误区:出现这种情况,大概率是因为没有找到真正的瓶颈——可能是CPU已经被计算任务打满,导致进程无法及时调度;可能是磁盘IO读写阻塞,数据库无法快速读取数据;也可能是网络带宽耗尽,请求无法正常传输;甚至是内存不足触发swap,导致系统性能断崖式下降。而压测,就是解决这种“盲目排查”的关键,其核心意义体现在4个方面:找到系统极限:明确系统在不同并发、不同负载下的性能上限(如QPS、TPS、响应时间),避免生产环

jlx8S4M50的博客 507

Windows环境下的iperf网络性能测试指南

在当今数字化的时代背景下,网络性能测试是确保数据传输质量的重要环节。iperf是一种被广泛使用的开源网络性能测试工具,它通过模拟数据传输来测试网络带宽、延迟、丢包等关键性能指标。iperf以其简洁的界面和强大的功能,成为了IT专业人士和网络工程师们在优化网络配置、故障排除和性能监控等场景中的得力助手。通过iperf,可以模拟不同类型的数据传输(如TCP和UDP),从而对网络进行精细的测量和分析。

weixin_29155599的博客 3833

以太网模块性能优化全攻略:从硬件配置到Linux驱动调优

以太网作为现代嵌入式系统和工业控制的核心通信技术,其底层原理基于CSMA/CD协议和MAC帧结构,通过物理层与数据链路层的协同工作实现设备间的可靠数据传输。在工程实践中,为了充分发挥以太网的性能潜力,需要从硬件选型、IP核配置、驱动优化到应用层调优进行全链路设计。例如,通过合理配置DMA缓冲区深度和启用Scatter Gather DMA可以显著提升数据吞吐效率;在Linux系统中,利用ethtool工具调整中断合并参数与多队列设置,能够有效平衡CPU负载与网络延迟。这些优化技术对于高速数据采集、视频流传输

weixin_34413802的博客 356

蓝牙6.0的‘新雷达’:Channel Sounding信道探测,真能比UWB更香吗?

本文探讨了蓝牙6.0的Channel Sounding信道探测技术在室内定位领域的应用潜力。通过与UWB技术的对比分析,揭示了其在成本、功耗和兼容性方面的优势,特别是在智能门锁、物品追踪等场景中的商业价值。Channel Sounding技术不仅具备亚米级精度,还能通过现有蓝牙设备实现零边际成本部署,为物联网应用提供了新的解决方案。

weixin_29288313的博客 346

STM32单片机远程升级

stm32远程升级

fang_yang_wa的博客 1万+

iperf详细使用方法

Iperf 是一个网络性能测试工具。Iperf可以测试TCP和UDP带宽质量。Iperf可以测量最大TCP带宽, 具有多种参数和UDP特性。Iperf可以报告带宽,延迟抖动和数据包丢失。 Iperf使用方法与参数说明 参数说明 -s 以server模式启动,eg:iperf -s -c host 以client模式启动,host是server端地址,eg:iperf -c 222.35.11.23 通用参数 -f [k|m|K|M] 分别表示以Kbits, Mbit...

hnlgzb的专栏 1万+

计组实验之四路表决器

请在之前四路表决器电路实现的基础上,继续用连接线 联接CD4511,将投票为1的票数总和显示到一个 LED上,思考如何做?由于我们需要通过显示字形来直接看出有几个1,在这里,我们最多有四个1,即显示字形最多到4就行,所以我们需要将有几个1用2进制数来表示,下面给出了相关电路图。显示输入插口,按真值表(自拟)要求,逐次改变输入变量, 测量相应的输出值,验证逻辑功能, 与表3-1 进行比较, 验证所设计的逻辑电路是否符合要求。用实验结果与真值表3-1和3-2进行比对,可以得出,我们实验结果是正确的。

szyugly的博客 1万+

netperf的安装、性能测试、参数、启动报错的坑、实例

netperf介绍 netperf是一个基于client-server模式的网络测试工具,可以测量TCP和UDP传输的吞吐量、时延、CPU占用率等性能参数。 它可以测试以下几种模式的TCP核UDP网络性能: TCP_STREAM:client端向server端发送批量TCP数据 UDP_STREAM:client端向server端发送批量UDP数据 TCP_RR和TCP_CRR:前者是在同一个连接中进行多次request和response请求(并发),后者(新建)是每次请求新建一个连接(HTTP) UDP

仙女肖消乐的博客 2万+

大漠插件找图找字避坑手册:从ziku0.txt字库制作到易语言精准识别(附综合工具实操)

本文深入解析大漠插件在图像识别中的核心难点,提供从ziku0.txt字库精准制作到易语言高效调用的完整避坑指南。重点讲解如何利用大漠综合工具科学设置偏色与二值化参数,生成高质量色彩描述字符串,并分享识别失败的系统排查方法与进阶优化策略,旨在实现99%的稳定识别率。

weixin_29264201的博客 1224

华为MetaERP的交易计税模块(即“税务引擎”)在设计上确实受到Oracle E-Business Tax(EBTax)等国际先进税务架构理念的影响,但结合了华为自身全球化运营、多准则合规、高并发处

华为MetaERP税务引擎在借鉴Oracle EBTax三层架构基础上,创新升级为五层智能税务架构,实现从"税码驱动"到"场景+规则+AI驱动"的转变。该模块采用云原生微服务架构,支持全球190+国家税务规则动态加载,具备实时计税、多准则并行处理、AI风险预警等核心能力,深度适配金税工程等国内合规要求。通过税务数字孪生、RPA机器人等创新,形成自主可控的智能税务中枢,为跨国企业提供全栈国产化税务解决方案,重新定义ERP税务管理范式。

金牌架构师 117

iperf详解与实践

iperf 是一个基于 Client/Server 的网络性能测试工具,可以测试 TCP、UDP 和 SCTP 带宽质量,能够提供网络吞吐量信息,以及震动、丢包率、最大段和最大传输单元大小等统计信息,帮助我们测试网络性能,定位网络瓶颈,其好处是纯粹的发包和接收,不会被硬盘、Flash的等读写速度影响测试结果。

不能将运气当成战略! 5855

Unity零基础到入门 ☀️| 近万字教程 对 Unity 中的 动画系统基础 全面解析+实战演练,你确定要错过吗?

Unity动画系统,Animation,Animator。 本文对Unity中的动画系统基础做了一个全面解析,还包括实战演练。近万字教程让你对Unity的动画系统有一个系统的了解,敬请品尝!

努力前行,总会成为自己心中的那道光 9万+

全网最完整的iperf测试工具使用说明

iPerf - TCP、UDP 和 SCTP 的终极速度测试工具。常用的的网络限制 + 互联网中立性测试工具。被广为认可。但是国内网站上的iperf使用说明都含糊不清甚至是错的,没办法只能自己手动翻译和搬运了官网上的iperf手册。

墨染锦年的博客 1万+

DDR5 的 PI: DIMM 上 PMIC,正在制造一批“新型 EMI 问题”

DDR5 的 PI,不再只是“供电设计”,而是一次“噪声管理设计”。电压稳定本地调节高频噪声EMI 风险系统不确定性DDR5 真正难的地方,不是跑起来,而是——在最差条件下,它还能不能一直跑。而 DIMM 上那颗 PMIC,正是你绕不开的关键角色。

weixin_43199439的博客 193

3. Matérn协方差模型与随机偏微分方程

对应的高斯马尔可夫随机场 (GMRF)可以通过使用某种随机偏微分方程(SPDE)明确构造,当由高斯白噪声驱动时,随机偏微分方程的解是具有 Matérn 协方差函数的高斯场(GF)

weixin_40614311的博客 1752

iperf3网络性能测试工具在windows下的使用方法

iperf3网络性能测试工具在windows下的使用方法 一、下载工具 1、下载iperf3 2、打开iperf3 二、使用iperf3开始测试。 1、iperf3测试准备 2、iperf3服务端操作 3、iperf3客户端操作 三、iperf3参数说明 1、iperf3共用参数说明 2、iperf3服务器参数说明 3、iperf3客户端参数说明

m0_60027682的博客 4万+

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Netperf网络测试

Netperf网络测试

教Linux的李老师 5456

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

快速上手:iperf网络性能测试工具

iperf命令是一个网络性能测试工具,可以测试TCP和UDP带宽质量。同时也可以通过UDP测试报告网丢包率或者发包性能,是一个非常实用的工具。目录iperf安装带宽测试(TCP、UDP分开测试)网络收发包性能测试iperf安装可以直接通过官网下载对应系统版本进行安装(https://iperf.fr/iperf-download.php)1.对于windows版的iPerf,直接将解压出来的ipe...

关注微信公众号【开源Linux】,后台回复『10T』,领取10T学习资源大放送,涵盖Linux、虚拟化、容器、云计算、网络、Python、Go等书籍和视频 3756

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

性能测试工具iPerf和Netperf使用介绍

实验教程 任务目的 1、 掌握iPerf的功能和基本命令,利用iPerf测试主机之间的吞吐量,熟悉基本命令参数的作用,为后期实验做准备。 2、 掌握Netperf的功能和基本命令,能够根据不同的测试需求使用不同的命令参数。 任务环境 设备名称 软件环境(镜像) 硬件环境 控制器 Floodlight 1.0桌面版 CPU:1核 内存:2G 磁盘:20G 交换机 Open vSwitch 2.3.1命令行版 CPU:1核 内...

qq_48490728的博客 9050

netperf常用命令使用方法

启动netserver服务报错解决方案:这个错误提示意味着netserver无法使用给定的IP地址和端口号来启动监听服务。可能的解决方案包括:检查是否已经有其他程序在占用端口号12865。可以使用命令来列出当前正在监听的端口,并查找是否有其他程序正在使用12865端口。使用sudo权限来启动netserver,以确保有足够的权限。确保输入的IP地址和端口号正确。如果IP地址不正确,可以尝试使用特定的IP地址(如127.0.0.1)或替换为主机名。

captain 5568
上一篇: LM Studio本地离线部署大语言模型
下一篇: python函数中的*args, **kwargs
KongTY312
博客等级 码龄12年 2143粉丝 189原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KongTY312

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址