Documentation ¶
Index ¶
Constants ¶
const ( // DefaultReadBufferGCInterval is the default interval that a Read will // perform a sweep to see which expired buffer.Reads can be released to // the runtime. DefaultReadBufferGCInterval = 15 * time.Second // DefaultReadBufferExpiryInterval is the default, minimum interval that // must elapse before a Read will release a buffer.Read. The maximum // time before the buffer can be released is equal to the expiry // interval plus the gc interval. DefaultReadBufferExpiryInterval = 30 * time.Second )
const ( // DefaultWriteBufferGCInterval is the default interval that a Write // will perform a sweep to see which expired buffer.Writes can be // released to the runtime. DefaultWriteBufferGCInterval = 15 * time.Second // DefaultWriteBufferExpiryInterval is the default, minimum interval // that must elapse before a Write will release a buffer.Write. The // maximum time before the buffer can be released is equal to the expiry // interval plus the gc interval. DefaultWriteBufferExpiryInterval = 30 * time.Second )
const DefaultWorkerTimeout = 90 * time.Second
DefaultWorkerTimeout is the default duration after which a worker goroutine will exit to free up resources after having received no newly submitted tasks.
Variables ¶
var ErrWorkerPoolExiting = errors.New("worker pool exiting")
ErrWorkerPoolExiting signals that a shutdown of the Worker has been requested.
Functions ¶
This section is empty.
Types ¶
type Read ¶
type Read struct {
// contains filtered or unexported fields
}
Read is a worker pool specifically designed for sharing access to buffer.Read objects amongst a set of worker goroutines. This enables an application to limit the total number of buffer.Read objects allocated at any given time.
type ReadBuffer ¶
type ReadBuffer struct {
// contains filtered or unexported fields
}
ReadBuffer is a pool of buffer.Read items, that dynamically allocates and reclaims buffers in response to load.
func NewReadBuffer ¶
func NewReadBuffer(gcInterval, expiryInterval time.Duration) *ReadBuffer
NewReadBuffer returns a freshly instantiated ReadBuffer, using the given gcInterval and expiryInterval.
func (*ReadBuffer) Return ¶
func (p *ReadBuffer) Return(buf *buffer.Read)
Return returns the buffer.Read to the pool, so that it can be cycled or released.
func (*ReadBuffer) Take ¶
func (p *ReadBuffer) Take() *buffer.Read
Take returns a fresh buffer.Read to the caller.
type Recycle ¶
type Recycle struct {
// contains filtered or unexported fields
}
Recycle is a generic queue for recycling objects implementing the Recycler interface. It is backed by an underlying queue.GCQueue, and invokes the Recycle method on returned objects before returning them to the queue.
func NewRecycle ¶
func NewRecycle(newItem func() interface{}, returnQueueSize int, gcInterval, expiryInterval time.Duration) *Recycle
NewRecycle initializes a fresh Recycle instance.
type Recycler ¶
type Recycler interface {
// Recycle resets the object to its default state.
Recycle()
}
Recycler is an interface that allows an object to be reclaimed without needing to be returned to the runtime.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker maintains a pool of goroutines that process submitted function closures, and enable more efficient reuse of expensive state.
func NewWorker ¶
func NewWorker(cfg *WorkerConfig) *Worker
NewWorker initializes a new Worker pool using the provided WorkerConfig.
type WorkerConfig ¶
type WorkerConfig struct { // NewWorkerState allocates a new state for a worker goroutine. // This method is called each time a new worker goroutine is // spawned by the pool. NewWorkerState func() WorkerState // NumWorkers is the maximum number of workers the Worker pool // will permit to be allocated. Once the maximum number is // reached, any newly submitted tasks are forced to be processed // by existing worker goroutines. NumWorkers int // WorkerTimeout is the duration after which a worker goroutine // will exit after having received no newly submitted tasks. WorkerTimeout time.Duration }
WorkerConfig parametrizes the behavior of a Worker pool.
type WorkerState ¶
type WorkerState interface { // Reset clears any internal state that may have been dirtied in // processing a prior task. Reset() // Cleanup releases any shared state before a worker goroutine // exits. Cleanup() }
WorkerState is an interface used by the Worker to abstract the lifecycle of internal state used by a worker goroutine.
type Write ¶
type Write struct {
// contains filtered or unexported fields
}
Write is a worker pool specifically designed for sharing access to buffer.Write objects amongst a set of worker goroutines. This enables an application to limit the total number of buffer.Write objects allocated at any given time.
type WriteBuffer ¶
type WriteBuffer struct {
// contains filtered or unexported fields
}
WriteBuffer is a pool of recycled buffer.Write items, that dynamically allocates and reclaims buffers in response to load.
func NewWriteBuffer ¶
func NewWriteBuffer(gcInterval, expiryInterval time.Duration) *WriteBuffer
NewWriteBuffer returns a freshly instantiated WriteBuffer, using the given gcInterval and expiryIntervals.
func (*WriteBuffer) Return ¶
func (p *WriteBuffer) Return(buf *buffer.Write)
Return returns the buffer.Write to the pool, so that it can be recycled or released.
func (*WriteBuffer) Take ¶
func (p *WriteBuffer) Take() *buffer.Write
Take returns a fresh buffer.Write to the caller.