LIFULL Creators Blog

LIFULL Creators Blogとは、株式会社LIFULLの社員が記事を共有するブログです。自分の役立つ経験や知識を広めることで世界をもっとFULLにしていきます。

iperf3の使い方まとめ

こんにちは、@szkkentaroです。

最近は、がっつりAWS周りのお仕事をさせてもらっています。

皆さんはネットワークのパフォーマンス測定にどんなツールを使っていますか? 自分の場合は、以前からIperfを利用してきました。

この度、ひさびさに利用する機会がありソースをダウンロードしに行ったら、 なんと、iperf3がstableになっているではありませんか!

ということで、 Iperf(ver.2系)の後継バージョンであるiperf3の使い方と追加機能についてまとめてみようと思います。

Iperfとは

TCPやUDPでネットワーク帯域のパフォーマンスを測定するC言語で書かれたツールになります。 2台のサーバーにて、それぞれサーバーモード、クライアントモードとして動作させることで、 サーバ間の帯域をテストすることができます。

Iperfとiperf3の違い

iperf3 is a new implementation from scratch, with the goal of a smaller, simpler code base, and a library version of the functionality that can be used in other programs. iperf3 also a number of features found in other tools such as nuttcp and netperf, but were missing from iperf2.X.

iperf3は、より小さくてよりシンプルなコードをベースにして、他のプログラムから使うことができる機能的なライブラリを目指し、スクラッチから実装され直されたそうです。また、iperf2系にはなくnuttcpやnetperf のような他のツールにあるいくつかの機能が追加されています。

個人的には、ユーティリティ系の機能追加が多いような印象を受けました。新しい機能については後述します。

現時点(2014/02/07)時点での、Stableなバージョンと、ダウンロード先を表にしてみました。

名前 バージョン ホスティング 最終更新日
Iperf 2.0.5 sourceforge.net 2010/07/09
iperf3 3.0.1 code.google.com 2014/01/10

ちなみに、名前の1文字目ですが、ver2系は大文字の『 I 』で、ver3系は小文字の『 i 』を使っています。 これは、以下ソースコードのホスティング(ダウンロード)先で使われている名前と、wikipediaに習って意図的にそうしました。

留意点

iperf3 is supported on Linux, FreeBSD (FreeBSD Ports Collection), and MacOS X only. (Windows is not currently supported.)

iperf3はWindowsにまだ対応していません。

Note that iperf3.X is not backwards compatible with iperf2.X.

また後方互換性もないようなので気をつけたいと思います。

インストール

iperf3のインストールは、とっても簡単です。 Amazon Linuxで試した感じでは、gccを先にインストールし、 iperf3をソースからさくっとインストールできます。

sudo yum install gcc -y
wget http://stats.es.net/software/iperf-3.0.1.tar.gz
tar zxvf iperf-3.0.1.tar.gz 
cd iperf-3.0.1
./configure
make
sudo make install
type iperf3 # iperf3 is /usr/local/bin/iperf3

※ Iperf(ver2系)をインストールする場合にはgccと、gcc-c++が必要になります。

基本的な使い方

サーバ側を待ち受け状態にし、クライアント側からパフォーマンステストを行います。

以下の例では、クライアント(172.20.17.181)とサーバ(172.20.17.182)間について、 3秒のパフォーマンステストを行った例になります。

サーバ側

[ec2-user@ip-172-20-17-182 ~]$ iperf3 -s

クライアント側

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 
Connecting to host 172.20.17.182, port 5201
[ 4] local 172.20.17.181 port 44130 connected to 172.20.17.182 port 5201
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-1.02 sec 18.6 MBytes 154 Mbits/sec 18 
[ 4] 1.02-2.02 sec 16.6 MBytes 139 Mbits/sec 4 
[ 4] 2.02-3.01 sec 18.0 MBytes 153 Mbits/sec 12 
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-3.01 sec 53.2 MBytes 148 Mbits/sec 34 sender
[ 4] 0.00-3.01 sec 53.0 MBytes 148 Mbits/sec receiver
iperf Done.

Iperfと基本的な使い方は変わっていなかったので、すぐに使うことができました。

iperf3での新機能

iperf3で追加された機能を見ていきます。

タイトルをつける

-T, --title str prefix every output line with this string

大文字Tのオプションで、出力にプレフィックスをつけることができます。

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 -T `date +%F` 
2014-02-03: Connecting to host 172.20.17.182, port 5201
2014-02-03: [ 4] local 172.20.17.181 port 44122 connected to 172.20.17.182 port 5201
2014-02-03: [ ID] Interval Transfer Bandwidth Retr
2014-02-03: [ 4] 0.00-1.00 sec 27.5 MBytes 231 Mbits/sec 10 
2014-02-03: [ 4] 1.00-2.00 sec 25.8 MBytes 216 Mbits/sec 1 
2014-02-03: [ 4] 2.00-3.00 sec 26.0 MBytes 218 Mbits/sec 4 
2014-02-03: - - - - - - - - - - - - - - - - - - - - - - - - -
2014-02-03: [ ID] Interval Transfer Bandwidth Retr
2014-02-03: [ 4] 0.00-3.00 sec 79.2 MBytes 222 Mbits/sec 15 sender
2014-02-03: [ 4] 0.00-3.00 sec 78.9 MBytes 221 Mbits/sec receiver
2014-02-03: 
2014-02-03: iperf Done.

Iperf(ver2系)では、Tオプションは、ttlを設定するオプションなので注意が必要ですね。

-T, --ttl # time-to-live, for multicast (default 1)

詳細情報を表示する

-V, --verbose more detailed output

地味に嬉しい機能です。

定期的に帯域テストをしてログ出力するような場合などは、versionやCPU Utilizationの表示が便利そうですね。

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 -V 
iperf version 3.0.1 (10 January 2014)
Linux ip-172-20-17-181 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Time: Mon, 03 Feb 2014 11:36:04 GMT
Connecting to host 172.20.17.182, port 5201
Cookie: ip-172-20-17-181.1391427364.967092.2
TCP MSS: 1448 (default)
[ 4] local 172.20.17.181 port 44124 connected to 172.20.17.182 port 5201
Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, omitting 0 seconds, 3 second test
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-1.01 sec 22.0 MBytes 182 Mbits/sec 21 
[ 4] 1.01-2.00 sec 22.5 MBytes 191 Mbits/sec 51 
[ 4] 2.00-3.00 sec 19.1 MBytes 160 Mbits/sec 5 
- - - - - - - - - - - - - - - - - - - - - - - - -
Test Complete. Summary Results:
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-3.00 sec 63.6 MBytes 178 Mbits/sec 77 sender
[ 4] 0.00-3.00 sec 63.1 MBytes 176 Mbits/sec receiver
CPU Utilization: local/sender 2.3% (0.9%u/1.8%s), remote/receiver 0.5% (0.1%u/0.4%s)
iperf Done.

はじめのn秒を省く

-O, --omit N omit the first n seconds

最初の数秒を統計から省くことができます。 接続直後のネットワークが不安定な場合などに異常値を弾くことができて便利ですね。

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 -O 1
Connecting to host 172.20.17.182, port 5201
[ 4] local 172.20.17.181 port 44132 connected to 172.20.17.182 port 5201
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-1.00 sec 18.1 MBytes 152 Mbits/sec 10 (omitted)
[ 4] 0.00-1.10 sec 22.9 MBytes 174 Mbits/sec 2 
[ 4] 1.10-2.00 sec 13.6 MBytes 127 Mbits/sec 0 
[ 4] 2.00-3.00 sec 20.6 MBytes 173 Mbits/sec 2 
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-3.00 sec 57.1 MBytes 160 Mbits/sec 4 sender
[ 4] 0.00-3.00 sec 58.4 MBytes 163 Mbits/sec receiver
iperf Done.

リバースモード

-R, --reverse run in reverse mode (server sends, client receives)

通常はクライアントから送信するのですが、このオプションを付けるとサーバから送信するモードになります。 サーバーとクライアントを入れ替えて帯域のテストをしたい場合に簡単にできます。

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 -R 
Connecting to host 172.20.17.182, port 5201
Reverse mode, remote host 172.20.17.182 is sending
[ 4] local 172.20.17.181 port 44154 connected to 172.20.17.182 port 5201
[ ID] Interval Transfer Bandwidth
[ 4] 0.00-1.01 sec 23.5 MBytes 196 Mbits/sec 
[ 4] 1.01-2.01 sec 27.6 MBytes 232 Mbits/sec 
[ 4] 2.01-3.01 sec 24.4 MBytes 204 Mbits/sec 
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-3.01 sec 76.2 MBytes 213 Mbits/sec 28 sender
[ 4] 0.00-3.01 sec 76.0 MBytes 212 Mbits/sec receiver
iperf Done.

JSONで出力する

-J, --json output in JSON format

詳細情報をJSONフォーマットで出力することができるので、mongoDBやElasticSearchに入れたりするのに使えそうです。

[ec2-user@ip-172-20-17-181 ~]$ iperf3 -c 172.20.17.182 -t 3 -J 
{
    "start": {
        "version": "iperf version 3.0.1 (10 January 2014)",
        "system_info": "Linux ip-172-20-17-181 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux\n",
        "timestamp": {
            "time": "Mon, 03 Feb 2014 11:37:29 GMT",
            "timesecs": 1391427449
        },
        "connecting_to": {
            "host": "172.20.17.182",
            "port": 5201
        },
        "cookie": "ip-172-20-17-181.1391427449.704612.4",
        "tcp_mss_default": 1448,
        "connected": {
            "socket": 4,
            "local_host": "172.20.17.181",
            "local_port": 44128,
            "remote_host": "172.20.17.182",
            "remote_port": 5201
        },
        "test_start": {
            "protocol": "TCP",
            "num_streams": 1,
            "blksize": 131072,
            "omit": 0,
            "duration": 3,
            "bytes": 0,
            "blocks": 0
        }
    },
    "intervals": [
        {
            "streams": [
                {
                    "socket": 4,
                    "start": 0,
                    "end": 1.00007,
                    "seconds": 1.00007,
                    "bytes": 24641536,
                    "bits_per_second": 1.97119E+8,
                    "retransmits": 50,
                    "snd_cwnd": 127424,
                    "omitted": false
                }
            ]
        },
        {
            "streams": [
                {
                    "socket": 4,
                    "start": 1.00007,
                    "end": 2.00013,
                    "seconds": 1.00006,
                    "bytes": 19398656,
                    "bits_per_second": 1.5518E+8,
                    "retransmits": 1,
                    "snd_cwnd": 128872,
                    "omitted": false
                }
            ]
        },
        {
            "streams": [
                {
                    "socket": 4,
                    "start": 2.00013,
                    "end": 3.00011,
                    "seconds": 0.999985,
                    "bytes": 15990784,
                    "bits_per_second": 1.27928E+8,
                    "retransmits": 3,
                    "snd_cwnd": 141904,
                    "omitted": false
                }
            ]
        }
    ],
    "end": {
        "streams": [
            {
                "sender": {
                    "socket": 4,
                    "start": 0,
                    "end": 3.00011,
                    "seconds": 3.00011,
                    "bytes": 60030976,
                    "bits_per_second": 1.60077E+8,
                    "retransmits": 54
                },
                "receiver": {
                    "socket": 4,
                    "start": 0,
                    "end": 3.00011,
                    "seconds": 3.00011,
                    "bytes": 59375616,
                    "bits_per_second": 1.58329E+8
                }
            }
        ],
        "cpu_utilization_percent": {
            "host_total": 2.26325,
            "host_user": 0.258657,
            "host_system": 2.32805,
            "remote_total": 0.921219,
            "remote_user": 0.117254,
            "remote_system": 0.787269
        }
    }
}

他にも

CPU Affinityの設定や、zero copyでの送信など、しっかり計測したい場合のオプションが追加されています。

-A, --affinity n/n,m set CPU affinity

-Z, --zerocopy use a 'zero copy' method of sending data

また、linux-congestionなどはオプションが "-Z" から "-C" へと、若干変わってたりするので気をつけたいですね。

-Z, --linux-congestion set TCP congestion control algorithm (Linux only) # Iperf

-C, --linux-congestion set TCP congestion control algorithm (Linux only) # iperf3

まとめ

主に、iperf3の新機能について見てきました。

基本的な操作は、ほとんどIperfと変わっていないので以前からのユーザは違和感なく使えると思います。

先に書きましたが、出力の形を整える機能や計測に対しての細かい設定ができるようになったのがありがたいですね。 また、測定結果の単位にG(ギガ)が追加されたことも時代の流れを感じてしまいました。

昔から使っている方も、新しく使いはじめる方も癖なく使えると思いますので、 是非、iperf3を触ってみてください!

参考リンク

https://code.google.com/p/iperf/

http://sourceforge.net/projects/iperf/

http://en.wikipedia.org/wiki/Iperf