pool

package
v1.7.17 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package pool provides gRPC connection pool client

This re-implementation maintains the public Conn interface unchanged while using atomic operations for efficient, lock-free connection management. Additional features such as DNS lookup, port scanning, and metrics collection are incorporated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Metrics added in v1.7.17

func Metrics(ctx context.Context) map[string]uint64

Metrics returns a map of healthy connection counts per target address.

Types

type ClientConn

type ClientConn = grpc.ClientConn

Alias types for clarity.

type Conn

type Conn interface {
	// Connect establishes connections for all slots.
	Connect(context.Context) (Conn, error)
	// Disconnect gracefully closes all connections in the pool.
	Disconnect(context.Context) error
	// Do executes the provided function using a healthy connection.
	Do(context.Context, func(*ClientConn) error) error
	// Get returns a healthy connection from the pool, if available.
	Get(context.Context) (*ClientConn, bool)
	// IsHealthy checks the overall health of the pool.
	IsHealthy(context.Context) bool
	// IsIPConn indicates whether the pool is using direct IP connections.
	IsIPConn() bool
	// Len returns the number of connection slots.
	Len() uint64
	// Size returns the configured pool size.
	Size() uint64
	// Reconnect re-establishes connections if the pool is unhealthy or if forced.
	Reconnect(context.Context, bool) (Conn, error)
	// String returns a string representation of the pool's state.
	String() string
}

Conn defines the interface for a gRPC connection pool.

func New

func New(ctx context.Context, opts ...Option) (Conn, error)

New creates a new connection pool with the provided options. It parses the target address, initializes the connection slots, and performs an initial dial check.

type DialOption

type DialOption = grpc.DialOption

Alias types for clarity.

type Option

type Option func(*pool)

Option defines a functional option for configuring the pool.

func WithAddr

func WithAddr(addr string) Option

WithAddr sets the target address. It also extracts the host and port.

func WithBackoff

func WithBackoff(bo backoff.Backoff) Option

WithBackoff sets the backoff strategy.

func WithDialOptions

func WithDialOptions(opts ...DialOption) Option

WithDialOptions appends gRPC dial options.

func WithDialTimeout added in v0.0.32

func WithDialTimeout(dur string) Option

WithDialTimeout sets the dial timeout duration.

func WithEndPort

func WithEndPort(port int) Option

WithEndPort sets the ending port for scanning.

func WithErrGroup added in v1.3.1

func WithErrGroup(eg errgroup.Group) Option

WithErrGroup sets the errgroup for goroutine management.

func WithHost

func WithHost(host string) Option

WithHost sets the target host.

func WithOldConnCloseDelay added in v1.7.17

func WithOldConnCloseDelay(dur string) Option

WithOldConnCloseDelay sets the delay before closing old connections.

func WithPort

func WithPort(port int) Option

WithPort sets the target port.

func WithResolveDNS added in v0.0.45

func WithResolveDNS(enable bool) Option

WithResolveDNS enables or disables DNS resolution.

func WithSize

func WithSize(size uint64) Option

WithSize sets the pool size.

func WithStartPort

func WithStartPort(port int) Option

WithStartPort sets the starting port for scanning.

Jump to

Keyboard shortcuts

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