Documentation ¶
Overview ¶
Package balancer defines APIs for load balancing in gRPC.
Index ¶
- Variables
- type Balancer
- func (Balancer) Register(builders ...gsel.Builder)
- func (b Balancer) WithLeastConnection() grpc.DialOption
- func (b Balancer) WithName(name string) grpc.DialOption
- func (b Balancer) WithRandom() grpc.DialOption
- func (b Balancer) WithRoundRobin() grpc.DialOption
- func (b Balancer) WithWeight() grpc.DialOption
- type Builder
- type Node
- type Picker
Constants ¶
This section is empty.
Variables ¶
var ( Random = gsel.NewBuilderRandom() Weight = gsel.NewBuilderWeight() RoundRobin = gsel.NewBuilderRoundRobin() LeastConnection = gsel.NewBuilderLeastConnection() )
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer struct{}
func (Balancer) WithLeastConnection ¶
func (b Balancer) WithLeastConnection() grpc.DialOption
WithLeastConnection returns a grpc.DialOption which enables the least connection load balancing.
func (Balancer) WithName ¶
func (b Balancer) WithName(name string) grpc.DialOption
WithName returns a grpc.DialOption which enables the load balancing by name.
func (Balancer) WithRandom ¶
func (b Balancer) WithRandom() grpc.DialOption
WithRandom returns a grpc.DialOption which enables random load balancing.
func (Balancer) WithRoundRobin ¶
func (b Balancer) WithRoundRobin() grpc.DialOption
WithRoundRobin returns a grpc.DialOption which enables round-robin load balancing.
func (Balancer) WithWeight ¶
func (b Balancer) WithWeight() grpc.DialOption
WithWeight returns a grpc.DialOption which enables weight load balancing.
type Builder ¶
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.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the node for the balancer.
type Picker ¶
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 ¶
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.