hedgedhttp

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 5 Imported by: 30

README

hedgedhttp

build-img pkg-img reportcard-img coverage-img

Hedged HTTP client which helps to reduce tail latency at scale.

Rationale

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.

Acknowledge

Thanks to Bohdan Storozhuk for the review and powerful hints.

Features

  • Simple API.
  • Easy to integrate.
  • Optimized for speed.
  • Clean and tested code.
  • Dependency-free.

Install

Go version 1.16+

go get github.com/cristalhq/hedgedhttp

Example

TODO

Documentation

See these docs.

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(timeout time.Duration, upto int, client *http.Client) *http.Client

NewClient returns a new http.Client which implements hedged requests pattern. Given Client starts a new request after a timeout from previous request. Starts no more than upto requests.

func NewRoundTripper

func NewRoundTripper(timeout time.Duration, upto int, rt http.RoundTripper) http.RoundTripper

NewRoundTripper returns a new http.RoundTripper which implements hedged requests pattern. Given RoundTripper starts a new request after a timeout from previous request. Starts no more than upto requests.

Types

type ErrorFormatFunc added in v0.2.0

type ErrorFormatFunc func([]error) string

ErrorFormatFunc is called by MultiError to return the list of errors as a string.

type MultiError added in v0.2.0

type MultiError struct {
	Errors        []error
	ErrorFormatFn ErrorFormatFunc
}

MultiError is an error type to track multiple errors. This is used to accumulate errors in cases and return them as a single "error". Insiper by https://github.com/hashicorp/go-multierror

func (*MultiError) Error added in v0.2.0

func (e *MultiError) Error() string

func (*MultiError) ErrorOrNil added in v0.2.0

func (e *MultiError) ErrorOrNil() error

ErrorOrNil returns an error if there are some.

func (*MultiError) String added in v0.2.0

func (e *MultiError) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL