The :hedging implements a strategy called “request hedging”, whereby a request is sent a request two times, over different connections, and picking up whichever arrives first.
This strategy makes sense in situations where SLA requirements enforce low latency, and every tail latency spike matters; so instead of waiting for the request too terminate too late, or worse, times out and retry, it is assumed that one of two connections opened will be healthy and fast enough. This is a strategy that makes sense in situations where the overhead of duplicating requests (and TCP connections) is irrelevant, and operations are idempotent.
http = HTTP.plugin(:hedging)
http.get("http://www.example.com")
# sent two times, only the fastest one comes back...
By default, request will be duplicated immediately. However, using this option, you can introduce a short delay (in seconds), so that only requests which haven’t completed during that delay will be duplicated.
http = HTTP.plugin(:hedging, hedge_after: 1)
http.get("http://www.example.com")
# will send one request, and if it doesn't complete within 1 second, the duplicate request will be sent
Request hedging will only be performed in “cold” connections, i.e. when a connection will need to be established before sending the request. If a connection is persistent (like in the case of persistent connections), requests will only be sent once (if a persistent connection drops however, and requires reconnecting, then the request will be reattempted using request hedging).
Next: Custom Plugins