Hi All,
I'm using ListenAndServeTLS with a self-signed certificate and running go1.6.
These things are confusing me a little and I have a demo program below which shows the problem:
1) HTTP2 doesn't seem to work out of the box as I had expected it to, go1.6 talking to go1.6.
2) Keep-Alives don't seem to be working, and therefore connection warm-up is always quite costly, even with every request going to the same server. (I always see the ConnState go to 'Closed' after each request).
3) Connection cost seems to depend on the frequency at which I make connections. It's generally quite slow (~30ms for 1 req/s), unless I make connections at a very high rate. Then the per-connection cost comes down ( ~10ms for ~100req/s). (CPU cache?).
===
The following program runs both the client and server in the same binary. Please take a quick look at this playground. You'll want to run it locally, owing to the playground's fun time and network connection physics:
http://play.golang.org/p/WFTakG8jkY
- It generates a self signed ECDSA certificate (which is also a CA) using P224.
- It starts a TLS server.
- It makes a http client with a certificate pool which just contains that one certificate.
- It makes requests every ~1ms, times them, and shows the resp.Proto. (Please play with this duration).
Observations:
- No matter what I have tried to do with the Server/Client/Transport settings, it always seems to close after every connection (according to ConnState). Does this mean Keep-Alive is not having a chance to work?
- The proto (resp.Proto) always says HTTP/1.1 (measured from the client in the above program). Shouldn't it be HTTP2? or did I forget to do something to enable it?
- The cost of a connection seems to be around 10ms on my computer.
- But only if I make connections at a rate of ~1ms.
- (If you tweak the timer on line 50 to 1 second instead, the cost of a connection can be much higher, 30-60ms.).
- With the race detector on, the per connection cost goes to 150-250ms. Expected? Any way to ameliorate? This is what made me notice that things weren't behaving as well as I had hoped.
- GODEBUG=http2debug=2 has no visible effect on the program.
In my current use case, I'm trying to keep the latency down, since this is on the interactive path for my users. I'm interested in any techniques which do that. I'm OK with paying the odd slow connection but an extra 30ms most times in production seems high, when presumably it should be able to do session resumption or re-use an existing connection almost "for free", no? (250ms in development with -race is also proving to be a little painful).
If this is all to be expected, that would be good to know too.
Thanks in advance,
- Peter