Closed danielealbano closed 7 months ago
Small note: probably HTTP/2 here is not supported altogether as it requires TLS but HTTP/1.1 with keep alive should. Of course the extra latency on the HTTP Ping compared to the alternative is to be expected even just because the server side has to be some extra work compared to the TCPPing or ICMPPing.
My concern is that assuming we send 10 HTTP ping requests and N(N <= 10)
ports are used in those 10 requests.
Then the result would be N
with a latency of 2RTT, and 10-N
with a RTT. I can reproduce this on wireshark.
The requests are sent sequentially, not in parallel, and forcing the keep alive in the http client would be enough to guarantee that any sequential request done within the keep alive time frame will be handled correctly.
Howerver, the current solution is just incorrect as it assumes that there are only 2 sets of packets sent but it's never the case.
Even doing a divided by two on the first request still keeps it on the wrong side, it should be more of a /3 or even a /4 but would need to be validated.
You're right, But I think the best way is to disable keep alive for http ping.
@r3inbowari I am not entirely sure it's a good idea to disable it, it's the only thing that guarantees that there will be only one packet forth and one packet back during the measurement.
With the tcp/ip ping you have the connection established in advance so you don't need to deal with the extra traffic generated by the initial handshake and the dns resolution, which is a very variable aspect that is triggered only once and goes through a totally separate route (therefore you can't simply do a divided by something).
Yes :) Thank you!
This PR changes how the HTTPPing calculates the latency doing a connection and dns warmup triggering an extra request at the beginning.
Meanwhile this will force the HTTPPing to carry out a de-facto unwanted request, it's a necessity to ensure that the initial connection will not impact the overall estimation.
This, though, is only effective when an HTTP/2 or an HTTP/1.1 with keep-alive is established, if none of the two work the latencies reported will be all over the place.
An improvement to this PR might be to validate that an HTTP/2 or an HTTP/1.1 with keepalive enabled is in use and otherwise raise an exception.
Tested with this code
Example output
Meanwhile the max latency is greater for HTTP Ping compared ot the a;ternatives, the mean latency is close enough to the latency reported by ICMP Ping