Documentation
¶
Index ¶
- Variables
- type AdaptiveOptions
- type AdaptivePool
- func (ap *AdaptivePool) Close() error
- func (ap *AdaptivePool) Get(ctx context.Context) (*PoolConn, error)
- func (ap *AdaptivePool) GetExtendedStatus() AdaptiveStatus
- func (ap *AdaptivePool) Preconnect(ctx context.Context, count int) error
- func (ap *AdaptivePool) Put(conn *PoolConn) error
- func (ap *AdaptivePool) Status() Status
- type AdaptiveStatus
- type ConnectionFactory
- type Options
- type Pool
- type PoolConn
- type Status
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrPoolClosed = errors.New("connection pool is closed") ErrTimeout = errors.New("connection pool: get connection timed out") )
Functions ¶
This section is empty.
Types ¶
type AdaptiveOptions ¶
type AdaptiveOptions struct {
// 基础连接池选项
BaseOptions Options
// 健康检查相关
HealthCheckInterval time.Duration // 健康检查间隔
HealthCheckTimeout time.Duration // 健康检查超时
// 自适应调整相关
EnableAdaptive bool // 是否启用自适应调整
LoadCheckInterval time.Duration // 负载检查间隔
HighLoadThreshold float64 // 高负载阈值 (0.0-1.0)
LowLoadThreshold float64 // 低负载阈值 (0.0-1.0)
ScaleUpFactor float64 // 扩容因子 (如1.2表示增加20%)
ScaleDownFactor float64 // 缩容因子 (如0.8表示减少20%)
MinConnections int // 最小连接数
MaxConnections int // 最大连接数
ScaleCooldownPeriod time.Duration // 两次缩放操作之间的冷却期
}
AdaptiveOptions 自适应连接池选项
func DefaultAdaptiveOptions ¶
func DefaultAdaptiveOptions() AdaptiveOptions
DefaultAdaptiveOptions 返回默认的自适应连接池选项
type AdaptivePool ¶
type AdaptivePool struct {
// contains filtered or unexported fields
}
AdaptivePool 自适应连接池实现
func (*AdaptivePool) Get ¶
func (ap *AdaptivePool) Get(ctx context.Context) (*PoolConn, error)
Get 从连接池获取一个连接
func (*AdaptivePool) GetExtendedStatus ¶
func (ap *AdaptivePool) GetExtendedStatus() AdaptiveStatus
GetExtendedStatus 返回扩展的连接池状态信息
func (*AdaptivePool) Preconnect ¶
func (ap *AdaptivePool) Preconnect(ctx context.Context, count int) error
预热连接池,创建一定数量的初始连接
type AdaptiveStatus ¶
type AdaptiveStatus struct {
Status Status
SuccessCount uint64
FailureCount uint64
TimeoutCount uint64
HealthFailures uint64
ScaleUpEvents uint32
ScaleDownEvents uint32
}
AdaptiveStatus 扩展的连接池状态
type ConnectionFactory ¶
ConnectionFactory 用于创建新的连接
type Options ¶
type Options struct {
// 最大空闲连接数
MaxIdle int
// 最大活跃连接数
MaxActive int
// 连接最大空闲时间,超过这个时间将被关闭
IdleTimeout time.Duration
// 获取连接的最大等待时间
WaitTimeout time.Duration
// 是否在连接池满时阻塞等待
Wait bool
}
Options 配置连接池参数
type Pool ¶
type Pool interface {
// Get 获取一个连接
Get(ctx context.Context) (*PoolConn, error)
// Put 归还一个连接
Put(conn *PoolConn) error
// Close 关闭连接池
Close() error
// Status 返回连接池状态信息
Status() Status
}
Pool 连接池接口
func NewAdaptivePool ¶
func NewAdaptivePool(target string, factory ConnectionFactory, opts AdaptiveOptions) Pool
NewAdaptivePool 创建新的自适应连接池
type PoolConn ¶
type PoolConn struct {
*grpc.ClientConn
// contains filtered or unexported fields
}
PoolConn 包装grpc.ClientConn,添加连接池管理相关信息
Click to show internal directories.
Click to hide internal directories.