balancer

package
v0.0.0-...-faba519 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 17 Imported by: 3

README

GRPC Balancer

This package is a forked version of https://github.com/GoogleCloudPlatform/grpc-gcp-go.

We use this primarily to create new sub-connections when we reach maximum number of streams (100 for GFE) on a given connection.

Refer to https://github.com/grpc/grpc/issues/21386 for status on the long-term fix for this issue.

Documentation

Overview

Package balancer is a forked version of https://github.com/GoogleCloudPlatform/grpc-gcp-go.

Index

Constants

View Source
const (
	// Name is the name of grpc_gcp balancer.
	Name = "grpc_gcp"
)

Variables

View Source
var (
	// DefaultMinConnections is the default number of gRPC sub-connections the
	// gRPC balancer should create during SDK initialization.
	DefaultMinConnections = 5

	// MinConnections is the minimum number of gRPC sub-connections the gRPC balancer
	// should create during SDK initialization.
	// It is initialized in flags package.
	MinConnections = DefaultMinConnections
)

Functions

func ParseAPIConfig

func ParseAPIConfig(path string) (*pb.ApiConfig, error)

ParseAPIConfig parses a json config file into ApiConfig proto message.

Types

type DialFunc

type DialFunc func(ctx context.Context) (*grpc.ClientConn, error)

DialFunc defines the dial function used in creating the pool.

type GCPInterceptor

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

GCPInterceptor provides functions for intercepting client requests in order to support GCP specific features

func NewGCPInterceptor

func NewGCPInterceptor(config *pb.ApiConfig) *GCPInterceptor

NewGCPInterceptor creates a new GCPInterceptor with a given ApiConfig

func (*GCPInterceptor) GCPStreamClientInterceptor

func (gcpInt *GCPInterceptor) GCPStreamClientInterceptor(
	ctx context.Context,
	desc *grpc.StreamDesc,
	cc *grpc.ClientConn,
	method string,
	streamer grpc.Streamer,
	opts ...grpc.CallOption,
) (grpc.ClientStream, error)

GCPStreamClientInterceptor intercepts the execution of a client streaming RPC and injects necessary information to be used by the picker.

func (*GCPInterceptor) GCPUnaryClientInterceptor

func (gcpInt *GCPInterceptor) GCPUnaryClientInterceptor(
	ctx context.Context,
	method string,
	req interface{},
	reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

GCPUnaryClientInterceptor intercepts the execution of a unary RPC and injects necessary information to be used by the picker.

type RRConnPool

type RRConnPool struct {
	grpc.ClientConnInterface
	io.Closer
	// contains filtered or unexported fields
}

RRConnPool is a pool of *grpc.ClientConn that are selected in a round-robin fashion.

func NewRRConnPool

func NewRRConnPool(ctx context.Context, poolSize int, dialFn DialFunc) (*RRConnPool, error)

NewRRConnPool makes a new instance of the round-robin connection pool and dials as many as poolSize connections using the provided dialFn.

func (*RRConnPool) Close

func (p *RRConnPool) Close() error

Close closes all connections in the bool.

func (*RRConnPool) Conn

func (p *RRConnPool) Conn() *grpc.ClientConn

Conn picks the next connection from the pool in a round-robin fasion.

func (*RRConnPool) Invoke

func (p *RRConnPool) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error

Invoke picks up a connection from the pool and delegates the call to it.

func (*RRConnPool) NewStream

func (p *RRConnPool) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)

NewStream picks up a connection from the pool and delegates the call to it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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