Hedged HTTP client which helps to reduce tail latency at scale.
Go
134
48 commits
updated Aug 13, 2024
Hedged HTTP client which helps to reduce tail latency at scale.
See paper Tail at Scale by Jeffrey Dean, Luiz André Barroso. In short: the client first sends one request, but then sends an additional request after a timeout if the previous hasn't returned an answer in the expected time. The client cancels remaining requests once the first result is received.
Thanks to Bohdan Storozhuk for the review and powerful hints.
http.Client and http.RoundTripper.Go version 1.16+
go get github.com/cristalhq/hedgedhttp
ctx := context.Background()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://google.com", http.NoBody)
if err != nil {
panic(err)
}
timeout := 10 * time.Millisecond
upto := 7
client := &http.Client{Timeout: time.Second}
hedged, err := hedgedhttp.NewClient(timeout, upto, client)
if err != nil {
panic(err)
}
// will take `upto` requests, with a `timeout` delay between them
resp, err := hedged.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
Also see examples: examples_test.go.
See these docs.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
802 followers · starred Dec 2021
293 followers · starred Jun 2021
323 followers · starred Oct 2024
294 followers · starred Jun 2021
Hedged HTTP client which helps to reduce tail latency at scale.
Go
134
48 commits
updated Aug 13, 2024
Hedged HTTP client which helps to reduce tail latency at scale.
See paper Tail at Scale by Jeffrey Dean, Luiz André Barroso. In short: the client first sends one request, but then sends an additional request after a timeout if the previous hasn't returned an answer in the expected time. The client cancels remaining requests once the first result is received.
Thanks to Bohdan Storozhuk for the review and powerful hints.
http.Client and http.RoundTripper.Go version 1.16+
go get github.com/cristalhq/hedgedhttp
ctx := context.Background()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://google.com", http.NoBody)
if err != nil {
panic(err)
}
timeout := 10 * time.Millisecond
upto := 7
client := &http.Client{Timeout: time.Second}
hedged, err := hedgedhttp.NewClient(timeout, upto, client)
if err != nil {
panic(err)
}
// will take `upto` requests, with a `timeout` delay between them
resp, err := hedged.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
Also see examples: examples_test.go.
See these docs.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
802 followers · starred Dec 2021
293 followers · starred Jun 2021
323 followers · starred Oct 2024
294 followers · starred Jun 2021