Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

テスト用HTTPスタブサーバに適したプログラム

以下の条件で、以下のページで挙げられているツールをながめてみた。

nordicapis.com

  • ボディの内容がこのパターンにマッチしたらこの内容を返す、また別の内容にマッチしたらこの内容を返す……というテストができること
  • HTTPヘッダも含めたレスポンスの内容を条件ごとに個別に定義できること
  • SaaSはダメで、ローカルで実行できること
  • Windows上で実行できるとよい
  • 無料で使えるとよい
  • 特定の言語のコードを書かずに、単純な設定ファイルか、GUIから設定ができるとよい
  • 実行にあたってnode.jsなど前提となるプログラムのセットアップが不要だとよい
  • ステートフルな機能や、レスポンスの一部置き換えのような機能は不要
  • レスポンスの遅延や多重化機能も不要

その結果、Mockoonが条件にマッチしそう。

mockoon.com

インターネット中継用衛星コンステレーションによるレイテンシ改善幅の見積

HFTをしている証券会社が、取引所までのhop数を減らすためにStarlinkを利用することを考えたとしよう。最大でどのくらいレイテンシを改善できるだろうか。計算合ってるかな?

光ファイバ中の光速と真空中の光速の差による改善幅

  • Starlinkのうち一番低い軌道は340km *1
  • 地球を雑に真球に近似すると、Starlinkへの電波が上方向に移動するオーバーヘッドが一番少なくなる場合、Starlinkまでの距離はx2+地球の半径2=(地球の半径+340km)2で求められる。地球の半径は12742kmで、これを解くとx=2963km。証券会社→StarlinkStarlink→取引所で5,926km。
    • 5,926kmを真空中の光速で通信した場合、19.7msで到達する。
  • 同じ距離を地上で通信した場合、最短距離で繋げたと仮定して、atan(2962*2/12742)=26.2度(0.457rad)。距離にすると5,826km。
    • シングルモード光ファイバ中の光速は20万km/sなので、29.1msで到達する。
  • Starlinkを使うことで、距離的には5926-5822=104kmぶんのロスが発生するように見えるが、実は時間的には29.1-19.7=9.4ms稼げる!

hop数の削減による改善幅

  • Starlinkがどういうネットワークトポロジか分からないが、ここでは雑に衛星コンステレーション全体が1つのサブネットだと仮定する。
  • ルータとスイッチでは話が違うが、1hopで0.008msec*2とする。
  • シングルモード光ファイバの通信距離が10GBASE-ERで最大40km*3だから、5822kmを通信するには最低でも146hop必要。
  • 現状、取引所まで146hopだった経路を、雑にStarlinkで2hopまで減らせると仮定する。
  • 144hopぶんで1.152ms稼げる!

結論として、楽観的に見積ると合計で10.5msくらい稼げるみたい。途中のネットワークをバイパスすることよりも、光ファイバ中の光速と真空中の光速の差の方が支配的みたい。

Copy-Item doesn't have --no-clobber option

Context:

cp(1) has -n or --no-clobber option. It makes cp not overwrite existing files. This option is useful when you copy only newly created files.

Problem:

In PowerShell, Copy-Item cmdlet doesn't have options equivalent to --no-clobber of cp. Copy-Item -Confirm prompts you for confirmation even if there are no existing files on destination.

Solution:

You have to check existence of files on destination folder one by one.

ルータ⇔PC間とルータ⇔ISP&インターネット間で速度計測

PC⇔ルータ間と、ルータ⇔ISP&インターネット間のどちらにボトルネックがあるのか調べる。

PC⇔ルータ間

PCとルータの両方にiPerf3を入れて計測する。

PC側

PS > .\iperf3.exe -s -i 5 -p 5001 -f m
-----------------------------------------------------------
Server listening on 5001
-----------------------------------------------------------
Accepted connection from 192.168.xxx.1, port 60464
[  5] local 192.168.xxx.yyy port 5001 connected to 192.168.xxx.1 port 60466
[  7] local 192.168.xxx.yyy port 5001 connected to 192.168.xxx.1 port 60468
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-5.00   sec  43.6 MBytes  73.1 Mbits/sec
[  7]   0.00-5.00   sec  43.7 MBytes  73.4 Mbits/sec
[SUM]   0.00-5.00   sec  87.3 MBytes   146 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   5.00-10.00  sec  47.1 MBytes  79.1 Mbits/sec
[  7]   5.00-10.00  sec  47.0 MBytes  78.8 Mbits/sec
[SUM]   5.00-10.00  sec  94.1 MBytes   158 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]  10.00-15.00  sec  46.2 MBytes  77.5 Mbits/sec
[  7]  10.00-15.00  sec  45.0 MBytes  75.6 Mbits/sec
[SUM]  10.00-15.00  sec  91.3 MBytes   153 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]  15.00-20.00  sec  45.3 MBytes  76.0 Mbits/sec
[  7]  15.00-20.00  sec  45.2 MBytes  75.8 Mbits/sec
[SUM]  15.00-20.00  sec  90.4 MBytes   152 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]  20.00-20.02  sec   153 KBytes  61.9 Mbits/sec
[  7]  20.00-20.02  sec   234 KBytes  94.3 Mbits/sec
[SUM]  20.00-20.02  sec   387 KBytes   156 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-20.02  sec  0.00 Bytes  0.00 Mbits/sec                  sender
[  5]   0.00-20.02  sec   182 MBytes  76.4 Mbits/sec                  receiver
[  7]   0.00-20.02  sec  0.00 Bytes  0.00 Mbits/sec                  sender
[  7]   0.00-20.02  sec   181 MBytes  75.9 Mbits/sec                  receiver
[SUM]   0.00-20.02  sec  0.00 Bytes  0.00 Mbits/sec                  sender
[SUM]   0.00-20.02  sec   363 MBytes   152 Mbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5001
-----------------------------------------------------------

ルータ側

root# iperf3 -c 192.168.xxx.yyy -P 2 -i 5 -p 5001 -f m -t 20
Connecting to host 192.168.xxx.yyy, port 5001
[  5] local 192.168.xxx.1 port 60466 connected to 192.168.xxx.yyy port 5001
[  7] local 192.168.xxx.1 port 60468 connected to 192.168.xxx.yyy port 5001
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-5.09   sec  44.6 MBytes  73.5 Mbits/sec   82    201 KBytes
[  7]   0.00-5.09   sec  44.7 MBytes  73.8 Mbits/sec    0    212 KBytes
[SUM]   0.00-5.09   sec  89.3 MBytes   147 Mbits/sec   82
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   5.09-10.02  sec  46.5 MBytes  79.0 Mbits/sec    0    211 KBytes
[  7]   5.09-10.02  sec  46.3 MBytes  78.7 Mbits/sec    0    212 KBytes
[SUM]   5.09-10.02  sec  92.8 MBytes   158 Mbits/sec    0
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]  10.02-15.09  sec  46.8 MBytes  77.5 Mbits/sec    0    211 KBytes
[  7]  10.02-15.09  sec  45.7 MBytes  75.7 Mbits/sec    0    212 KBytes
[SUM]  10.02-15.09  sec  92.4 MBytes   153 Mbits/sec    0
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]  15.09-20.01  sec  44.5 MBytes  75.9 Mbits/sec    0    211 KBytes
[  7]  15.09-20.01  sec  44.4 MBytes  75.7 Mbits/sec    0    212 KBytes
[SUM]  15.09-20.01  sec  88.9 MBytes   152 Mbits/sec    0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-20.01  sec   182 MBytes  76.5 Mbits/sec   82             sender
[  5]   0.00-20.01  sec   182 MBytes  76.5 Mbits/sec                  receiver
[  7]   0.00-20.01  sec   181 MBytes  75.9 Mbits/sec    0             sender
[  7]   0.00-20.01  sec   181 MBytes  75.9 Mbits/sec                  receiver
[SUM]   0.00-20.01  sec   363 MBytes   152 Mbits/sec   82             sender
[SUM]   0.00-20.01  sec   363 MBytes   152 Mbits/sec                  receiver

iperf Done.

ルータ⇔ISP&インターネット間

一つは、iPerf3の公開サーバを使用する方法。当然、使用するサーバによって速度が異なる。speedtest.netに参加しているサーバがiPerf3に対応していればいいのだが……

root# iperf3 -c bouygues.iperf.fr -P 1 -i 5 -p 9200 -f m -t 20
Connecting to host bouygues.iperf.fr, port 9200
[  5] local 192.168.1.2 port 47220 connected to 89.84.1.222 port 9200
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-5.00   sec  1.52 MBytes  2.55 Mbits/sec    0    112 KBytes
[  5]   5.00-10.00  sec  4.43 MBytes  7.43 Mbits/sec    1    278 KBytes
[  5]  10.00-15.00  sec  6.89 MBytes  11.6 Mbits/sec    0    396 KBytes
[  5]  15.00-20.00  sec  7.93 MBytes  13.3 Mbits/sec    0    427 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-20.00  sec  20.8 MBytes  8.71 Mbits/sec    1             sender
[  5]   0.00-20.24  sec  20.3 MBytes  8.40 Mbits/sec                  receiver

もう一つは、netperfを使う方法。

root# speedtest-netperf.sh
2020-10-26 20:10:37 Starting speedtest for 60 seconds per transfer session.
Measure speed to netperf.bufferbloat.net (IPv4) while pinging gstatic.com.
Download and upload sessions are sequential, each with 5 simultaneous streams.
..............................................................
 Download:  57.29 Mbps
  Latency: [in msec, 62 pings, 0.00% packet loss]
      Min:   3.820
    10pct:   4.000
   Median:   4.340
      Avg:   4.767# clear
    90pct:   4.700
      Max:  25.681
 CPU Load: [in % busy (avg +/- std dev), 60 samples]
     cpu0:  32.3 +/-  9.3
 Overhead: [in % used of total CPU available]
  netperf:  19.5
.............................................................
   Upload:  74.16 Mbps
  Latency: [in msec, 60 pings, 0.00% packet loss]
      Min:   4.080
    10pct:   4.180
   Median:   4.500
      Avg:   5.555
    90pct:   9.101
      Max:  15.660
 CPU Load: [in % busy (avg +/- std dev), 58 samples]
     cpu0:  53.1 +/- 10.6
 Overhead: [in % used of total CPU available]
  netperf:  14.5

4Kモニタへの60Hz出力についての知見

  • USB3.1 Type-Cコネクタでも、ハードウェアレベルで画面出力には使えないことがある。4K60Hzだと12Gbps必要で、USB 3.1Gen2の10Gbpsでは追いつかない。USB Alt ModeのDisplayPortでも4Kでは30Hzになってしまう。4K 60Hzに追いつくにはThunderbolt 3(40Gbps)が必要。
  • HDMIで4K出力対応と書いてあっても、リフレッシュレートが30Hzかもしれない。30Hzでもブラウザ等の表示に違和感はないが、マウスカーソルの表示がかなりカクついて見える。
  • チップセットがDisplayPortでの4K 60Hz出力に対応していても、HDMI接続では4K 30Hz出力にしか対応していないかもしれない。そのうえ、DisplayPortの出力端子がないかもしれない。
  • USBのディスプレイアダプタにはUSB 3.0で4K 60Hz出力が可能なものもある。ただ、けっこう高価(DisplayLinkのチップを使ったものが多く、だいたい1万円からする)。
  • USB-CポートにDisplayPortのマークが付いていれば画面出力に使用できる。ただ、BIOS画面の出力には使えないことがあるみたい。OSが立ち上がって、画面出力切り替え操作をしないと出力されないケースがあった。
  • USB-CポートにDisplayPortのマークも付いてるし、マシンスペック上は4K 60Hzに対応している場合でも、OSの設定で4K 60Hz出力が使えなくなっている場合がある。例えばシンクライアントの場合。
  • USB Type-Aポートが付いているモニタの場合、USB-Cポートからの入力がないとUSB Type-Aポートへの給電がされない場合があるみたい。
  • PIPが使えるモニタなら4KモニタをスケーリングしてFull HD x 2 60Hzのモニタとして使えるのかな?