Documentation
¶
Index ¶
- Constants
- Variables
- func WithDetectInterval(detectInterval time.Duration) dynamicOption
- func WithDynamicTaskQueueCap(taskQueueCap int) dynamicOption
- func WithMeetCondNum(meetCondNum int) dynamicOption
- func WithTaskQueueCap(taskQueueCap int) option
- type AtomicBool
- type Callable
- type DynamicGPool
- func (p *DynamicGPool) Cancel() bool
- func (p *DynamicGPool) CurrentGCount() int
- func (p *DynamicGPool) IsShutdown() bool
- func (p *DynamicGPool) Shutdown()
- func (p *DynamicGPool) Submit(task Callable) (Future, error)
- func (p *DynamicGPool) TaskQueueCap() int
- func (p *DynamicGPool) TaskQueueLength() int
- func (p *DynamicGPool) WaitTerminate()
- type DynamicGPoolOption
- type ExecutorService
- type FixedGPool
- func (p *FixedGPool) Cancel() bool
- func (p *FixedGPool) Consume()
- func (p *FixedGPool) CurrentGCount() int
- func (p *FixedGPool) IsShutdown() bool
- func (p *FixedGPool) Shutdown()
- func (p *FixedGPool) Submit(task Callable) (Future, error)
- func (p *FixedGPool) TaskQueueCap() int
- func (p *FixedGPool) TaskQueueLength() int
- func (p *FixedGPool) WaitTerminate()
- type FixedGPoolOption
- type Future
- type FutureTask
- type GPResult
- type Runnable
- type ShrinkWorker
- type Worker
Constants ¶
View Source
const (
SIZE int = 50
)
Variables ¶
View Source
var ( ErrTaskCanceled = errors.New("task has been canceled") ErrPoolShutdown = errors.New("pool has been shutdown") )
Functions ¶
func WithDetectInterval ¶
func WithDynamicTaskQueueCap ¶
func WithDynamicTaskQueueCap(taskQueueCap int) dynamicOption
Optional parameters
func WithMeetCondNum ¶
func WithMeetCondNum(meetCondNum int) dynamicOption
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
atomicBool is a wrapper around uint32 for usage as a boolean value with atomic access.
func NewAtomicBool ¶
func NewAtomicBool(flag bool) *AtomicBool
func (*AtomicBool) IsSet ¶
func (ab *AtomicBool) IsSet() bool
IsSet returns whether the current boolean value is true
func (*AtomicBool) IsTrue ¶
func (ab *AtomicBool) IsTrue() bool
func (*AtomicBool) Set ¶
func (ab *AtomicBool) Set(value bool)
Set sets the value of the bool regardless of the previous value
type DynamicGPool ¶
type DynamicGPool struct {
// task queue
TaskChan chan *FutureTask
// contains filtered or unexported fields
}
nolint: govet
func (*DynamicGPool) Cancel ¶
func (p *DynamicGPool) Cancel() bool
func (*DynamicGPool) CurrentGCount ¶
func (p *DynamicGPool) CurrentGCount() int
func (*DynamicGPool) IsShutdown ¶
func (p *DynamicGPool) IsShutdown() bool
func (*DynamicGPool) Shutdown ¶
func (p *DynamicGPool) Shutdown()
New tasks may be added even after shutdown
func (*DynamicGPool) Submit ¶
func (p *DynamicGPool) Submit(task Callable) (Future, error)
When submitting tasks, blocking may occur
func (*DynamicGPool) TaskQueueCap ¶
func (p *DynamicGPool) TaskQueueCap() int
func (*DynamicGPool) TaskQueueLength ¶
func (p *DynamicGPool) TaskQueueLength() int
func (*DynamicGPool) WaitTerminate ¶
func (p *DynamicGPool) WaitTerminate()
type DynamicGPoolOption ¶
type DynamicGPoolOption struct {
// contains filtered or unexported fields
}
type ExecutorService ¶
type ExecutorService interface {
// no longer accept new tasks
Shutdown()
Submit(task Callable) (Future, error)
IsShutdown() bool
// Wait for all the tasks to be completed
WaitTerminate()
TaskQueueCap() int
TaskQueueLength() int
Cancel() bool
CurrentGCount() int
}
func NewDynamicGPool ¶
func NewDynamicGPool(ctx context.Context, min int, max int, opts ...dynamicOption) ExecutorService
func NewFixedGPool ¶
func NewFixedGPool(ctx context.Context, size int, opts ...option) ExecutorService
func NewSingleGPool ¶
func NewSingleGPool(ctx context.Context, opts ...option) ExecutorService
type FixedGPool ¶
type FixedGPool struct {
Size int
// task queue
TaskChan chan *FutureTask
// contains filtered or unexported fields
}
nolint: govet
func (*FixedGPool) Cancel ¶
func (p *FixedGPool) Cancel() bool
func (*FixedGPool) Consume ¶
func (p *FixedGPool) Consume()
func (*FixedGPool) CurrentGCount ¶
func (p *FixedGPool) CurrentGCount() int
func (*FixedGPool) IsShutdown ¶
func (p *FixedGPool) IsShutdown() bool
func (*FixedGPool) Shutdown ¶
func (p *FixedGPool) Shutdown()
New tasks may be added even after shutdown
func (*FixedGPool) Submit ¶
func (p *FixedGPool) Submit(task Callable) (Future, error)
When submitting tasks, blocking may occur
func (*FixedGPool) TaskQueueCap ¶
func (p *FixedGPool) TaskQueueCap() int
func (*FixedGPool) TaskQueueLength ¶
func (p *FixedGPool) TaskQueueLength() int
func (*FixedGPool) WaitTerminate ¶
func (p *FixedGPool) WaitTerminate()
type FixedGPoolOption ¶
type FixedGPoolOption struct {
// contains filtered or unexported fields
}
type FutureTask ¶
type FutureTask struct {
// contains filtered or unexported fields
}
func NewFutureTask ¶
func NewFutureTask(ctx context.Context, c Callable) *FutureTask
func (*FutureTask) Cancel ¶
func (f *FutureTask) Cancel() bool
func (*FutureTask) Get ¶
func (f *FutureTask) Get() *GPResult
func (*FutureTask) IsCancelled ¶
func (f *FutureTask) IsCancelled() bool
func (*FutureTask) IsDone ¶
func (f *FutureTask) IsDone() bool
type ShrinkWorker ¶
type ShrinkWorker struct {
RunningFlag *AtomicBool
ExitedFlag chan struct{}
ExitChan chan struct{}
// contains filtered or unexported fields
}
func NewShrinkWorker ¶
func NewShrinkWorker(pool *DynamicGPool, interval time.Duration, meetCondNum int) *ShrinkWorker
func (*ShrinkWorker) Start ¶
func (w *ShrinkWorker) Start()
Shrinking rules:
Condition: If the number of workers in a busy state is less than 1/4 of the total number of workers, try to reduce the number of workers by 1/2. Execute meetCondNum consecutive checks, with detectInterval every time, and perform shrinking if the conditions are met each time.
func (*ShrinkWorker) Stop ¶
func (worker *ShrinkWorker) Stop()
type Worker ¶
type Worker struct {
RunningFlag *AtomicBool
ExitedFlag chan struct{}
ExitChan chan struct{}
// contains filtered or unexported fields
}
func NewWorker ¶
func NewWorker(pool *DynamicGPool) *Worker
Source Files
¶
Click to show internal directories.
Click to hide internal directories.