X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=docs%2Fclasses%2FDynamicClusterPool.html;h=3e421373a21db07a80264558cd01a3a152be85b9;hb=b45edd35eec0fb1d5fd8fa979ff00f17f4e3c24e;hp=09bddee613cddcf688eac0525f44ba4128bb51e8;hpb=79458fb6e10234a237757111e710f8f71424fa06;p=poolifier.git diff --git a/docs/classes/DynamicClusterPool.html b/docs/classes/DynamicClusterPool.html index 09bddee6..3e421373 100644 --- a/docs/classes/DynamicClusterPool.html +++ b/docs/classes/DynamicClusterPool.html @@ -1,4 +1,4 @@ -
A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
This cluster pool creates new workers when the others are busy, up to the maximum number of workers. -When the maximum number of workers is reached, an event is emitted. If you want to listen to this event, use the pool's
+When the maximum number of workers is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool'semitter
.emitter
.Author
Christopher Quadflieg
@@ -33,16 +33,16 @@ When the maximum number of workers is reached, an event is emitted. If you wantResponse = unknown
-Type of response of execution. This can only be serializable data.
+Type of execution response. This can only be serializable data.
Hierarchy
-- FixedClusterPool<Data, Response>
+
- FixedClusterPool<Data, Response>
- DynamicClusterPool
@@ -56,35 +56,36 @@ When the maximum number of workers is reached, an event is emitted. If you wantemitter?
file Path
-max
+max
number Of Workers
opts
promise Response Map
worker Choice Strategy Context
-workers
+worker Nodes
Properties
Accessors
-Methods
-constructor
-- new
Dynamic Cluster Pool<Data, Response>(min: number, max: number, filePath: string, opts?: ClusterPoolOptions): DynamicClusterPool<Data, Response>
+- new
Dynamic Cluster Pool<Data, Response>(min: number, max: number, filePath: string, opts?: ClusterPoolOptions): DynamicClusterPool<Data, Response>
-
@@ -125,20 +126,25 @@ When the maximum number of workers is reached, an event is emitted. If you want
Constructs a new poolifier dynamic cluster pool.
opts: ClusterPoolOptions = {}
Options for this dynamic cluster pool.
Returns DynamicClusterPool<Data, Response>
Properties
Optional
Readonly
emitter{@inheritDoc}
+Emitter on which events can be listened to.
+Events that can currently be listened to:
++
+
+
'full'
: Emitted when the pool is dynamic and full.'busy'
: Emitted when the pool is busy.Inherited from FixedClusterPool.emitter
-- Defined in src/pools/abstract-pool.ts:32
Readonly
fileInherited from FixedClusterPool.filePath
-- Defined in src/pools/abstract-pool.ts:67
+Protected
Readonly
maxReadonly
maxMaximum number of workers that can be created by this pool.
-- Defined in src/pools/cluster/dynamic.ts:30
Readonly
numberInherited from FixedClusterPool.numberOfWorkers
-- Defined in src/pools/abstract-pool.ts:66
Readonly
optsInherited from FixedClusterPool.opts
-- Defined in src/pools/cluster/fixed.ts:53
Response Map
-Protected
promiseThe promise response map.
+The execution response promise map.
key
: The message id of each submitted task.value
: An object that contains the worker, the promise resolve and reject callbacks.value
: An object that contains the worker, the execution response promise resolve and reject callbacks.When we receive a message from the worker we get a map entry with the promise resolve/reject bound to the message.
+When we receive a message from the worker, we get a map entry with the promise resolve/reject bound to the message id.
Inherited from FixedClusterPool.promiseResponseMap
-- Defined in src/pools/abstract-pool.ts:42
Choice Strategy Context
-Protected
workerWorker choice strategy instance implementing the worker choice algorithm.
-Default to a strategy implementing a round robin algorithm.
+Worker choice strategy context referencing a worker choice algorithm implementation.
+Default to a round robin algorithm.
Inherited from FixedClusterPool.workerChoiceStrategyContext
-- Defined in src/pools/abstract-pool.ts:52
-Readonly
workers{@inheritDoc}
+ Nodes
+Readonly
workerPool worker nodes.
Inherited from FixedClusterPool.workers
+Inherited from FixedClusterPool.workerNodes
-- Defined in src/pools/abstract-pool.ts:29
Accessors
-busy
-+
+- get busy(): boolean
-
-
-
-
+
+
+
+
+
+- get numberOfRunningTasks(): number
-
-
+- Defined in src/pools/abstract-pool.ts:176
+Protected
busy{@inheritDoc}
+Whether the pool is busy or not.
+The pool busyness boolean status.
Returns boolean
Overrides FixedClusterPool.busy
-- Defined in src/pools/cluster/dynamic.ts:43
number Of Running Tasks
-+- Defined in src/pools/cluster/dynamic.ts:48
+Protected
full+- get full(): boolean
+-
+
+
+
Whether the pool is full or not.
+The pool filling boolean status.
+Returns boolean
Overrides FixedClusterPool.full
++- Defined in src/pools/cluster/dynamic.ts:43
Of Queued Tasks
+Private
number+- get numberOfQueuedTasks(): number
+-
+
+
+
Number of tasks queued in the pool.
+Returns number
Inherited from FixedClusterPool.numberOfQueuedTasks
++- Defined in src/pools/abstract-pool.ts:186
Of Running Tasks
+Private
number{@inheritDoc}
+Number of tasks running in the pool.
Returns number
Inherited from FixedClusterPool.numberOfRunningTasks
-- Defined in src/pools/abstract-pool.ts:141
type
-- get type(): PoolType
+- get type(): PoolType
-
-
-
+
+- Defined in src/pools/cluster/dynamic.ts:38
-
+ Task Execution Hook
{@inheritDoc}
+Pool type.
+If it is
'dynamic'
, it provides themax
property.Returns PoolType
Returns PoolType
Overrides FixedClusterPool.type
-- Defined in src/pools/cluster/dynamic.ts:38
Methods
- Promise Response Hook
+Protected
afterProtected
after-- after
Promise Response Hook(worker: Worker, message: MessageValue<Response, unknown>): void
+- after
Task Execution Hook(worker: Worker, message: MessageValue<Response, unknown>): void
-
-
@@ -253,166 +284,179 @@ Can be overridden.
-
-
-
+- Defined in src/pools/abstract-pool.ts:335
Worker Setup
- after
Worker Setup(worker: Worker): void
-
-
-
-
+
-
-- Defined in src/pools/cluster/fixed.ts:93
+
+ Task Execution Hook
Hook executed after the worker task promise resolution. +
Hook executed after the worker task execution. Can be overridden.
The worker.
message: MessageValue<Response, unknown>
+message: MessageValue<Response, unknown>
The received message.
Returns void
Inherited from FixedClusterPool.afterPromiseResponseHook
+Inherited from FixedClusterPool.afterTaskExecutionHook
-- Defined in src/pools/abstract-pool.ts:253
Protected
after{@inheritDoc}
+Function that can be hooked up when a worker has been newly created and moved to the pool worker nodes.
+Can be used to update the
maxListeners
or binding themain-worker
<->worker
connection if not bind by default.Parameters
worker: Worker
worker: Worker
+The newly created worker.
+Returns void
Inherited from FixedClusterPool.afterWorkerSetup
-- Defined in src/pools/cluster/fixed.ts:93
Promise Response Hook
+Protected
beforeProtected
before-- before
Promise Response Hook(workerKey: number): void
+- before
Task Execution Hook(workerNodeKey: number): void
-
-
-
-
-
-
-- Defined in src/pools/abstract-pool.ts:324
+
+ Worker Node
Hook executed before the worker task promise resolution. +
Hook executed before the worker task execution. Can be overridden.
Parameters
workerKey: number
-The worker key.
+workerNodeKey: number
+The worker node key.
Returns void
Inherited from FixedClusterPool.beforePromiseResponseHook
+Inherited from FixedClusterPool.beforeTaskExecutionHook
-- Defined in src/pools/abstract-pool.ts:242
Worker
+Protected
chooseProtected
choose-- choose
Worker(): [number, Worker]
+- choose
Worker Node(): [number, WorkerNode<Worker, Data>]
-
-
-
-
+
+- Defined in src/pools/abstract-pool.ts:368
And Setup Worker
- create
And Setup Worker(): Worker
-
-
+- Defined in src/pools/abstract-pool.ts:430
Worker
- create
Worker(): Worker
-
-
+- Defined in src/pools/cluster/fixed.ts:88
- destroy(): Promise<void>
-
-
-
-
+
+- destroy
Worker(worker: Worker): void
-
-
-
-
+
+- Defined in src/pools/cluster/fixed.ts:69
-
-- Defined in src/pools/abstract-pool.ts:256
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file
Chooses a worker for the next task.
-The default implementation uses a round robin algorithm to distribute the load.
+Chooses a worker node for the next task.
+The default uses a round robin algorithm to distribute the load.
-Returns
[worker key, worker].
+Returns
[worker node key, worker node].
Returns [number, Worker]
Inherited from FixedClusterPool.chooseWorker
+Returns [number, WorkerNode<Worker, Data>]
Inherited from FixedClusterPool.chooseWorkerNode
-- Defined in src/pools/abstract-pool.ts:290
Protected
createCreates a new worker for this pool and sets it up completely.
+Creates a new worker and sets it up completely in the pool worker nodes.
Returns
New, completely set up worker.
Returns Worker
Inherited from FixedClusterPool.createAndSetupWorker
-- Defined in src/pools/abstract-pool.ts:335
Protected
create{@inheritDoc}
+Returns a newly created worker.
Returns Worker
Inherited from FixedClusterPool.createWorker
-- Defined in src/pools/cluster/fixed.ts:88
destroy
{@inheritDoc}
+Shutdowns every current worker in this pool.
Returns Promise<void>
Inherited from FixedClusterPool.destroy
-- Defined in src/pools/abstract-pool.ts:208
destroy Worker
-+- Defined in src/pools/abstract-pool.ts:287
Worker
+Protected
destroy{@inheritDoc}
+Shutdowns the given worker.
Parameters
worker: Worker
worker: Worker
+A worker within
+workerNodes
.Returns void
Inherited from FixedClusterPool.destroyWorker
-- Defined in src/pools/cluster/fixed.ts:69
execute
-- execute(data: Data): Promise<Response>
+- execute(data: Data): Promise<Response>
-
-
-
-
-
+
+
{@inheritDoc}
+Performs the task specified in the constructor with the data parameter.
+ +Returns
Promise that will be resolved when the task is successfully completed.
Parameters
data: Data
Returns Promise<Response>
data: Data
+The input for the specified task. This can only be serializable data.
+Returns Promise<Response>
Inherited from FixedClusterPool.execute
-- Defined in src/pools/abstract-pool.ts:193
find Free Worker Key
+find Free Worker Node Key
-- find
Free Worker Key(): number | false
+- find
Free Worker Node Key(): number
-
-
-
-
+
-
-- Defined in src/pools/abstract-pool.ts:249
+
+ Busy
+- Defined in src/pools/abstract-pool.ts:244
Main
- is
Main(): boolean
-
-
-
-
+
+
-
-
+- Defined in src/pools/cluster/fixed.ts:80
To Worker
+- Defined in src/pools/cluster/fixed.ts:75
- set
Worker Choice Strategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"): void
-
-
-
-
+
+- Defined in src/pools/abstract-pool.ts:209
Hook
- setup
Hook(): void
-
-
+- Defined in src/pools/cluster/fixed.ts:59
Listener
-
+- Defined in src/pools/abstract-pool.ts:453
+
+
-
-
-
+- constructor
+- emitter
+- file
Path
+- max
+- number
Of Workers
+- opts
+- promise
Response Map
+- worker
Choice Strategy Context
+- worker
Nodes
+- busy
+- full
+- number
Of Queued Tasks
+- number
Of Running Tasks
+- type
+- after
Task Execution Hook
+- after
Worker Setup
+- before
Task Execution Hook
+- choose
Worker Node
+- create
And Setup Worker
+- create
Worker
+- destroy
+- destroy
Worker
+- execute
+- find
Free Worker Node Key
+- internal
Busy
+- is
Main
+- register
Worker Message Listener
+- send
To Worker
+- set
Worker Choice Strategy
+- setup
Hook
+- worker
Listener
+
+
{@inheritDoc}
+Finds a free worker node key based on the number of tasks the worker has applied.
+If a worker is found with
+0
running tasks, it is detected as free and its worker node key is returned.If no free worker is found,
+ +-1
is returned.Returns
A worker node key if there is one,
-1
otherwise.Returns number | false
Inherited from FixedClusterPool.findFreeWorkerKey
+Returns number
Inherited from FixedClusterPool.findFreeWorkerNodeKey
-- Defined in src/pools/abstract-pool.ts:185
Get Busy Status
+Protected
internalProtected
internal-- internal
Get Busy Status(): boolean
+- internal
Busy(): boolean
-
-
Returns boolean
Inherited from FixedClusterPool.internalGetBusyStatus
+Inherited from FixedClusterPool.internalBusy
-- Defined in src/pools/abstract-pool.ts:177
Protected
is{@inheritDoc}
+Should return whether the worker is the main worker or not.
Returns boolean
Inherited from FixedClusterPool.isMain
-- Defined in src/pools/cluster/fixed.ts:64
register Worker Message Listener
--- register
Worker Message Listener<Message>(worker: Worker, listener: ((message: MessageValue<Message, unknown>) => void)): void
+- Defined in src/pools/cluster/fixed.ts:64
Worker Message Listener
+Protected
register+- register
Worker Message Listener<Message>(worker: Worker, listener: ((message: MessageValue<Message, unknown>) => void)): void
-
-
-
-
+
-
-
-
{@inheritDoc}
+Registers a listener callback on the given worker.
Type Parameters
@@ -423,103 +467,96 @@ Can be overridden.Parameters
worker: Worker
worker: Worker
+The worker which should register a listener.
+listener: ((message: MessageValue<Message, unknown>) => void)
+listener: ((message: MessageValue<Message, unknown>) => void)
+The message listener callback.
+-- (message: MessageValue<Message, unknown>): void
+- (message: MessageValue<Message, unknown>): void
-
-
-
+
Parameters
message: MessageValue<Message, unknown>
message: MessageValue<Message, unknown>
Returns void
Returns void
Inherited from FixedClusterPool.registerWorkerMessageListener
-- Defined in src/pools/cluster/fixed.ts:80
Worker
-Protected
remove-- remove
Worker(worker: Worker): void
--
-
-
-
-
-
Removes the given worker from the pool.
-Parameters
---
-
worker: Worker
-The worker that will be removed.
-Returns void
Inherited from FixedClusterPool.removeWorker
--- Defined in src/pools/abstract-pool.ts:277
Protected
send-- send
To Worker(worker: Worker, message: MessageValue<Data, unknown>): void
+- send
To Worker(worker: Worker, message: MessageValue<Data, unknown>): void
-
-
-
-
+
-
-
+
{@inheritDoc}
+Sends a message to the given worker.
Parameters
worker: Worker
worker: Worker
+The worker which should receive the message.
+message: MessageValue<Data, unknown>
message: MessageValue<Data, unknown>
+The message.
+Returns void
Inherited from FixedClusterPool.sendToWorker
-- Defined in src/pools/cluster/fixed.ts:75
set Worker Choice Strategy
{@inheritDoc}
+Sets the worker choice strategy in this pool.
Parameters
workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"
workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"
+The worker choice strategy.
+Returns void
Inherited from FixedClusterPool.setWorkerChoiceStrategy
-- Defined in src/pools/abstract-pool.ts:156
Protected
setup{@inheritDoc}
+Setup hook to execute code before worker node are created in the abstract constructor. +Can be overridden
Returns void
Inherited from FixedClusterPool.setupHook
-- Defined in src/pools/cluster/fixed.ts:59
Protected
worker-- worker
Listener(): ((message: MessageValue<Response, unknown>) => void)
+- worker
Listener(): ((message: MessageValue<Response, unknown>) => void)
-
-
--
This function is the listener registered for each worker.
+This function is the listener registered for each worker message.
Returns
The listener function to execute when a message is received from a worker.
Returns ((message: MessageValue<Response, unknown>) => void)
+Returns ((message: MessageValue<Response, unknown>) => void)
-- (message: MessageValue<Response, unknown>): void
+- (message: MessageValue<Response, unknown>): void
-
-
@@ -527,15 +564,16 @@ Can be overridden.
-
-
+
This function is the listener registered for each worker.
+This function is the listener registered for each worker message.
Returns
The listener function to execute when a message is received from a worker.
Parameters
message: MessageValue<Response, unknown>
message: MessageValue<Response, unknown>
Returns void
Inherited from FixedClusterPool.workerListener
-- Defined in src/pools/abstract-pool.ts:364
-
+Settings
Settings
Member Visibility
Theme
Generated using TypeDoc