labunix's blog

labunixのラボUnix

nuttcp/curl/wgetでネットワークの速度を測定してみる。

■nuttcp/curl/wgetでネットワークの速度を測定してみる。
 pingのRTTは以下で試した。NDTは使用しない。

 ラウンドトリップ時間をpingのワンライナーで計測してみる。
 http://labunix.hateblo.jp/entry/20150804/1438641097

 ネットワーク/ストレージの処理能力をチェックするためのベンチマークツール
 http://knowledge.sakura.ad.jp/tech/938/

■Debianバージョンとnuttcpのインストール

$ lsb_release -d
Description:	Debian GNU/Linux 8.4 (jessie)

$ sudo apt-get install -y nuttcp
$ nuttcp -V
nuttcp-6.1.2

■サーバモードの起動と停止
 「-S」オプションで起動。停止はkillコマンドを使用する。

$ man nuttcp | grep -A 6 "^ *\-S"
       -S     Indicates  that this nuttcp is the server.  The only option that
              may be specified to the server is the "-P" option, which  allows
              one to change the control port used by the server, but only when
              the server is started by a normal,  non-privileged  user.   When
              the server is initiated by inetd/xinetd, the server control port
              should be specified in the services file.

$ nuttcp -S

$ ps -ef | awk '/nuttc[p]/{print "kill "$2}' | sh
$ pkill nuttcp

■TCPの転送速度を計測

$ hostname -s ;nuttcp -S
to-jessie

$ hostname -s;nuttcp to-jessie
from-jessie
  806.3484 MB /  10.03 sec =  674.6915 Mbps 2 %TX 21 %RX 0 retrans 0.29 msRTT

データ量 MB / かかった時間 () = 通信速度 Mbps
送信側CPU利用率「%TX」 受信側のCPU利用率「%RX」、
パケットの再送回数「retrans」、「msRTT」はRTT。

■UDPの転送速度を計測

$ hostname -s ;nuttcp -S
to-jessie

$ hostname -s;nuttcp -u to-jessie
from-jessie
  799.8733 MB /  10.07 sec =  666.4842 Mbps 2 %TX 21 %RX 0 retrans 0.32 msRTT

■詳細の確認

$ hostname;nuttcp -v to-jessie
from-jessie
nuttcp-t: v6.1.2: socket
nuttcp-t: buflen=65536, nstream=1, port=5001 tcp -> to-jessie
nuttcp-t: time limit = 10.00 seconds
nuttcp-t: connect to 172.31.31.1 with mss=1448, RTT=0.296 ms
nuttcp-t: send window size = 87040, receive window size = 372480
nuttcp-t: available send window = 43520, available receive window = 186240
nuttcp-t: 803.4223 MB in 10.00 real seconds = 82270.09 KB/sec = 673.9566 Mbps
nuttcp-t: retrans = 0
nuttcp-t: 12855 I/O calls, msec/call = 0.80, calls/sec = 1285.49
nuttcp-t: 0.0user 0.2sys 0:10real 2% 0i+0d 2080maxrss 0+0pf 697+12csw

nuttcp-r: v6.1.2: socket
nuttcp-r: buflen=65536, nstream=1, port=5001 tcp
nuttcp-r: accept from 172.31.31.2
nuttcp-r: send window size = 87040, receive window size = 374400
nuttcp-r: available send window = 43520, available receive window = 187200
nuttcp-r: 803.4223 MB in 10.04 real seconds = 81925.23 KB/sec = 671.1315 Mbps
nuttcp-r: 92761 I/O calls, msec/call = 0.11, calls/sec = 9237.18
nuttcp-r: 0.0user 2.1sys 0:10real 21% 0i+0d 736maxrss 0+0pf 79647+886csw

$ hostname;nuttcp -v -u to-jessie
from-jessie
nuttcp-t: v6.1.2: socket
nuttcp-t: buflen=1024, nstream=1, port=5001 udp -> to-jessie
nuttcp-t: time limit = 10.00 seconds
nuttcp-t: rate limit = 1.000 Mbps (aggregate), 122 pps
nuttcp-t: send window size = 212992, receive window size = 212992
nuttcp-t: available send window = 106496, available receive window = 106496
nuttcp-t: 1.1924 MB in 10.00 real seconds = 122.07 KB/sec = 1.0000 Mbps
nuttcp-t: 1228 I/O calls, msec/call = 8.34, calls/sec = 122.77
nuttcp-t: 9.9user 0.0sys 0:10real 99% 0i+0d 2084maxrss 0+0pf 0+533csw

nuttcp-r: v6.1.2: socket
nuttcp-r: buflen=1024, nstream=1, port=5001 udp
nuttcp-r: send window size = 212992, receive window size = 212992
nuttcp-r: available send window = 106496, available receive window = 106496
nuttcp-r: 1.1924 MB in 10.00 real seconds = 122.07 KB/sec = 1.0000 Mbps
nuttcp-r: 0 / 1221 drop/pkt 0.00% data loss
nuttcp-r: 1225 I/O calls, msec/call = 8.36, calls/sec = 122.47
nuttcp-r: 0.0user 0.0sys 0:10real 0% 0i+0d 742maxrss 0+1pf 1224+1csw

■コントロールポートに5000、データポートに50015004を使用する。

$ man nuttcp | grep -A 17 '^ *\-pdata_port'
       -pdata_port
              Port number used for the data connection, which defaults to port
              5001.  If multiple streams are specified with the  "-N"  option,
              the  "-p" option specifies the starting port number for the data
              connection.  For example, if four streams  are  specified  using
              the  default  data connection port number, nuttcp will use ports
              5001, 5002, 5003, and 5004 for the four TCP (or UDP) connections
              used to perform the data transfer.

       -Pcontrol_port
              For  client/server  mode, specifies the port number used for the
              control connection between the client and server,  and  defaults
              to  port  5000.  On the server side, the "-P" option should only
              be used when the server is started manually by the user.  If the
              server  is  started  by inetd/xinetd (the preferred method), the
              control connection must be specified by adding a nuttcp entry to
              the services file.

$ hostname;nuttcp -v -i1 to-jessie
from-jessie
nuttcp-t: v6.1.2: socket
nuttcp-t: buflen=65536, nstream=1, port=5001 tcp -> to-jessie
nuttcp-t: time limit = 10.00 seconds
nuttcp-t: connect to 172.31.31.1 with mss=1448, RTT=0.402 ms
nuttcp-t: send window size = 87040, receive window size = 372480
nuttcp-t: available send window = 43520, available receive window = 186240
nuttcp-r: v6.1.2: socket
nuttcp-r: buflen=65536, nstream=1, port=5001 tcp
nuttcp-r: interval reporting every 1.00 second
nuttcp-r: accept from 172.31.31.2
nuttcp-r: send window size = 87040, receive window size = 374400
nuttcp-r: available send window = 43520, available receive window = 187200
   80.3750 MB /   1.00 sec =  674.2256 Mbps     0 retrans
   82.8750 MB /   1.00 sec =  695.2149 Mbps     0 retrans
   78.1250 MB /   1.00 sec =  655.3705 Mbps     0 retrans
   77.3125 MB /   1.00 sec =  648.5015 Mbps     0 retrans
   80.3750 MB /   1.00 sec =  674.2627 Mbps     0 retrans
   80.7500 MB /   1.00 sec =  677.3733 Mbps     0 retrans
   83.7500 MB /   1.00 sec =  702.5677 Mbps     0 retrans
   81.2500 MB /   1.00 sec =  681.5444 Mbps     0 retrans
   79.4375 MB /   1.00 sec =  666.3954 Mbps     0 retrans
   79.5000 MB /   1.00 sec =  666.8797 Mbps     0 retrans
nuttcp-t: 805.6875 MB in 10.00 real seconds = 82501.88 KB/sec = 675.8554 Mbps
nuttcp-t: retrans = 0
nuttcp-t: 12891 I/O calls, msec/call = 0.79, calls/sec = 1289.09
nuttcp-t: 0.0user 0.7sys 0:10real 8% 0i+0d 2126maxrss 0+1pf 12810+73csw

nuttcp-r: 805.6875 MB in 10.03 real seconds = 82272.42 KB/sec = 673.9756 Mbps
nuttcp-r: 94233 I/O calls, msec/call = 0.11, calls/sec = 9397.03
nuttcp-r: 0.0user 2.1sys 0:10real 21% 0i+0d 744maxrss 0+15pf 81297+78csw

■ダミーデータの作成
 nuttcpが約800MBのデータをやりとりしているようなので、同様のファイルを作成

$ dd if=/dev/zero of=dummy.bin bs=512k count=1600
1600+0 レコード入力
1600+0 レコード出力
838860800 バイト (839 MB) コピーされました、 11.8164 秒、 71.0 MB/秒

$ du -h dummy.bin 
801M	dummy.bin

■ポートは固定なので、ftpクライアントで速度計測
 以下の場合、77.6790 MB/s

$ ftp remote-jessie 
Connected to remote-jessie.
220 (vsFTPd 3.0.2)
Name (remote-jessie:labunix): 
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bin
200 Switching to Binary mode.
ftp> prompt
Interactive mode off.
ftp> mget dummy.bin
local: dummy.bin remote: dummy.bin
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for dummy.bin (838860800 bytes).
226 Transfer complete.
838860800 bytes received in 10.30 secs (77.6790 MB/s)
ftp> bye
221 Goodbye.

■wgetによる速度計測
 84.2MB/s

$ wget -O /dev/null --no-proxy http://172.31.31.2/dummy.bin >/dev/null
--2016-05-30 21:34:58--  http://172.31.31.2/dummy.bin
172.31.31.2:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 838860800 (800M) [application/octet-stream]
`/dev/null' に保存中

/dev/null           100%[=====================>] 800.00M  84.2MB/s 時間 10s    

2016-05-30 21:35:08 (78.6 MB/s) - `/dev/null' へ保存完了 [838860800/838860800]

■curlによる速度計測
 49.4MB/s

$ curl -noproxy http://172.31.31.2/dummy.bin >/dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  800M  100  800M    0     0  49.4M      0  0:00:16  0:00:16 --:--:-- 35.4M