Iperfの使用方法 (Linuxネットワーク帯域確認方法)

World Clock

Iperfの使用方法 (Linuxネットワーク帯域確認方法)ネットワーク帯域ベンチマークツール「Iperf」を用いて、サーバ間の実効ネットワーク帯域・ネットワーク転送性能を測定する際の手順メモです。

「Iperf」は、Server(Receiver)とClient(Sender)で詳細な条件を指定してTCP・UDPのネットワーク転送性能を測定できる優れたベンチマークツールです。Windows版も提供されており、LinuxサーバとWindowsサーバ・Windows PC間のネットワーク帯域を確認する用途でも利用できます。

動作確認環境
  • CentOS 5.8 (RHEL 5.8 クローンOS)
  • CentOS 6.2 (RHEL 6.2 クローンOS)
  • Iperf 2.0.5
ソースのダウンロード URL

次のURLより、tar.gz形式で圧縮されたソースファイル一式をダウンロードして下さい。
http://sourceforge.net/projects/iperf/

Iperf インストール

make

ソースファイル一式を解凍して、configureとmakeを行います。

$ cd /home/yourusername
$ tar xzvf iperf-2.0.5.tar.gz
$ cd iperf-2.0.5
$
$ ./configure
$ make
make install

root権限で /usr/local/bin 配下にインストールします。
Server(Receiver)とClient(Sender)になる2台のサーバにインストールして下さい。

$ su -
# cd /home/yourusername/iperf-2.0.5
# make install
# exit

Iperf 実行(ネットワーク帯域の計測)

Linux NICRight ArrowLinux NIC
Iperf Client
(Sender)
dataIperf Server
(Receiver)

 

Iperf Server側 : 測定用のServer起動

ServerのIPアドレスが分からない場合は、起動前にifconfigコマンドで確認しておきます。

$ ifconfig

通信を待ち受けるIperf Server(Receiver)を起動します。

$ iperf -s

Iperf Serverは標準では5001番ポートでLISTENしています。FireWall等の制約があり、例えば「8080番ポート」に変更して測定する場合には、次のように指定してIperf Serverを起動します。

$ iperf -s -p 8080
Iperf Client側 : 測定実行

ServerのIPアドレスが「192.168.1.1」で「8080番ポート」でLISTENしている場合は、Iperf Client(Sender)側で次のように指定して実行します。標準の5001番ポートを使用する場合は、-pオプションは指定不要です。

$ iperf -c 192.168.1.1 -p 8080

実行時に「connect failed: No route to host」というエラーメッセージが出て接続できない場合は、NW経路上のFireWallやサーバのiptablesの設定を確認して下さい。
 

Iperf Server側 : 測定用のServer停止

測定が終了したら、CTRL+C を押下してIperf Serverを停止します。

CTRL+C

Iperf 実行結果の見方

測定終了後、次のような実行結果が表示されます。
サーバ間で 935 Mbits/sec の実効ネットワーク帯域を持っていることが分かります。

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 8080
TCP window size:  330 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.2 port 45076 connected with 192.168.1.1 port 8080
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.09 GBytes   935 Mbits/sec

こちらは、2台のサーバを10GbEの光ファイバーケーブルで直結した際の実行結果です。10GbEのワイヤースピードを発揮していることが分かります。

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 8080
TCP window size: 64.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.2 port 48200 connected with 192.168.1.1 port 8080
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  11.5 GBytes  9.92 Gbits/sec

Iperf の色々な使い方

双方向の通信を同時に計測する(-dオプション)

Iperf Server側 : 通信を待ち受けるIperf Server(Receiver)を起動します。

$ iperf -s

Iperf Client側 : 次のように-dオプションを付けてIperfを実行します。コマンド実行後にClient側でもIperf Serverが自動で起動して、双方向の計測が開始されます。

$ iperf -c 192.168.1.1 -d
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size:  189 KByte (default)
------------------------------------------------------------
[  5] local 192.168.1.2 port 47814 connected with 192.168.1.1 port 5001
[  4] local 192.168.1.2 port 5001 connected with 192.168.1.1 port 47443
[ ID] Interval       Transfer     Bandwidth
[  5]  0.0-10.0 sec  1.05 GBytes   897 Mbits/sec
[  4]  0.0-10.0 sec  1.02 GBytes   873 Mbits/sec
計測時に起動するスレッド数を指定する(-Pオプション)

Iperf Client側 : 次のように-Pオプションを付けてIperfを実行します。この例では、計測時に起動するスレッド数を「2」に指定しています。シングルスレッドでネットワーク帯域を使い切れない場合には、スレッド数を調整して下さい。

$ iperf -c 192.168.1.1 -P 2
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size:  189 KByte (default)
------------------------------------------------------------
[  4] local 192.168.1.2 port 35242 connected with 192.168.1.1 port 5001
[  3] local 192.168.1.2 port 35241 connected with 192.168.1.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.0 sec   563 MBytes   472 Mbits/sec
[  3]  0.0-10.0 sec   566 MBytes   473 Mbits/sec
[SUM]  0.0-10.0 sec  1.10 GBytes   944 Mbits/sec
輻輳制御アルゴリズムを指定して計測する(-Zオプション)

Iperfの起動前にsysctlコマンドで現在設定されている輻輳制御アルゴリズムを確認しておきます。
RHEL5系のデフォルト設定は「bic」、RHEL6系のデフォルト設定は「cubic」です。
(参考 : Linuxカーネルパラメータ一覧・標準設定 (CentOS 6)

# sysctl -a | grep tcp_congestion_control
net.ipv4.tcp_congestion_control = cubic

Iperf Server側 : 次のように-Zオプションを付けて輻輳制御アルゴリズムを指定し、通信を待ち受けるIperf Server(Receiver)を起動します。ここではアルゴリズムに「reno」を指定しています。

$ iperf -s -Z reno

Iperf Client側 : Server側と同様に-Zオプションを付けて輻輳制御アルゴリズムを指定します。輻輳が発生しやすいように双方向通信の-dオプションも付けてIperfを実行します。

$ iperf -c 192.168.1.1 -d -Z reno
Iperf 実行オプション一覧
$ iperf --help
Usage: iperf [-s|-c host] [options]
       iperf [-h|--help] [-v|--version]
Client/Server:
  -f, --format    [kmKM]   format to report: Kbits, Mbits, KBytes, MBytes
  -i, --interval  #        seconds between periodic bandwidth reports
  -l, --len       #[KM]    length of buffer to read or write (default 8 KB)
  -m, --print_mss          print TCP maximum segment size (MTU - TCP/IP header)
  -o, --output    <filename> output the report or error message to this specified file
  -p, --port      #        server port to listen on/connect to
  -u, --udp                use UDP rather than TCP
  -w, --window    #[KM]    TCP window size (socket buffer size)
  -B, --bind      <host>   bind to <host>, an interface or multicast address
  -C, --compatibility      for use with older versions does not sent extra msgs
  -M, --mss       #        set TCP maximum segment size (MTU - 40 bytes)
  -N, --nodelay            set TCP no delay, disabling Nagle's Algorithm
  -V, --IPv6Version        Set the domain to IPv6
Server specific:
  -s, --server             run in server mode
  -U, --single_udp         run in single threaded UDP mode
  -D, --daemon             run the server as a daemon
Client specific:
  -b, --bandwidth #[KM]    for UDP, bandwidth to send at in bits/sec
                           (default 1 Mbit/sec, implies -u)
  -c, --client    <host>   run in client mode, connecting to <host>
  -d, --dualtest           Do a bidirectional test simultaneously
  -n, --num       #[KM]    number of bytes to transmit (instead of -t)
  -r, --tradeoff           Do a bidirectional test individually
  -t, --time      #        time in seconds to transmit for (default 10 secs)
  -F, --fileinput <name>   input the data to be transmitted from a file
  -I, --stdin              input the data to be transmitted from stdin
  -L, --listenport #       port to receive bidirectional tests back on
  -P, --parallel  #        number of parallel client threads to run
  -T, --ttl       #        time-to-live, for multicast (default 1)
  -Z, --linux-congestion <algo>  set TCP congestion control algorithm (Linux only)
Miscellaneous:
  -x, --reportexclude [CDMSV]   exclude C(connection) D(data) M(multicast) S(settings) V(server) reports
  -y, --reportstyle C      report as a Comma-Separated Values
  -h, --help               print this message and quit
  -v, --version            print version information and quit
[KM] Indicates options that support a K or M suffix for kilo- or mega-
The TCP window size option can be set by the environment variable
TCP_WINDOW_SIZE. Most other options can be set by an environment variable
IPERF_<long option name>, such as IPERF_BANDWIDTH.

関連記事

姫野ベンチの使用方法・測定結果一覧 (Linux編)
STREAMの使用方法 (Linuxメモリ帯域幅の計測方法)
HDDベンチマーク手順+性能測定結果一覧 (hdparm,dd,bonnie++)
Iperfの使用方法 (Linuxネットワーク帯域確認方法)
 
ネットワーク構成図の書き方 – 参考サイトの厳選リンク集
ネットワーク構成図を作成する際に役立つ参考サイトのリンク集です。
作成にあたって最低限押さえておくべき基本的な情報と、厳選したサンプル図面をまとめています。
 
「Linux」カテゴリーの記事一覧