pool

package
v0.0.0-...-efcb6f0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pool 实现了连接池管理

pool.Manager,连接池管理器,它为每个后端服务维护了一个连接池pool.pool, pool.pool,连接池,它维护了一个远程地址对应的一组连接pool.connection, pool.connection,虚拟连接,它嵌入了一个net.Conn来完成真正的Read, Write操作,

对于Close操作我们对齐进行了重写,以让连接的关闭操作由连接池接管

连接池会根据连接上发生的错误类型、连接池当前状态来决定是关闭还是复用连接。

使用时可以通过:

pm := pool.New(...) c, err := pm.Get(ctx, net, address)

if err != nil {
  ...
}

defer c.Close()

//do something about reading/writing ...

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnLeaked       = errors.New("connection leaked")              // 连接池连接泄露
	ErrConnIdle         = errors.New("connection idle")                // 连接空闲
	ErrConnTooMany      = errors.New("connection too many")            // 连接太多了
	ErrConnInitNumLimit = errors.New("open connection: limit by init") // 初始数量限制
	ErrConnMinNumLimit  = errors.New("open connection: limit by min")  // 最小数量限制
)

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 连接池管理器,应用程序初始化一个实例即可,它负责维护所有callee的连接池

func New

func New(init, min, max int, checkInterval, idleBeforeClose time.Duration) *Manager

New 创建一个连接池管理器

func (*Manager) Get

func (pm *Manager) Get(ctx context.Context, network, address string) (net.Conn, error)

Get return a tcpconn for use

Jump to

Keyboard shortcuts

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