Documentation ¶
Overview ¶
Package balancer defines APIs for load balancing in gRPC.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
type Node ¶ added in v0.3.0
type Node struct {
// contains filtered or unexported fields
}
Node is the node for the balancer.
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
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.