connpool

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 6 Imported by: 0

README

go-connpool

CircleCI GoDoc |

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 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 returning 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.

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

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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.

func (*Pool) Close

func (p *Pool) Close()

Close closes the connection pool, and terminates all connections contained within the connection pool.

func (*Pool) Get

func (p *Pool) Get(context.Context) (*ClientConn, error)

Get retrieves a healthy connection for use with a GRPC client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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