pool

package
v1.0.5-0...-20c45f9 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CaseRecentDuration = time.Second * 60
)

Variables

This section is empty.

Functions

func SetLog

func SetLog(w io.Writer)

func Timer

func Timer() func() (start, end time.Time, duration time.Duration)

Types

type Counter

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

计数器(线程安全)

func NewCounter

func NewCounter() *Counter

func (*Counter) Dec

func (c *Counter) Dec() int64

自减

func (*Counter) Get

func (c *Counter) Get() int64

获取值

func (*Counter) GetMax

func (c *Counter) GetMax() int64

获取峰值

func (*Counter) Inc

func (c *Counter) Inc() int64

自增

type DynamicPoolMonitor

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

func NewDynamicPoolMonitor

func NewDynamicPoolMonitor(o *Options) *DynamicPoolMonitor

func (*DynamicPoolMonitor) Construct

func (m *DynamicPoolMonitor) Construct() GoroutineUID

强制构建一个新线程

func (*DynamicPoolMonitor) Destroy

func (m *DynamicPoolMonitor) Destroy(gid GoroutineUID)

强制销毁一个线程

func (*DynamicPoolMonitor) GetCurrentActiveCount

func (m *DynamicPoolMonitor) GetCurrentActiveCount() int

获取当前活跃线程数

func (*DynamicPoolMonitor) GetGoroutineCount

func (m *DynamicPoolMonitor) GetGoroutineCount() int

获取当前存活线程数

func (*DynamicPoolMonitor) GetGoroutinePeak

func (m *DynamicPoolMonitor) GetGoroutinePeak() int

获取存活线程数最高峰值

func (*DynamicPoolMonitor) GetStatusSettle

func (m *DynamicPoolMonitor) GetStatusSettle() map[GoroutineStatus]time.Duration

获取状态总结

func (*DynamicPoolMonitor) SwitchGoRoutineStatus

func (m *DynamicPoolMonitor) SwitchGoRoutineStatus(gid GoroutineUID)

切换一个线程的状态

func (*DynamicPoolMonitor) TryConstruct

func (m *DynamicPoolMonitor) TryConstruct(want bool) (GoroutineUID, bool)

尝试创建一个线程

func (*DynamicPoolMonitor) TryDestroy

func (m *DynamicPoolMonitor) TryDestroy(gid GoroutineUID) bool

尝试关闭一个线程 如果线程最近活跃时长较短 则关闭线程

type Generator

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

func NewGenerator

func NewGenerator() *Generator

func (*Generator) Collect

func (i *Generator) Collect(gid GoroutineUID)

func (*Generator) Generate

func (i *Generator) Generate() GoroutineUID

type GoroutinePool

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

func NewGoroutinePool

func NewGoroutinePool(options *Options) *GoroutinePool

func (*GoroutinePool) GetCurrentActiveCount

func (g *GoroutinePool) GetCurrentActiveCount() int

获取当前活跃线程数

func (*GoroutinePool) GetGoroutineCount

func (g *GoroutinePool) GetGoroutineCount() int

获取当前存活线程数

func (*GoroutinePool) GetGoroutinePeak

func (g *GoroutinePool) GetGoroutinePeak() int

获取线程池存活线程峰值

func (*GoroutinePool) GetStatusSettle

func (g *GoroutinePool) GetStatusSettle() map[GoroutineStatus]time.Duration

获取状态总结

func (*GoroutinePool) GetWorkCount

func (g *GoroutinePool) GetWorkCount() int

获取等待线程执行的任务数

func (*GoroutinePool) Put

func (g *GoroutinePool) Put(obj TaskObj)

向线程池推一个任务

func (*GoroutinePool) Stop

func (g *GoroutinePool) Stop()

关闭组件

type GoroutineSettle

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

单个线程信息总结(线程安全)

func NewGoroutineSettle

func NewGoroutineSettle(d time.Duration) *GoroutineSettle

func (*GoroutineSettle) AutoSwitchGoRoutineStatus

func (g *GoroutineSettle) AutoSwitchGoRoutineStatus() GoroutineStatus

切换线程状态

func (*GoroutineSettle) GetRecentActiveRatio

func (g *GoroutineSettle) GetRecentActiveRatio() float64

获取最近活跃占比

func (*GoroutineSettle) GetRecentStatusSettle

func (g *GoroutineSettle) GetRecentStatusSettle() map[GoroutineStatus]time.Duration

获取最近时间状态总结

func (*GoroutineSettle) GetStatus

func (g *GoroutineSettle) GetStatus() GoroutineStatus

获取当前状态

func (*GoroutineSettle) GetStatusSettle

func (g *GoroutineSettle) GetStatusSettle() map[GoroutineStatus]time.Duration

获取所有时间状态总结

func (*GoroutineSettle) GetSurvivalDuration

func (g *GoroutineSettle) GetSurvivalDuration() time.Duration

type GoroutineSettleMap

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

多线程信息总结(线程安全)

func NewGoroutineSettleMap

func NewGoroutineSettleMap() *GoroutineSettleMap

func (*GoroutineSettleMap) AutoSwitchGoRoutineStatus

func (m *GoroutineSettleMap) AutoSwitchGoRoutineStatus(gid GoroutineUID) GoroutineStatus

切换线程状态

func (*GoroutineSettleMap) DeleteGoroutineSettle

func (m *GoroutineSettleMap) DeleteGoroutineSettle(gid GoroutineUID)

终结一个线程

func (*GoroutineSettleMap) GetActiveGoroutineCount

func (m *GoroutineSettleMap) GetActiveGoroutineCount() int

获取当前处于活跃状态的线程数

func (*GoroutineSettleMap) GetAllGoroutineStatusDuration

func (m *GoroutineSettleMap) GetAllGoroutineStatusDuration() map[GoroutineStatus]time.Duration

获取当前所有存活线程的所有状态总结

func (*GoroutineSettleMap) GetAllGoroutineUID

func (m *GoroutineSettleMap) GetAllGoroutineUID() []GoroutineUID

获取所有存活线程ID

func (*GoroutineSettleMap) GetCurrentStatus

func (m *GoroutineSettleMap) GetCurrentStatus(gid GoroutineUID) GoroutineStatus

func (*GoroutineSettleMap) GetRecentActiveRatio

func (m *GoroutineSettleMap) GetRecentActiveRatio(gid GoroutineUID) float64

获取指定线程最近活跃占比

func (*GoroutineSettleMap) GetRecentStatusSettle

func (m *GoroutineSettleMap) GetRecentStatusSettle(gid GoroutineUID) map[GoroutineStatus]time.Duration

获取最近时间状态总结

func (*GoroutineSettleMap) GetStatusSettle

func (m *GoroutineSettleMap) GetStatusSettle(gid GoroutineUID) map[GoroutineStatus]time.Duration

获取指定线程所有时间状态总结

func (*GoroutineSettleMap) GetSurvivalDuration

func (m *GoroutineSettleMap) GetSurvivalDuration(gid GoroutineUID) time.Duration

获取线程存活时间

func (*GoroutineSettleMap) NewGoroutineSettle

func (m *GoroutineSettleMap) NewGoroutineSettle(gid GoroutineUID, gs *GoroutineSettle) GoroutineUID

构建一个新的线程

type GoroutineStatus

type GoroutineStatus int
const (
	GoroutineStatusNone   GoroutineStatus = 0
	GoroutineStatusActive GoroutineStatus = 1
	GoroutineStatusSleep  GoroutineStatus = 2
)

func SwitchStatus

func SwitchStatus(p GoroutineStatus) (s GoroutineStatus)

状态转移

func (GoroutineStatus) IsValid

func (s GoroutineStatus) IsValid() bool

func (GoroutineStatus) ToString

func (s GoroutineStatus) ToString() string

type GoroutineUID

type GoroutineUID int

type IGenerator

type IGenerator interface {
	Generate() GoroutineUID
	Collect(gid GoroutineUID)
}

ID 生成器

type Latency

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

单种状态总结(线程安全)

func NewLatency

func NewLatency(status GoroutineStatus) *Latency

func (*Latency) AmountDurationOfNow

func (l *Latency) AmountDurationOfNow() *Latency

func (*Latency) AmountDurationOfTime

func (l *Latency) AmountDurationOfTime(t time.Time) *Latency

func (*Latency) Clone

func (l *Latency) Clone() *Latency

func (*Latency) IsStart

func (l *Latency) IsStart() bool

func (*Latency) Start

func (l *Latency) Start()

如果原先状态为启动 那么不操作

func (*Latency) Stop

func (l *Latency) Stop()

如果原先状态为停止 那么不操作

type LatencyMap

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

多状态总结(线程安全)

func NewLatencyMap

func NewLatencyMap() *LatencyMap

func (*LatencyMap) Clone

func (g *LatencyMap) Clone() *LatencyMap

func (*LatencyMap) GetAll

func (g *LatencyMap) GetAll() map[GoroutineStatus]time.Duration

func (*LatencyMap) IsStart

func (g *LatencyMap) IsStart(status GoroutineStatus) bool

func (*LatencyMap) Set

func (g *LatencyMap) Set(status GoroutineStatus, l *Latency)

func (*LatencyMap) Start

func (g *LatencyMap) Start(status GoroutineStatus)

func (*LatencyMap) Stop

func (g *LatencyMap) Stop(status GoroutineStatus)

type Options

type Options struct {
	AutoMonitorDuration time.Duration // 定时check时长
	CloseLessThanF      float64       // 定时check活跃线程比例 小于50%时 会关闭当前线程
	NewGreaterThanF     float64       // 活跃线程比例大于90%时 新任务会创建新线程去跑
	GoroutineLimit      int           // 线程上限数
	TaskChannelSize     int           // 任务channel尺寸
}

func NewDefaultOptions

func NewDefaultOptions() *Options

构建默认配置

func (*Options) Clone

func (o *Options) Clone() *Options

type RecentRecord

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

存储最后d时长的切换记录

func NewRecentRecord

func NewRecentRecord(d time.Duration) *RecentRecord

func (*RecentRecord) AddSwitchRecord

func (l *RecentRecord) AddSwitchRecord(preStatus, status GoroutineStatus)

添加切换记录

func (*RecentRecord) Clone

func (l *RecentRecord) Clone() *RecentRecord

生成副本

func (*RecentRecord) GetRecentSettle

func (l *RecentRecord) GetRecentSettle() map[GoroutineStatus]time.Duration

获取最近的状态总结

type StatusSettle

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

单线程状态总结(线程安全)

func NewStatusSettle

func NewStatusSettle(status GoroutineStatus, duration time.Duration) *StatusSettle

func (*StatusSettle) AddDuration

func (s *StatusSettle) AddDuration(duration time.Duration)

func (*StatusSettle) GetDuration

func (s *StatusSettle) GetDuration() time.Duration

type StatusSettleMap

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

多线程状态总结(线程安全)

func NewStatusSettleMap

func NewStatusSettleMap() *StatusSettleMap

func (*StatusSettleMap) AddMultiStatusDuration

func (m *StatusSettleMap) AddMultiStatusDuration(multiStatusDuration map[GoroutineStatus]time.Duration)

func (*StatusSettleMap) AddStatusDuration

func (m *StatusSettleMap) AddStatusDuration(status GoroutineStatus, duration time.Duration)

func (*StatusSettleMap) GetAllStatusDuration

func (m *StatusSettleMap) GetAllStatusDuration() map[GoroutineStatus]time.Duration

func (*StatusSettleMap) GetOrCreate

func (m *StatusSettleMap) GetOrCreate(status GoroutineStatus, duration time.Duration) *StatusSettle

type StatusSwitch

type StatusSwitch struct {
	Time      time.Time       // 切换时间
	PreStatus GoroutineStatus // 切换前状态
	Status    GoroutineStatus // 切换后状态
}

切换状态信息

func NewStatusSwitch

func NewStatusSwitch(preStatus, status GoroutineStatus) *StatusSwitch

func (*StatusSwitch) Clone

func (s *StatusSwitch) Clone() *StatusSwitch

func (*StatusSwitch) Equal

func (s *StatusSwitch) Equal(t time.Time) bool

func (*StatusSwitch) Gte

func (s *StatusSwitch) Gte(t time.Time) bool

func (*StatusSwitch) Lt

func (s *StatusSwitch) Lt(t time.Time) bool

type TaskObj

type TaskObj func(gid GoroutineUID)

任务函数 gid为执行该任务的线程id

Jump to

Keyboard shortcuts

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