こんにちは、阿形です。
Linux、Mac、Windowsの各端末の間で、ネットワーク性能を計測したい場合について取り上げます。
と言いながら、早速Windowsの方はこちらの弊社運営の中小企業向けIT情報提供サイト、「まちIT」の方へどうぞ。
ネットワークの性能測定ツールとして、Linuxの定番はiperf3です。ですが、このツールはWindowsにおいてはMicrosoftが非推奨としています。
世間ではWindowsでも気にせずiperf3で計測しているようですが、こちらのMicrosoftの記事にあるように、WindowsのネイティブAPIで動いていないため、実際の性能とは異なった結果となってしまう可能性があります。
Windowsの方は上記の「まちIT」の記事を参照して、ntttcpを使用するようにしましょう。
なお、当然ですが、Windows←→LinuxやWindows←→Macもiperf3はダメです。
LinuxについてはntttcpのLinux版がリリースされているので、これを使用しましょう。
ですが、残念ながらntttcpのMac版はリリースされていないようです。MacとWindowsで計測する場合は、正確ではないですが、iperfを使用するしかないかもしれません。
ということで気を取り直して、Linux、Macで計測する場合です。
計測には計測したい2台の両方にiperf3をインストールする必要があります。
iperf3はサーバー側とクライアント側がありますが、それぞれオプションで切り替えるだけなので、同じものをインストールします。
まずはipef3のインストールです。
例としてUbuntuの場合を挙げておきます。
sudo apt install iperf3
brew install iperf3
Linux、Macいずれでも基本的に同じです。
2台のいずれかをサーバーとし、他方をクライアントとして決定します。これはどちらでも任意に決めて構いません。
サーバー側にする端末ではiperf3をサーバーモードで、クライアント側にする端末ではiperf3をクライアントモードでiperf3を起動します。
この時、ファイアウォールが有効になっている場合は無効にするか、iperf3で使用するポート(デフォルトは5201)を解放しておきます。
以下のコマンドで、まずサーバー側を起動します。
iperf3 -s
続いてクライアント側を起動します。
オプションのIPアドレス192.168.0.1は、実際に使用するサーバー側のIPアドレス(IPv4/IPv6)またはホスト名で置き換えてください。
iperf3 -c 192.168.0.1
クライアント側に以下のような実行結果が出ます。
Connecting to host 192.168.0.1, port 5201
[ 5] local 192.168.0.129 port 50893 connected to 192.168.0.1 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 75.9 MBytes 636 Mbits/sec
[ 5] 1.00-2.00 sec 61.0 MBytes 511 Mbits/sec
[ 5] 2.00-3.00 sec 68.8 MBytes 578 Mbits/sec
[ 5] 3.00-4.00 sec 71.2 MBytes 598 Mbits/sec
[ 5] 4.00-5.00 sec 67.0 MBytes 560 Mbits/sec
[ 5] 5.00-6.00 sec 70.0 MBytes 589 Mbits/sec
[ 5] 6.00-7.00 sec 72.9 MBytes 610 Mbits/sec
[ 5] 7.00-8.00 sec 60.0 MBytes 503 Mbits/sec
[ 5] 8.00-9.00 sec 72.8 MBytes 610 Mbits/sec
[ 5] 9.00-10.00 sec 63.9 MBytes 538 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.00 sec 683 MBytes 573 Mbits/sec sender
[ 5] 0.00-10.02 sec 682 MBytes 571 Mbits/sec receiver
iperf Done.
そのまま起動した場合、計測時間が10秒になっています。これだと一時的なネットワーク負荷の変動で測定誤差が大きくなるかもしれません。
ですので、計測時間はもう少し長く、例えば60秒等に設定した方が良いかもしれません。
計測時間は -t
オプションで設定できます。
iperf3 -c 192.168.8.3 -t 60
ちなみに、普通にクライアントを起動した場合は、クライアントからサーバーにデータを送信して計測されます。
もしなんらかの理由で逆方向の速度を計測したい場合、クライアント側のオプションに-R
をつけるだけで切り替えることができます。
iperf3 -c 192.168.0.1 -R
Connecting to host 192.168.0.1, port 5201
Reverse mode, remote host 192.168.0.1 is sending
[ 5] local 192.168.0.129 port 51116 connected to 192.168.0.1 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 76.8 MBytes 641 Mbits/sec
[ 5] 1.00-2.00 sec 79.2 MBytes 667 Mbits/sec
[ 5] 2.00-3.00 sec 81.0 MBytes 677 Mbits/sec
[ 5] 3.00-4.00 sec 80.6 MBytes 676 Mbits/sec
[ 5] 4.00-5.00 sec 80.4 MBytes 674 Mbits/sec
[ 5] 5.00-6.00 sec 80.4 MBytes 674 Mbits/sec
[ 5] 6.00-7.00 sec 78.9 MBytes 662 Mbits/sec
[ 5] 7.00-8.00 sec 76.5 MBytes 644 Mbits/sec
[ 5] 8.00-9.00 sec 80.2 MBytes 671 Mbits/sec
[ 5] 9.00-10.00 sec 78.1 MBytes 657 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.02 sec 795 MBytes 666 Mbits/sec 12 sender
[ 5] 0.00-10.00 sec 792 MBytes 664 Mbits/sec receiver
iperf Done.
データを後でなんらか処理することを考えている場合はJSONで出力しておいた方が便利かもしれません。
以下のサンプルを見ても分かる通り、より詳細に出力されます。
iperf3 -c 192.168.0.1 -J
{
"start": {
"connected": [{
"socket": 5,
"local_host": "192.168.0.129",
"local_port": 51240,
"remote_host": "192.168.0.1",
"remote_port": 5201
}],
"version": "iperf 3.18",
"system_info": "Darwin Agata-MacBook-Pro.local 23.6.0 Darwin Kernel Version 23.6.0: Thu Sep 12 23:34:49 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_X86_64 x86_64",
"timestamp": {
"time": "Fri, 31 Jan 2025 05:12:25 UTC",
"timesecs": 1738300345
},
"connecting_to": {
"host": "192.168.0.1",
"port": 5201
},
"cookie": "2lmxmjdwqnodwixbylwsplixxex4geldlzo6",
"tcp_mss_default": 1448,
"target_bitrate": 0,
"fq_rate": 0,
"sock_bufsize": 0,
"sndbuf_actual": 131072,
"rcvbuf_actual": 131072,
"test_start": {
"protocol": "TCP",
"num_streams": 1,
"blksize": 131072,
"omit": 0,
"duration": 60,
"bytes": 0,
"blocks": 0,
"reverse": 0,
"tos": 0,
"target_bitrate": 0,
"bidir": 0,
"fqrate": 0,
"interval": 1
}
},
"intervals": [{
"streams": [{
"socket": 5,
"start": 0,
"end": 1.004466,
"seconds": 1.0044660568237305,
"bytes": 72351744,
"bits_per_second": 576240429.49773228,
"omitted": false,
"sender": true
}],
"sum": {
"start": 0,
"end": 1.004466,
"seconds": 1.0044660568237305,
"bytes": 72351744,
"bits_per_second": 576240429.49773228,
"omitted": false,
"sender": true
}
}, {
"streams": [{
"socket": 5,
"start": 1.004466,
"end": 2.002778,
"seconds": 0.998311996459961,
"bytes": 73007104,
"bits_per_second": 585044388.99971151,
"omitted": false,
"sender": true
}],
"sum": {
"start": 1.004466,
"end": 2.002778,
"seconds": 0.998311996459961,
"bytes": 73007104,
"bits_per_second": 585044388.99971151,
"omitted": false,
"sender": true
}
}, {
"streams": [{
"socket": 5,