chpool

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 13 modules, 12 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chpool is a connection pool for ch.

Acquire order

By default (AcquireLIFO), Acquire returns the most recently released connection. This keeps few connections in use and lets idle ones close. Set Options.AcquireStrategy to AcquireFIFO to rotate through all idle connections instead. Use FIFO when connections go to different replicas behind a load balancer and you want queries spread evenly across them. FIFO keeps every connection in use, so the pool does not shrink while it is under load, and each Acquire costs a little more.

Index

Constants

View Source
const (
	DefaultMaxConnLifetime   = time.Hour
	DefaultMaxConnIdleTime   = time.Minute * 30
	DefaultHealthCheckPeriod = time.Minute
)

Defaults for pool.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcquireStrategy added in v0.76.0

type AcquireStrategy uint8

AcquireStrategy controls which idle connection Acquire returns.

const (
	// AcquireLIFO returns the most recently released connection. Under
	// light load, queries reuse a small set of connections and the other
	// connections age out via MaxConnIdleTime. The trade-off is that load
	// does not spread across connections, so if a load balancer sends
	// connections to different replicas, a few replicas get most queries.
	// This is the default.
	AcquireLIFO AcquireStrategy = iota
	// AcquireFIFO returns the least recently released connection,
	// rotating through all idle connections. Use it when connections
	// land on heterogeneous backends behind a load balancer: it
	// spreads queries evenly instead of concentrating load on the
	// slowest backend. The trade-off is that all idle connections stay
	// in rotation, so the pool does not shrink via MaxConnIdleTime
	// while it stays under load.
	// Each acquire scans the idle set, which costs O(n) in the number of
	// idle connections and serializes concurrent acquires. The order is
	// best-effort: a connection released during an acquire can be
	// returned before older ones.
	AcquireFIFO
)

type Client

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

Client is an acquired *ch.Client from a Pool.

func (*Client) Close added in v0.67.0

func (c *Client) Close() error

func (*Client) Do

func (c *Client) Do(ctx context.Context, q ch.Query) (err error)

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) Release

func (c *Client) Release()

Release returns client to the pool.

type Options

type Options struct {
	ClientOptions     ch.Options
	MaxConnLifetime   time.Duration
	MaxConnIdleTime   time.Duration
	MaxConns          int32
	MinConns          int32
	HealthCheckPeriod time.Duration
	// AcquireStrategy controls which idle connection Acquire returns.
	// The default is AcquireLIFO.
	AcquireStrategy AcquireStrategy
}

Options for Pool.

type Pool

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

Pool of connections to ClickHouse.

func Dial

func Dial(ctx context.Context, opt Options) (*Pool, error)

Dial returns a pool of connections to ClickHouse. Checks if ClickHouse is available, fails if not.

func New added in v0.52.0

func New(ctx context.Context, opt Options) (*Pool, error)

New returns a pool of connections to ClickHouse.

func (*Pool) Acquire

func (p *Pool) Acquire(ctx context.Context) (*Client, error)

Acquire connection from pool.

func (*Pool) Close

func (p *Pool) Close()

Close pool.

func (*Pool) Do

func (p *Pool) Do(ctx context.Context, q ch.Query) (err error)

func (*Pool) Ping

func (p *Pool) Ping(ctx context.Context) error

func (*Pool) Stat

func (p *Pool) Stat() *puddle.Stat

Stat return pool statistic.

Jump to

Keyboard shortcuts

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