PHP Class Icicle\Concurrent\Worker\DefaultPool

A worker pool is a collection of worker threads that can perform multiple tasks simultaneously. The load on each worker is balanced such that tasks are completed as soon as possible and workers are used efficiently.
Inheritance: implements Pool
显示文件 Open project: icicleio/concurrent Class Usage Examples

Public Methods

Method Description
__construct ( integer $minSize = null, integer $maxSize = null, Icicle\Concurrent\Worker\WorkerFactory $factory = null ) Creates a new worker pool.
enqueue ( Icicle\Concurrent\Worker\Task $task ) : Generator Enqueues a task to be executed by the worker pool.
get ( ) : Worker
getIdleWorkerCount ( ) : integer
getMaxSize ( ) : integer
getMinSize ( ) : integer
getWorkerCount ( ) : integer
isIdle ( ) : boolean Checks if the pool has any idle workers.
isRunning ( ) : boolean Checks if the pool is running.
kill ( ) Kills all workers in the pool and halts the worker pool.
shutdown ( ) : Generator Shuts down the pool and all workers in it.
start ( ) Starts the worker pool execution.

Private Methods

Method Description
createWorker ( ) : Worker Creates a worker and adds them to the pool.
push ( Worker $worker ) Pushes the worker back into the queue.

Method Details

__construct() public method

Creates a new worker pool.
public __construct ( integer $minSize = null, integer $maxSize = null, Icicle\Concurrent\Worker\WorkerFactory $factory = null )
$minSize integer The minimum number of workers the pool should spawn. Defaults to `Pool::DEFAULT_MIN_SIZE`.
$maxSize integer The maximum number of workers the pool should spawn. Defaults to `Pool::DEFAULT_MAX_SIZE`.
$factory Icicle\Concurrent\Worker\WorkerFactory A worker factory to be used to create new workers.

enqueue() public method

Enqueues a task to be executed by the worker pool.
public enqueue ( Icicle\Concurrent\Worker\Task $task ) : Generator
$task Icicle\Concurrent\Worker\Task The task to enqueue.
return Generator

get() public method

public get ( ) : Worker
return Worker

getIdleWorkerCount() public method

public getIdleWorkerCount ( ) : integer
return integer

getMaxSize() public method

public getMaxSize ( ) : integer
return integer

getMinSize() public method

public getMinSize ( ) : integer
return integer

getWorkerCount() public method

public getWorkerCount ( ) : integer
return integer

isIdle() public method

Checks if the pool has any idle workers.
public isIdle ( ) : boolean
return boolean True if the pool has at least one idle worker, otherwise false.

isRunning() public method

Checks if the pool is running.
public isRunning ( ) : boolean
return boolean True if the pool is running, otherwise false.

kill() public method

Kills all workers in the pool and halts the worker pool.
public kill ( )

shutdown() public method

Shuts down the pool and all workers in it.
public shutdown ( ) : Generator
return Generator

start() public method

When the worker pool starts up, the minimum number of workers will be created. This adds some overhead to starting the pool, but allows for greater performance during runtime.
public start ( )