pool

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

@Author daixk 2025-10-28 22:00:20

Index

Constants

View Source
const (
	DefaultMinSize       = 100              // Minimum pool size | 最小协程数
	DefaultMaxSize       = 2000             // Maximum pool size | 最大协程数
	DefaultScaleUpRate   = 0.8              // Scale-up threshold (expand when usage exceeds this ratio) | 扩容阈值,当使用率超过此比例时扩容
	DefaultScaleDownRate = 0.3              // Scale-down threshold (shrink when usage below this ratio) | 缩容阈值,当使用率低于此比例时缩容
	DefaultCheckInterval = time.Minute      // Interval for auto-scaling checks | 检查间隔
	DefaultExpiry        = 10 * time.Second // Idle worker expiry duration | 空闲协程过期时间
)

Default configuration constants | 默认配置常量

Variables

This section is empty.

Functions

This section is empty.

Types

type RenewPoolBuilder

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

RenewPoolBuilder builder for RenewPoolManager | RenewPoolManager 构造器

func NewRenewPoolBuilder

func NewRenewPoolBuilder() *RenewPoolBuilder

NewRenewPoolBuilder creates a new builder | 创建构造器

func (*RenewPoolBuilder) Build

func (b *RenewPoolBuilder) Build() (*RenewPoolManager, error)

Build constructs a RenewPoolManager instance | 构建 RenewPoolManager 实例

func (*RenewPoolBuilder) CheckInterval

func (b *RenewPoolBuilder) CheckInterval(interval time.Duration) *RenewPoolBuilder

CheckInterval sets auto-scaling check interval | 设置检查间隔

func (*RenewPoolBuilder) Config

func (b *RenewPoolBuilder) Config() *RenewPoolConfig

Config returns the current RenewPoolConfig | 返回当前的续期池配置

func (*RenewPoolBuilder) Expiry

func (b *RenewPoolBuilder) Expiry(expiry time.Duration) *RenewPoolBuilder

Expiry sets worker expiry duration | 设置空闲协程过期时间

func (*RenewPoolBuilder) MaxSize

func (b *RenewPoolBuilder) MaxSize(size int) *RenewPoolBuilder

MaxSize sets maximum pool size | 设置最大协程数

func (*RenewPoolBuilder) MinSize

func (b *RenewPoolBuilder) MinSize(size int) *RenewPoolBuilder

MinSize sets minimum pool size | 设置最小协程数

func (*RenewPoolBuilder) NonBlocking

func (b *RenewPoolBuilder) NonBlocking(nonblocking bool) *RenewPoolBuilder

NonBlocking sets non-blocking mode | 设置是否非阻塞模式

func (*RenewPoolBuilder) PreAlloc

func (b *RenewPoolBuilder) PreAlloc(prealloc bool) *RenewPoolBuilder

PreAlloc sets pre-allocation flag | 设置是否预分配内存

func (*RenewPoolBuilder) PrintStatusInterval

func (b *RenewPoolBuilder) PrintStatusInterval(interval time.Duration) *RenewPoolBuilder

PrintStatusInterval sets the interval for printing pool status | 设置打印状态的间隔

func (*RenewPoolBuilder) ScaleDownRate

func (b *RenewPoolBuilder) ScaleDownRate(down float64) *RenewPoolBuilder

ScaleDownRate sets the threshold for scaling down | 设置缩容阈值

func (*RenewPoolBuilder) ScaleUpRate

func (b *RenewPoolBuilder) ScaleUpRate(up float64) *RenewPoolBuilder

ScaleUpRate sets the threshold for scaling up | 设置扩容阈值

type RenewPoolConfig

type RenewPoolConfig struct {
	MinSize             int           // Minimum pool size | 最小协程数
	MaxSize             int           // Maximum pool size | 最大协程数
	ScaleUpRate         float64       // Scale-up threshold | 扩容阈值
	ScaleDownRate       float64       // Scale-down threshold | 缩容阈值
	CheckInterval       time.Duration // Auto-scale check interval | 检查间隔
	Expiry              time.Duration // Idle worker expiry duration | 空闲协程过期时间
	PrintStatusInterval time.Duration // Interval for periodic status printing (0 = disabled) | 定时打印池状态的间隔(0表示关闭)
	PreAlloc            bool          // Whether to pre-allocate memory | 是否预分配内存
	NonBlocking         bool          // Whether to use non-blocking mode | 是否为非阻塞模式
}

RenewPoolConfig configuration for the renewal pool manager | 续期池配置

func DefaultRenewPoolConfig

func DefaultRenewPoolConfig() *RenewPoolConfig

DefaultRenewPoolConfig returns default configuration | 返回默认配置

type RenewPoolManager

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

RenewPoolManager manages a dynamic scaling goroutine pool for token renewal tasks | 续期任务协程池管理器

func NewRenewPoolManagerWithConfig

func NewRenewPoolManagerWithConfig(cfg *RenewPoolConfig) (*RenewPoolManager, error)

NewRenewPoolManagerWithConfig creates manager with config | 使用配置创建续期池管理器

func (*RenewPoolManager) PrintStatus

func (m *RenewPoolManager) PrintStatus()

PrintStatus prints current pool status | 打印池状态

func (*RenewPoolManager) Stats

func (m *RenewPoolManager) Stats() (running, capacity int, usage float64)

Stats returns current pool statistics | 返回当前池状态

func (*RenewPoolManager) Stop

func (m *RenewPoolManager) Stop()

Stop stops the auto-scaling process | 停止自动扩缩容

func (*RenewPoolManager) Submit

func (m *RenewPoolManager) Submit(task func()) error

Submit submits a renewal task | 提交续期任务

Jump to

Keyboard shortcuts

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