ultrapool

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0, MIT Imports: 6 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task interface{}

Task is the type for a single task.

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) Start

func (wp *WorkerPool) Start()

Start starts the worker pool.

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop stops the worker pool. All tasks that have been added will be processed before shutdown.

Jump to

Keyboard shortcuts

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