connpool

package
v0.0.0-...-fd97e0e Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2016 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

connpool Travis CI Status Coverage Status GoDoc

net.Conn pooling for Go.

GoDoc

Documentation

Index

Constants

View Source
const (
	DefaultClaimTimeout = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Size: while active, the pool will attempt to maintain at these many
	// connections.
	Size int

	// ClaimTimeout: connections will be removed from pool if unclaimed for
	// longer than ClaimTimeout. The default ClaimTimeout is 10 minutes. Once
	// connections have been removed from the Pool, they won't be replaced until
	// another connection is requested, at which point the pool will fill again.
	ClaimTimeout time.Duration

	// Dial: specifies the function used to create new connections
	Dial DialFunc
}

Config contains configuration information for a Pool.

type DialFunc

type DialFunc func() (net.Conn, error)

type Pool

type Pool interface {
	// Get gets a connection from the pool, or dials a new one if none are
	// available.
	Get() (net.Conn, error)

	// Close stops the goroutines that are filling the pool, blocking until
	// they've all terminated.
	Close()
}

Pool is a pool of connections, built from a Config using the New method. The purpose of connpool is to accelerate bursty clients, that is to say clients that tend to do a lot of dialing in rapid succeession. At steady state, the pool is usually empty, but once activity is detected it starts to fill itself up and keeps itself filled as long as activity continues.

Connections are pooled lazily up to Size and expire after ClaimTimeout. Lazily here means that the Pool won't start to fill until the first request for a connection. As long as the Pool is actively being used, it will attempt to always have Size number of connections ready to use.

func New

func New(cfg Config) Pool

New creates and starts a Pool.

Jump to

Keyboard shortcuts

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