pool

package
v4.6.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2016 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed      = errors.New("pg: database is closed")
	ErrPoolTimeout = errors.New("pg: connection pool timeout")
)

Functions

func SetIdleCheckFrequency

func SetIdleCheckFrequency(d time.Duration)

Types

type Buffer

type Buffer struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(w io.Writer, b []byte) *Buffer

func (*Buffer) FinishMessage

func (buf *Buffer) FinishMessage()

func (*Buffer) FinishNullParam

func (buf *Buffer) FinishNullParam()

func (*Buffer) FinishParam

func (buf *Buffer) FinishParam()

func (*Buffer) Flush

func (buf *Buffer) Flush() error

func (*Buffer) ReadFrom

func (buf *Buffer) ReadFrom(r io.Reader) (int64, error)

func (*Buffer) Reset

func (buf *Buffer) Reset()

func (*Buffer) StartMessage

func (buf *Buffer) StartMessage(c byte)

func (*Buffer) StartParam

func (buf *Buffer) StartParam()

func (*Buffer) Write

func (buf *Buffer) Write(b []byte) (int, error)

func (*Buffer) WriteByte

func (buf *Buffer) WriteByte(c byte)

func (*Buffer) WriteBytes

func (buf *Buffer) WriteBytes(b []byte)

func (*Buffer) WriteInt16

func (buf *Buffer) WriteInt16(num int16)

func (*Buffer) WriteInt32

func (buf *Buffer) WriteInt32(num int32)

func (*Buffer) WriteString

func (buf *Buffer) WriteString(s string)

type Conn

type Conn struct {
	NetConn net.Conn
	Buf     []byte
	Rd      *bufio.Reader // read buffer
	Wr      *Buffer       // write buffer

	Inited bool
	UsedAt time.Time

	ProcessId int32
	SecretKey int32
	// contains filtered or unexported fields
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) IsStale

func (cn *Conn) IsStale(timeout time.Duration) bool

func (*Conn) NextId

func (cn *Conn) NextId() string

func (*Conn) Read

func (cn *Conn) Read(b []byte) (int, error)

func (*Conn) ReadN

func (cn *Conn) ReadN(n int) ([]byte, error)

func (*Conn) SetReadTimeout

func (cn *Conn) SetReadTimeout(dur time.Duration)

func (*Conn) SetWriteTimeout

func (cn *Conn) SetWriteTimeout(dur time.Duration)

func (*Conn) Write

func (cn *Conn) Write(b []byte) (int, error)

type ConnPool

type ConnPool struct {
	DialLimiter *ratelimit.RateLimiter
	OnClose     func(*Conn) error
	// contains filtered or unexported fields
}

func NewConnPool

func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckFrequency time.Duration) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() (retErr error)

func (*ConnPool) Closed

func (p *ConnPool) Closed() bool

func (*ConnPool) FreeLen

func (p *ConnPool) FreeLen() int

FreeLen returns number of free connections.

func (*ConnPool) Get

func (p *ConnPool) Get() (*Conn, error)

Get returns existed connection from the pool or creates a new one.

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn() (*Conn, error)

func (*ConnPool) PopFree

func (p *ConnPool) PopFree() *Conn

func (*ConnPool) Put

func (p *ConnPool) Put(cn *Conn) error

func (*ConnPool) ReapStaleConns

func (p *ConnPool) ReapStaleConns() (n int, err error)

func (*ConnPool) Remove

func (p *ConnPool) Remove(cn *Conn, reason error) error

func (*ConnPool) Stats

func (p *ConnPool) Stats() *PoolStats

type PoolStats

type PoolStats struct {
	Requests uint32 // number of times a connection was requested by the pool
	Hits     uint32 // number of times free connection was found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalConns uint32 // the number of total connections in the pool
	FreeConns  uint32 // the number of free connections in the pool
}

PoolStats contains pool state information and accumulated stats.

type Pooler

type Pooler interface {
	Get() (*Conn, error)
	Put(*Conn) error
	Remove(*Conn, error) error
	Len() int
	FreeLen() int
	Stats() *PoolStats
	Close() error
	Closed() bool
}

Jump to

Keyboard shortcuts

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