Documentation ¶
Index ¶
- func NewImplementation(opts ...Option) abstractlist.Implementation
- func Spec() yarpcconfig.PeerListSpec
- func SpecWithOptions(options ...ListOption) yarpcconfig.PeerListSpec
- type Configuration
- type List
- func (l *List) Choose(ctx context.Context, req *transport.Request) (peer peer.Peer, onFinish func(error), err error)
- func (l *List) Introspect() introspection.ChooserStatus
- func (l *List) IsRunning() bool
- func (l *List) NotifyStatusChanged(pid peer.Identifier)
- func (l *List) Peers() []peer.StatusPeer
- func (l *List) Start() error
- func (l *List) Stop() error
- func (l *List) Update(updates peer.ListUpdates) error
- type ListOption
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewImplementation ¶ added in v1.47.0
func NewImplementation(opts ...Option) abstractlist.Implementation
NewImplementation creates a new round-robin abstractlist.Implementation.
Use this constructor instead of NewList, when wanting to do custom peer connection management.
func Spec ¶
func Spec() yarpcconfig.PeerListSpec
Spec returns a configuration specification for the round-robin peer list implementation, making it possible to select the least recently chosen peer with transports that use outbound peer list configuration (like HTTP).
cfg := yarpcconfig.New() cfg.MustRegisterPeerList(roundrobin.Spec())
This enables the round-robin peer list:
outbounds: otherservice: unary: http: url: https://host:port/rpc round-robin: peers: - 127.0.0.1:8080 - 127.0.0.1:8081
Other than a specific peer or peers list, use any peer list updater registered with a yarpc Configurator. The configuration allows for alternative initial allocation capacity and a fail-fast option. With fail-fast enabled, the peer list will return an error immediately if no peers are available (connected) at the time the request is sent. The default choose timeout enables calls without deadlines, ie streaming, to choose peers without waiting indefinitely.
round-robin: peers: - 127.0.0.1:8080 capacity: 1 failFast: true defaultChooseTimeout: 1s
func SpecWithOptions ¶ added in v1.42.1
func SpecWithOptions(options ...ListOption) yarpcconfig.PeerListSpec
SpecWithOptions accepts additional list constructor options.
Types ¶
type Configuration ¶ added in v1.31.0
type Configuration struct { Capacity *int `config:"capacity"` FailFast bool `config:"failFast"` // DefaultChooseTimeout specifies the deadline to add to Choose calls if not // present. This enables calls without deadlines, ie streaming, to choose // peers without waiting indefinitely. DefaultChooseTimeout *time.Duration `config:"defaultChooseTimeout"` }
Configuration descripes how to build a round-robin peer list.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a PeerList which rotates which peers are to be selected in a circle
func New ¶
func New(transport peer.Transport, opts ...ListOption) *List
New creates a new round robin peer list.
func (*List) Choose ¶
func (l *List) Choose(ctx context.Context, req *transport.Request) (peer peer.Peer, onFinish func(error), err error)
Choose returns a peer, suitable for sending a request.
The peer is not guaranteed to be connected and available, but the peer list makes every attempt to ensure this and minimize the probability that a chosen peer will fail to carry a request.
func (*List) Introspect ¶
func (l *List) Introspect() introspection.ChooserStatus
Introspect reveals information about the list to the internal YARPC introspection system.
func (*List) NotifyStatusChanged ¶
func (l *List) NotifyStatusChanged(pid peer.Identifier)
NotifyStatusChanged forwards a status change notification to an individual peer in the list.
This satisfies the peer.Subscriber interface and should only be used to send notifications in tests. The list's RetainPeer and ReleasePeer methods deal with an individual peer.Subscriber instance for each peer in the list, avoiding a map lookup.
func (*List) Peers ¶ added in v1.43.0
func (l *List) Peers() []peer.StatusPeer
Peers produces a slice of all retained peers.
func (*List) Start ¶
Start causes the peer list to start.
Starting will retain all peers that have been added but not removed the first time it is called.
Start may be called any number of times and in any order in relation to Stop but will only cause the list to start the first time, and only if it has not already been stopped.
func (*List) Stop ¶
Stop causes the peer list to stop.
Stopping will release all retained peers to the underlying transport.
Stop may be called any number of times and in order in relation to Start but will only cause the list to stop the first time, and only if it has previously been started.
func (*List) Update ¶
func (l *List) Update(updates peer.ListUpdates) error
Update may add and remove logical peers in the list.
The peer list uses a transport to obtain a physical peer for each logical peer. The transport is responsible for informing the peer list whether the peer is available or unavailable, but cannot guarantee that the peer will still be available after it is chosen.
type ListOption ¶
type ListOption func(*listConfig)
ListOption customizes the behavior of a roundrobin list.
func Capacity ¶
func Capacity(capacity int) ListOption
Capacity specifies the default capacity of the underlying data structures for this list.
Defaults to 10.
func DefaultChooseTimeout ¶ added in v1.46.0
func DefaultChooseTimeout(timeout time.Duration) ListOption
DefaultChooseTimeout specifies the default timeout to add to 'Choose' calls without context deadlines. This prevents long-lived streams from setting calling deadlines.
Defaults to 500ms.
func FailFast ¶ added in v1.42.0
func FailFast() ListOption
FailFast indicates that the peer list should not wait for a peer to become available when choosing a peer.
This option is preferrable when the better failure mode is to retry from the origin, since another proxy instance might already have a connection.
func Logger ¶ added in v1.42.1
func Logger(logger *zap.Logger) ListOption
Logger specifies a logger.