Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultMaxSendMsgSize int = 8 * 1024 * 1024 DefaultMaxRecvMsgSize int = 8 * 1024 * 1024 DefaultInitialWindowSize int32 = 128 * 1024 * 1024 DefaultInitialConnWindowSize int32 = 128 * 1024 * 1024 DefaultDialTimeout = 5 * time.Second DefaultMinConnectTimeout = 3 * time.Second DefaultKeepAliveTime = 10 * time.Second DefaultKeepAliveTimeout = 3 * time.Second )
NOTE: Tune the default values to provide better system's throughput.
Functions ¶
func DefaultDial ¶
func DefaultDial(serverAddr, serverName, certFile string) (*grpc.ClientConn, error)
DefaultDial returns a secure grpc client connection with default settings.
func DefaultDialWithInsecure ¶
func DefaultDialWithInsecure(serverAddr string) (*grpc.ClientConn, error)
DefaultDialWithInsecure returns an insecure grpc client connection with default settings.
Types ¶
type GrpcClientConnPool ¶
type GrpcClientConnPool struct {
// contains filtered or unexported fields
}
func NewGrpcClientConnPool ¶
func NewGrpcClientConnPool(opts ...PoolSettingsOption) (p *GrpcClientConnPool, err error)
NewGrpcClientConnPool returns a new fresh grpc client connection pool.
func (*GrpcClientConnPool) PickOne ¶
func (p *GrpcClientConnPool) PickOne(wait bool, waitTime int64) (*GrpcConn, error)
PickOne returns a available connection from the pool. User should use GrpcConn.Close() to put the connection back to the pool. If waitTime <= 0, which means block waiting for PickOne.
func (*GrpcClientConnPool) Release ¶
func (p *GrpcClientConnPool) Release() error
Release releases all pool resources.
func (*GrpcClientConnPool) Status ¶
func (p *GrpcClientConnPool) Status() string
Status returns the current status of the pool.
type GrpcConn ¶
type GrpcConn struct {
// contains filtered or unexported fields
}
GrpcConn encapsulates the grpc.ClientConn.
func (*GrpcConn) Close ¶
func (c *GrpcConn) Close()
Close decreases the reference of grpc connection if pool not full or just close the underlay TCP connection.
func (*GrpcConn) Underlay ¶
func (c *GrpcConn) Underlay() *grpc.ClientConn
Underlay returns the actual grpc connection.
type PoolSettings ¶
type PoolSettings struct { // Grpc server address to serve client connections. Addr string // An app-supplied-function for connection creation and configuration. Dial func(addr string) (conn *grpc.ClientConn, err error) // Maximum number of idle connections inside the pool, should be the power of 2. MaxIdles uint32 // Maximum number of connections can be allocated by the pool at a given time, should be the power of 2. MaxActives uint32 // Maximum number of concurrent streams attached to a single tcp connection, should be the power of 2. MaxStreams uint32 }
PoolSettings includes pool settings for pool initialization.
type PoolSettingsOption ¶
type PoolSettingsOption func(settings *PoolSettings)
func WithAddr ¶
func WithAddr(addr string) PoolSettingsOption
func WithDialFunc ¶
func WithDialFunc(f func(addr string) (conn *grpc.ClientConn, err error)) PoolSettingsOption
func WithMaxActives ¶
func WithMaxActives(n uint32) PoolSettingsOption
func WithMaxIdles ¶
func WithMaxIdles(n uint32) PoolSettingsOption
func WithMaxStreams ¶
func WithMaxStreams(n uint32) PoolSettingsOption