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/fizx/baseplate.go/clientpool BenchmarkPoolGetRelease/channel-8 3993308 278 ns/op 0 B/op 0 allocs/op PASS ok github.com/fizx/baseplate.go/clientpool 2.495s
This package is considered low level. Package thriftclient provided a more useful, thrift-specific wrapping to this package. In most cases you would want to use that package instead if you are using the pool for thrift clients. See thriftclient package's doc for examples.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExhausted = errors.New("clientpool: exhausted")
ErrExhausted is the error returned by Get when the pool is exhausted.
Functions ¶
This section is empty.
Types ¶
type Client ¶
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. thriftclient.TTLClient also implements it, with an additional TTL to the transport.
type ClientOpener ¶
ClientOpener defines a generator for clients.
type ConfigError ¶
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(initialClients, maxClients int, opener ClientOpener) (Pool, error)
NewChannelPool creates a new client pool implemented via channel.