h2-ping - HTTP/2のPINGフレームを送り続けるだけのスクリプト

h2-ping

http-2 gemの使い方をお勉強するために、HTTP/2のPINGフレームを送り続けるだけのスクリプトを書きました。
機能も出力もお粗末ですが、http-2 gemのexampleが非常に分かりやすく、かつ便利なので殆どコピペしただけで出来てしまいました。

https://github.com/flano-yuki/h2-ping

demo

1つのコネクション上で指定回数、指定間隔でpingを送ります。
こんな感じ。(分かりづらいですが、(00000000)などはPINGフレームのペイロード)

$ ./ping.rb https://twitter.com -s -i 1 -c 10
NPN protocols supported by server: ["h2-15", "spdy/3.1", "http/1.1"]
==== PING https://twitter.com (interval: 1sec)====
   0. 14:15:47 Send PING (00000000)... Recieve ACK (00000000) (269ms)
   1. 14:15:48 Send PING (00000001)... Recieve ACK (00000001) (118ms)
   2. 14:15:49 Send PING (00000002)... Recieve ACK (00000002) (114ms)
   3. 14:15:50 Send PING (00000003)... Recieve ACK (00000003) (116ms)
   4. 14:15:51 Send PING (00000004)... Recieve ACK (00000004) (116ms)
   5. 14:15:53 Send PING (00000005)... Recieve ACK (00000005) (116ms)
   6. 14:15:54 Send PING (00000006)... Recieve ACK (00000006) (127ms)
   7. 14:15:55 Send PING (00000007)... Recieve ACK (00000007) (121ms)
   8. 14:15:56 Send PING (00000008)... Recieve ACK (00000008) (117ms)
   9. 14:15:57 Send PING (00000009)... Recieve ACK (00000009) (118ms)

==== 10 frame sended ====
max:269, min:114, ave:121.0909090909091

Google先生に怒られる

Google先生PING送るとtoo_many_pingsと言ってGOAWAY返されてしまう(´・ω・`)

$ ./ping.rb https://google.com/ -i 1
NPN protocols supported by server: ["h2-15", "h2-14", "spdy/3.1", "spdy/3", "http/1.1"]

==== PING https://google.com/ (interval: 1sec)====
   0. 23:17:01 Send PING (00000000)... Recieve ACK (00000000) (46ms)
   1. 23:17:02 Send PING (00000001)... Recieve ACK (00000001) (3ms)
   2. 23:17:03 Send PING (00000002)...
Recieve GOAWAY(too_many_pings)