pkg: istio.io/pkg/pool Index | Files

package pool

import "istio.io/pkg/pool"

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

Index

Package Files

buffer.go goroutine.go intern.go

func GetBuffer Uses

func GetBuffer() *bytes.Buffer

GetBuffer returns a buffer from the buffer pool.

func Intern Uses

func Intern(s string) string

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

func PutBuffer Uses

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.

type GoroutinePool Uses

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

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

func NewGoroutinePool Uses

func NewGoroutinePool(queueDepth int, singleThreaded bool) *GoroutinePool

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

func (*GoroutinePool) AddWorkers Uses

func (gp *GoroutinePool) AddWorkers(numWorkers int)

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

func (*GoroutinePool) Close Uses

func (gp *GoroutinePool) Close() error

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

func (*GoroutinePool) ScheduleWork Uses

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 Uses

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.

Package pool imports 2 packages (graph) and is imported by 36 packages. Updated 2019-08-09. Refresh now. Tools for package owners.