balancer

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package balancer defines APIs for load balancing in gRPC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register added in v0.3.0

func Register(name string, builder gsel.Builder)

Register registers the given balancer builder with the given name.

func WithLeastConnection added in v0.3.0

func WithLeastConnection() grpc.DialOption

WithLeastConnection returns a grpc.DialOption which enables the least connection load balancing.

func WithRandom added in v0.3.0

func WithRandom() grpc.DialOption

WithRandom returns a grpc.DialOption which enables random load balancing.

func WithRoundRobin added in v0.3.0

func WithRoundRobin() grpc.DialOption

WithRoundRobin returns a grpc.DialOption which enables round-robin load balancing.

func WithWeight added in v0.3.0

func WithWeight() grpc.DialOption

WithWeight returns a grpc.DialOption which enables weight load balancing.

Types

type Builder added in v0.3.0

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

Builder implements grpc balancer base.PickerBuilder, which returns a picker that will be used by gRPC to pick a SubConn.

func (*Builder) Build added in v0.3.0

func (b *Builder) Build(info base.PickerBuildInfo) balancer.Picker

Build returns a picker that will be used by gRPC to pick a SubConn.

type Node added in v0.3.0

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

Node is the node for the balancer.

func (*Node) Address added in v0.3.0

func (n *Node) Address() string

Address returns the address of the node.

func (*Node) Service added in v0.3.0

func (n *Node) Service() gsvc.Service

Service returns the service of the node.

type Picker added in v0.3.0

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

Picker implements grpc balancer.Picker, which is used by gRPC to pick a SubConn to send an RPC. Balancer is expected to generate a new picker from its snapshot every time its internal state has changed.

The pickers used by gRPC can be updated by ClientConn.UpdateState().

func (*Picker) Pick added in v0.3.0

func (p *Picker) Pick(info balancer.PickInfo) (balancer.PickResult, error)

Pick returns the connection to use for this RPC and related information.

Pick should not block. If the balancer needs to do I/O or any blocking or time-consuming work to service this call, it should return ErrNoSubConnAvailable, and the Pick call will be repeated by gRPC when the Picker is updated (using ClientConn.UpdateState).

If an error is returned:

  • If the error is ErrNoSubConnAvailable, gRPC will block until a new Picker is provided by the balancer (using ClientConn.UpdateState).
  • If the error is a status error (implemented by the grpc/status package), gRPC will terminate the RPC with the code and message provided.
  • For all other errors, wait for ready RPCs will wait, but non-wait for ready RPCs will be terminated with this error's Error() string and status code Unavailable.

Jump to

Keyboard shortcuts

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