Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Work ¶
type Work interface { Work() interface{} Return(interface{}) }
Work is an interface to allow the abstraction of Work and Return, enabling generic Workers doing blind Work
type WorkError ¶
type WorkError struct {
Messages string
}
WorkError is sent to Work.Return() if the Work generates a panic
type Worker ¶
type Worker struct { // WorkChan is where the work comes from WorkChan chan Work // QuitChan will get some bools sent to it when the Worker pool needs to shrink QuitChan chan bool // KillChan will close when all the Workers need to exit KillChan chan struct{} // contains filtered or unexported fields }
Worker is a simple primitive construct that listens on WorkChan for Work to do, Might hear a "true" on QuitChan if it is underworked, Might see a closed KillChan if it's time to leave expeditiously
type WorkerPool ¶
type WorkerPool struct { // WorkChan is where the work goes WorkChan chan Work // Stop permanently stops the pool after current work is done. // WorkChan is not closed, to prevent errant reads Stop func() Metrics metrics.Meter // contains filtered or unexported fields }
WorkerPool is an overly-complicated mechanation to allow arbitrary work to be accomplished by an arbitrary worker, which will then return arbitrary results onto an arbitrary channel, while allowing for the evidence-driven growing or shrinking of the pool of available workers based on the fillyness of the WorkChan, which should be buffered and of an appropriate size. If that hasn't turned you off yet, carry on.
func NewWorkerPool ¶
func NewWorkerPool(WorkChan chan Work, initialSize int, autoAdjustInterval time.Duration) *WorkerPool
NewWorkerPool returns a functioning WorkerPool bound to WorkChan, with an initial pool size of initialSize, and if autoAdjustInterval > 0, then it will run the CheckAndAdjust() every that often. NOTE: If your WorkChan is unbuffered (no size during make(), autoAdjust will not run, nor will calling CheckAndAdjust() result in changes. The channel capacity and usage is key to this. It is recommended that the buffer size be around anticipated burst size for work
func (*WorkerPool) AddWorkers ¶
func (p *WorkerPool) AddWorkers(number int64)
AddWorkers adds the specified number of workers
func (*WorkerPool) CheckAndAdjust ¶
func (p *WorkerPool) CheckAndAdjust()
CheckAndAdjust asynchronously triggers the process to possibly resize the pool. While a resize process is running, subsequent processors will silently exit
func (*WorkerPool) RemoveWorkers ¶
func (p *WorkerPool) RemoveWorkers(number int64)
RemoveWorkers removes the specified number of workers, or the number running.
func (*WorkerPool) Size ¶
func (p *WorkerPool) Size() int64
Size returns the eventually-consistent number of workers in the pool
func (*WorkerPool) Work ¶
func (p *WorkerPool) Work() int
Work returns the quantity of Work in the work channel