clientpool

package
v0.9.12-beta.8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package clientpool provides implementations of a generic client pool.

The channel implementation has roughly 300ns overhead on Get/Release pair calls:

$ go test -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/reddit/baseplate.go/clientpool
BenchmarkPoolGetRelease/channel-8         	 3993308	       278 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/reddit/baseplate.go/clientpool	2.495s

This package is considered low level and should not be used directly in most cases. A thrift-specific wrapping is available in thriftbp package.

Index

Constants

This section is empty.

Variables

View Source
var ErrExhausted = exhaustedError{}

ErrExhausted is the error returned by Get when the pool is exhausted.

Functions

This section is empty.

Types

type Client

type Client interface {
	io.Closer

	IsOpen() bool
}

Client is a minimal interface for a client needed by the pool.

TTransport interface in thrift satisfies Client interface, so embedding the TTransport used by the actual client is a common way to implement the ClientOpener for thrift Clients.

type ClientOpener

type ClientOpener func() (Client, error)

ClientOpener defines a generator for clients.

type ConfigError

type ConfigError struct {
	BestEffortInitialClients int
	RequiredInitialClients   int
	MaxClients               int
}

ConfigError is the error type returned when trying to open a new client pool, but the configuration values passed in won't work.

func (*ConfigError) Error

func (e *ConfigError) Error() string

type Pool

type Pool interface {
	io.Closer

	Get() (Client, error)
	Release(c Client) error
	NumActiveClients() int32
	NumAllocated() int32
	IsExhausted() bool
}

Pool defines the client pool interface.

func NewChannelPool

func NewChannelPool(ctx context.Context, requiredInitialClients, bestEffortInitialClients, maxClients int, opener ClientOpener) (Pool, error)

NewChannelPool creates a new client pool implemented via channel.

Note that this function could return both non-nil Pool and error, when we failed to create all asked bestEffortInitialClients. In such case the returned Pool would have at least requiredInitialClients clients we already established.

Jump to

Keyboard shortcuts

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