pool

package
v0.0.0-...-48a44ca Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pool provides access to a mixer-global pool of buffers, a pool of goroutines, and a string interning table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer returns a buffer from the buffer pool.

func Intern

func Intern(s string) string

Intern returns a sharable version of the string, allowing the parameter's storage to be garbage collected.

func PutBuffer

func PutBuffer(b *bytes.Buffer)

PutBuffer returns a buffer to the buffer pool. You shouldn't reference this buffer after it has been returned to the pool, otherwise bad things will happen.

Types

type GoroutinePool

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

GoroutinePool represents a set of reusable goroutines onto which work can be scheduled.

func NewGoroutinePool

func NewGoroutinePool(queueDepth int, singleThreaded bool) *GoroutinePool

NewGoroutinePool creates a new pool of goroutines to schedule async work.

func (*GoroutinePool) AddWorkers

func (gp *GoroutinePool) AddWorkers(numWorkers int)

AddWorkers introduces more goroutines in the worker pool, increasing potential parallelism.

func (*GoroutinePool) Close

func (gp *GoroutinePool) Close() error

Close waits for all goroutines to terminate (and implements io.Closer).

func (*GoroutinePool) ScheduleWork

func (gp *GoroutinePool) ScheduleWork(fn WorkFunc, param interface{})

ScheduleWork registers the given function to be executed at some point. The given param will be supplied to the function during execution.

By making use of the supplied parameter, it is possible to avoid allocation costs when scheduling the work function. The caller needs to make sure that function fn only depends on external data through the passed in param interface{} and nothing else.

A way to ensure this condition is met, is by passing ScheduleWork a normal named function rather than an inline anonymous function. It's easy for code in an anonymous function to have (or gain) an accidental reference that causes a closure to silently be created.

type WorkFunc

type WorkFunc func(param interface{})

WorkFunc represents a function to invoke from a worker. The parameter is passed on the side to avoid creating closures and allocating.

Jump to

Keyboard shortcuts

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