routine

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

README

boot4go-routine

hight performanece goroutine pool

Documentation

Index

Constants

View Source
const DefaultCleanIntervalTime = time.Second
View Source
const DefaultConcurrency = 256 * 1024

Variables

View Source
var (
	NotValidJobChan = errors.New("not valid job chan now")
	NullJobChan     = errors.New("null job chan")
)
View Source
var (

	// ErrInvalidMaxIdle will be returned when setting a negative number as the periodic duration to purge goroutines.
	ErrInvalidMaxIdle = errors.New("invalid max idle for pool")
)
View Source
var Logger = log4go.LoggerManager.GetLogger("gohutool.boot4go.routine")

Functions

func NewPool

func NewPool[T any](options ...Option) (*workerPool[T], error)

Types

type CyclicDistributionEventChain added in v1.0.8

type CyclicDistributionEventChain[T any] struct {
	// contains filtered or unexported fields
}

func NewCyclicDistributionEventChain added in v1.0.7

func NewCyclicDistributionEventChain[T any](cyclicSize int) *CyclicDistributionEventChain[T]

func (*CyclicDistributionEventChain[T]) BorrowOne added in v1.0.8

func (tp *CyclicDistributionEventChain[T]) BorrowOne() (*EventChannel[T], error)

func (*CyclicDistributionEventChain[T]) ReportMetrics added in v1.0.8

func (*CyclicDistributionEventChain[T]) ReturnOne added in v1.0.8

func (tp *CyclicDistributionEventChain[T]) ReturnOne(jc *EventChannel[T]) error

func (*CyclicDistributionEventChain[T]) Start added in v1.0.8

func (tp *CyclicDistributionEventChain[T]) Start(eventHandler EventHander[T])

func (*CyclicDistributionEventChain[T]) Stop added in v1.0.8

func (tp *CyclicDistributionEventChain[T]) Stop()

type CyclicEventChainReportMetric added in v1.0.8

type CyclicEventChainReportMetric struct {
	PoolSize          int    `json:"pool_size,omitempty"`
	Actives           []bool `json:"actives,omitempty"`
	NumClients        []int  `json:"num_clients,omitempty"`
	CurrentCyclicCode uint64 `json:"current_cyclic_code,omitempty"`
	Started           bool   `json:"started,omitempty"`
}

type EventChannel added in v1.0.7

type EventChannel[T any] struct {
	// contains filtered or unexported fields
}

func (*EventChannel[T]) AddEvent added in v1.0.7

func (jc *EventChannel[T]) AddEvent(one *T)

func (*EventChannel[T]) ID added in v1.0.7

func (jc *EventChannel[T]) ID() int

type EventHander added in v1.0.7

type EventHander[T any] func(job EventChannel[T], t *T) error

type Option

type Option func(opts *Options)

Option represents the optional function.

func WithLogAllErrors

func WithLogAllErrors(logAllErrors bool) Option

WithLogAllErrors indicates whether it should malloc for workers.

func WithMaxIdleWorkerDuration

func WithMaxIdleWorkerDuration(maxIdleWorkerDuration time.Duration) Option

WithMaxIdleWorkerDuration sets up the interval time of cleaning up goroutines.

func WithMaxWorkersCount

func WithMaxWorkersCount(maxWorkersCount uint32) Option

WithMaxWorkersCount sets up the maximum number of goroutines that are blocked when it reaches the capacity of pool.

func WithOptions

func WithOptions(options Options) Option

WithOptions accepts the whole Options config.

type Options

type Options struct {
	// MaxIdleWorkerDuration is a period for the scavenger goroutine to clean up those expired workers,
	// the scavenger scans all workers every `MaxIdleWorkerDuration` and clean up those workers that haven't been
	// used for more than `ExpiryDuration`.
	MaxIdleWorkerDuration time.Duration

	// Max number of goroutine blocking on pool.Submit.
	// 0 (default value) means no such limit.
	MaxWorkersCount uint32

	LogAllErrors bool
}

Options contains all options which will be applied when instantiating an ants pool.

func LoadOptions

func LoadOptions(options ...Option) *Options

type WorkPoolMetrics added in v1.0.7

type WorkPoolMetrics struct {
	MaxWorkersCount       uint32        `json:"max_workers_count,omitempty"`
	LogAllErrors          bool          `json:"log_all_errors,omitempty"`
	MaxIdleWorkerDuration time.Duration `json:"max_idle_worker_duration,omitempty"`

	Ready      int    `json:"ready,omitempty"`
	GetTimes   uint64 `json:"get_times,omitempty"`
	PurgeTimes uint64 `json:"purge_times,omitempty"`
	// contains filtered or unexported fields
}

type WorkerFunc

type WorkerFunc func() error

Jump to

Keyboard shortcuts

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