Documentation
¶
Overview ¶
Package ultrapool implements a blazing fast worker pool with adaptive spawning of new workers and cleanup of idle workers It was modeled after valyala/fasthttp's worker pool which is one of the best worker pools I've seen in the Go world.
Copyright 2019-2022 Moritz Fain Moritz Fain <moritz@fain.io>
Source available at github.com/maurice2k/ultrapool, licensed under the MIT license (see LICENSE file).
Index ¶
- type Task
- type TaskHandlerFunc
- type WorkerPool
- func (wp *WorkerPool) AddTask(task Task) error
- func (wp *WorkerPool) AddTaskForShard(task Task, shardIdx int) error
- func (wp *WorkerPool) GetSpawnedWorkers() uint64
- func (wp *WorkerPool) SetIdleWorkerLifetime(d time.Duration)
- func (wp *WorkerPool) SetNumShards(numShards int)
- func (wp *WorkerPool) Start()
- func (wp *WorkerPool) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TaskHandlerFunc ¶
type TaskHandlerFunc func(task Task)
TaskHandlerFunc is the handler for a task.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool defines the ultrapool.
func NewWorkerPool ¶
func NewWorkerPool(handlerFunc TaskHandlerFunc) *WorkerPool
NewWorkerPool creates a new workerInstance pool with the given task handling function.
func (*WorkerPool) AddTask ¶
func (wp *WorkerPool) AddTask(task Task) error
AddTask adds a new task.
func (*WorkerPool) AddTaskForShard ¶
func (wp *WorkerPool) AddTaskForShard(task Task, shardIdx int) error
AddTaskForShard adds a new task for a specific shard.
func (*WorkerPool) GetSpawnedWorkers ¶
func (wp *WorkerPool) GetSpawnedWorkers() uint64
GetSpawnedWorkers returns the number of currently spawned workers.
func (*WorkerPool) SetIdleWorkerLifetime ¶
func (wp *WorkerPool) SetIdleWorkerLifetime(d time.Duration)
SetIdleWorkerLifetime sets the time after which idling workers are shut down (default is 15 seconds).
func (*WorkerPool) SetNumShards ¶
func (wp *WorkerPool) SetNumShards(numShards int)
SetNumShards sets number of shards (default is GOMAXPROCS shards).
func (*WorkerPool) Stop ¶
func (wp *WorkerPool) Stop()
Stop stops the worker pool. All tasks that have been added will be processed before shutdown.