Documentation
¶
Overview ¶
Package connpool provides GRPC connection pooling. This allows clients to distribute their requests across (level 3 or 4) load balanced services.
This package is based on the [grpc-go-pool](https://github.com/processout/grpc-go-pool) package, but cures a fundamental inefficiency. GRPC allows for multiplexing requests on a single connection. But grpc-go-pool removes a connection from the pool for each call to it's New(...) function, not ruturning it to the pool until it is closed. This limits the connection to a single client at a time, and thus a single request at a time.
This package leaves connections in the pool for use by multiple clients, thus allowing for multiplexed requests. In application, we have seen a 5-fold increase in throughput.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
type ClientConn struct { *grpc.ClientConn sync.RWMutex // contains filtered or unexported fields }
ClientConn is a client connection managed by the connection pool.
func (*ClientConn) Close ¶
func (c *ClientConn) Close()
Close communicates to a connection that a GRPC client is done using the connection. The connection itself will only be terminated if it is no longer healthy.
type Factory ¶
type Factory func() (*grpc.ClientConn, error)
Factory is a function type creating a GRPC connection.
type Pool ¶
Pool is the GRPC connection pool.
func New ¶
func New( factory Factory, capacity int, idleTimeout time.Duration, lifeTimeout time.Duration) *Pool
New creates a new connection pool. The factory parameter accepts a function that creates new connections. The capacity parameter sets the maximum capacity of healthy connections inside the connection pool. The idleTimeout parameter sets a duration after which, if no new requests are made on the connection, the connection is recycled. The lifeTimeout parameter sets a duration that is the maximum lifetime of a connection before it is recycled. Negative idleTimeout or lifeTimeout values mean no timeouts.