pendingheap

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package pendingheap provides an implementation of a peer list that sends traffic to the peer with the fewest pending requests, but degenerates to round robin when all peers have equal pending requests, using a heap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Spec

Spec returns a configuration specification for the pending heap 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(pendingheap.Spec())

This enables the pending heap peer list:

outbounds:
  otherservice:
    unary:
      http:
        url: https://host:port/rpc
        fewest-pending-requests:
          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.

fewest-pending-requests:
  peers:
    - 127.0.0.1:8080
  capacity: 1
  failFast: true

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"`
}

Configuration descripes how to build a fewest pending heap peer list.

type List

type List struct {
	*abstractlist.List
}

List is a peer list 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 pending heap.

type ListOption

type ListOption func(*listConfig)

ListOption customizes the behavior of a pending requests peer heap.

func Capacity

func Capacity(capacity int) ListOption

Capacity specifies the default capacity of the underlying data structures for this list.

Defaults to 10.

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 provides an optional logger for the list.

func Seed added in v1.36.0

func Seed(seed int64) ListOption

Seed specifies the random seed to use for shuffling peers.

Defaults to time in nanoseconds.

Jump to

Keyboard shortcuts

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