peerheap

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Spec added in v1.9.0

Spec returns a configuration specification for the least-pending peer heap peer chooser implementation, making it possible to select the least pending peer with transports that use outbound peer list configuration (like HTTP).

cfg := yarpcconfig.New()
cfg.MustRegisterPeerList(peerheap.Spec())

This enables the least-pending peer list:

outbounds:
  otherservice:
    unary:
      http:
        url: https://host:port/rpc
        least-pending:
          peers:
            - 127.0.0.1:8080
            - 127.0.0.1:8081

Types

type HeapOption added in v1.6.0

type HeapOption func(*heapConfig)

HeapOption customizes the behavior of a peer heap.

func StartupWait added in v1.6.0

func StartupWait(t time.Duration) HeapOption

StartupWait specifies how long updates to the heap will block before the list heap been started

Defaults to 5 seconds.

type List

type List struct {
	// contains filtered or unexported fields
}

List is a peer list and peer chooser that favors the peer with the least pending requests, and then favors the least recently used or most recently introduced peer.

func New

func New(transport peer.Transport, opts ...HeapOption) *List

New returns a new peer heap-chooser-list for the given transport.

func (*List) Choose

func (pl *List) Choose(ctx context.Context, _ *transport.Request) (peer.Peer, func(error), error)

Choose satisfies peer.Chooser, providing a single peer for a request, a callback for when the request is finished, or an error if it fails. The choose method takes a context that must have a deadline. Choose resepects this deadline, waiting for an available peer until the deadline. The peer heap does not use the given *transport.Request and can safely receive nil.

func (*List) IsRunning

func (pl *List) IsRunning() bool

IsRunning returns whether the peer list is running.

func (*List) NotifyStatusChanged

func (pl *List) NotifyStatusChanged(pid peer.Identifier)

NotifyStatusChanged receives notifications when a peer becomes available, connected, unavailable, or when its pending request count changes. This method satisfies peer.Subscriber and is only used for tests, since the peer heap has a subscriber for each invividual peer.

func (*List) Start

func (pl *List) Start() error

Start starts the peer list.

func (*List) Stop

func (pl *List) Stop() error

Stop stops the peer list. This releases all retained peers.

func (*List) Update

func (pl *List) Update(updates peer.ListUpdates) error

Update satisfies the peer.List interface, so a peer list updater can manage the retained peers.

Jump to

Keyboard shortcuts

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