僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。
一応これで。
#!/usr/bin/env python3 from sys import argv from os import stat print(stat(argv[1]).st_size)
$ truncate foo.img -s 25632 $ ls -alF foo.img -rw-rw-r-- 1 user group 25632 7月 11 15:55 foo.img $ python3 size.py3 foo.img 25632
argv[1]がファイル名、argv[2]が最大サイズ(終了条件)、 argv[3]が待ち時間(秒)。
#!/usr/bin/env python3 from sys import argv from os import stat from time import sleep maxsize = int(argv[2]) sleeptime = float(argv[3]) oldsize, size = 0, 0 while size < maxsize: size = stat(argv[1]).st_size print(size, size - oldsize) oldsize = size sleep(sleeptime)
別ウィンドウでコマンドを叩きながら動作確認。
$ truncate -s 0 foo.img $ truncate -s 1 foo.img $ truncate -s 10 foo.img $ truncate -s 104 foo.img $ truncate -s 1048 foo.img $ truncate -s 10485 foo.img $ truncate -s 104857 foo.img $ truncate -s 1048575 foo.img $ echo -n 1 >> foo.img
$ python3 size.py3 foo.img 1048576 3.8 0 0 1 1 10 9 104 94 1048 944 10485 9437 104857 94372 1048575 943718 1048576 1
出力の解釈を間違えかけた。
それもメモしておくとするか。
1 + 9 = 10 10 + 94 = 104 104 + 944 = 1048 1048 + 9437 = 10485 . . .
のようになる。
一応python2.7.6でも動いた。
ファイルサイズの変化を測定するツールができたので、早速リモートホスト
に送信するファイルサイズを一定時間ごとに測定させた。
truncate -s 0 でファイルを作成したら、その名前のファイルをこっちから
scp。
それまでpingのrttは平均157.2msだったのに、
いきなり締められた帯域の狭さは驚異的だ。
$ time scp 8M.img $REMOTEHOST: Enter passphrase for key '/$HOME/.ssh/$KEY: 8M.img 100% 8192KB 1.3KB/s 1:47:06 real 151m50.443s user 0m0.692s sys 0m0.564s
落ちるまでのrtt平均が320490ms、最大(最凶)が523675ms。
$ ping $GLOBAL_IP PING $GLOBAL_IP ($GLOBAL_IP) 56(84) bytes of data. 64 bytes from $GLOBAL_IP: icmp_seq=1 ttl=55 time=676 ms 64 bytes from $GLOBAL_IP: icmp_seq=2 ttl=55 time=117 ms 64 bytes from $GLOBAL_IP: icmp_seq=3 ttl=55 time=115 ms 64 bytes from $GLOBAL_IP: icmp_seq=4 ttl=55 time=112 ms 64 bytes from $GLOBAL_IP: icmp_seq=5 ttl=55 time=114 ms 64 bytes from $GLOBAL_IP: icmp_seq=6 ttl=55 time=103 ms // 64 bytes from $GLOBAL_IP: icmp_seq=7123 ttl=55 time=432131 ms 64 bytes from $GLOBAL_IP: icmp_seq=7124 ttl=55 time=431258 ms 64 bytes from $GLOBAL_IP: icmp_seq=7125 ttl=55 time=432098 ms 64 bytes from $GLOBAL_IP: icmp_seq=7126 ttl=55 time=431223 ms ping: sendmsg: Network is unreachable ping: sendmsg: Network is unreachable ping: sendmsg: Network is unreachable ping: sendmsg: Network is unreachable
転送速度は、思ったほど変化するわけでもないみたい。
単に遅くしているだけのような。
後で、あるいは省略。
リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。