clientpool

package
v0.0.0-...-bde19ca Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: BSD-3-Clause Imports: 4 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/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

View Source
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

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. thriftclient.TTLClient also implements it, with an additional TTL to the transport.

type ClientOpener

type ClientOpener func() (Client, error)

ClientOpener defines a generator for clients.

type ConfigError

type ConfigError struct {
	InitialClients 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(initialClients, maxClients int, opener ClientOpener) (Pool, error)

NewChannelPool creates a new client pool implemented via channel.

Jump to

Keyboard shortcuts

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