X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=docs%2Fclasses%2FDynamicClusterPool.html;h=5f346787bea4cbc0136c612864f6cfee22e741b3;hb=027063571693f211b35c8851566a063201adb9af;hp=5e8ceb76f84d47a8c1fd4f1d335bec4060a9200f;hpb=248bc34b348a7d8d2b90eecff49d60a3b465da9e;p=poolifier.git diff --git a/docs/classes/DynamicClusterPool.html b/docs/classes/DynamicClusterPool.html index 5e8ceb76..5f346787 100644 --- a/docs/classes/DynamicClusterPool.html +++ b/docs/classes/DynamicClusterPool.html @@ -1,13 +1,15 @@ -
Generated using TypeDoc
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
- -emitter
.Template
of data sent to the worker. This can only be serializable data.
- -Template
of response of execution. This can only be serializable data.
+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
.Author
Christopher Quadflieg
@@ -30,17 +28,21 @@ When the maximum number of workers is reached, an event is emitted. If you wantType Parameters
Data = unknown
Data = unknown
+Type of data sent to the worker. This can only be serializable data.
+Response = unknown
Response = unknown
+Type of response of execution. This can only be serializable data.
+Hierarchy
-- FixedClusterPool<Data, Response>
+
- FixedClusterPool<Data, Response>
- DynamicClusterPool
@@ -54,40 +56,36 @@ When the maximum number of workers is reached, an event is emitted. If you wantemitter?
file Path
-max
-next Message Id
+max
number Of Workers
opts
-promise Map
-tasks
+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,351 +123,341 @@ When the maximum number of workers is reached, an event is emitted. If you want
-
-
Constructs a new poolifier dynamic cluster pool.
Path to an implementation of a
ClusterWorker
file, which can be relative or absolute.
+Optional
opts: ClusterPoolOptions = {}opts: ClusterPoolOptions = {}
Options for this dynamic cluster pool.
Returns DynamicClusterPool<Data, Response>
Properties
-Optional
Readonly
emitterInherit Doc
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:36
Path
-Readonly
filePath to the worker-file.
+Inherited from FixedClusterPool.filePath
-- Defined in src/pools/abstract-pool.ts:79
Readonly
maxInherit Doc
Inherited from FixedClusterPool.max
--- Defined in src/pools/cluster/dynamic.ts:30
Message Id
-Protected
nextId of the next message.
+Maximum number of workers that can be created by this pool.
Inherited from FixedClusterPool.nextMessageId
-- Defined in src/pools/abstract-pool.ts:57
Of Workers
-Readonly
numberNumber of workers that this pool should manage.
+Inherited from FixedClusterPool.numberOfWorkers
-- Defined in src/pools/abstract-pool.ts:78
-Readonly
optsOptions for this fixed cluster pool.
+Inherited from FixedClusterPool.opts
-- Defined in src/pools/cluster/fixed.ts:47
Map
-Protected
promiseThe promise map.
+ Response Map
+Protected
promiseThe execution response promise map.
-
-
+
+
-key
: This is the message Id of each submitted task.value
: An object that contains the worker, the resolve function and the reject function.key
: The message id of each submitted task.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 and resolve/reject the promise based on 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.promiseMap
+Inherited from FixedClusterPool.promiseResponseMap
-- Defined in src/pools/abstract-pool.ts:49
-Readonly
tasksInherit Doc
Inherited from FixedClusterPool.tasks
--- Defined in src/pools/abstract-pool.ts:33
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:64
-Readonly
workersInherit Doc
Inherited from FixedClusterPool.workers
+ Nodes
+Readonly
workerPool worker nodes.
+Inherited from FixedClusterPool.workerNodes
-- Defined in src/pools/abstract-pool.ts:30
Accessors
-busy
-+
+- get busy(): boolean
-
-
-
+
-
-
+Protected
busyInherit Doc
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
numberInherit Doc
Number of tasks running in the pool.
+Returns number
Inherited from FixedClusterPool.numberOfRunningTasks
-- Defined in src/pools/abstract-pool.ts:150
type
-- get type(): PoolType
+- get type(): PoolType
-
-
-
-
+
+
Inherit Doc
Returns PoolType
Pool type.
+If it is
+'dynamic'
, it provides themax
property.Returns PoolType
Overrides FixedClusterPool.type
-- Defined in src/pools/cluster/dynamic.ts:38
Methods
+ Task Execution Hook
+Protected
after+- after
Task Execution Hook(worker: Worker, message: MessageValue<Response, unknown>): void
+-
+
+
+
+
+
Hook executed after the worker task execution. +Can be overridden.
+Parameters
++-
+
+-
+
worker: Worker
+The worker.
+message: MessageValue<Response, unknown>
+The received message.
+Returns void
Inherited from FixedClusterPool.afterTaskExecutionHook
++- Defined in src/pools/abstract-pool.ts:335
Protected
afterInherit Doc
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:89
Worker
+Protected
chooseProtected
before-- choose
Worker(): Worker
+- before
Task Execution Hook(workerNodeKey: number): void
-
-
+
+
+
+
+
+
+- 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
+
Choose a worker for the next task.
-The default implementation uses a round robin algorithm to distribute the load.
+Hook executed before the worker task execution. +Can be overridden.
+Parameters
++-
+
workerNodeKey: number
+The worker node key.
+Returns void
Inherited from FixedClusterPool.beforeTaskExecutionHook
++- Defined in src/pools/abstract-pool.ts:324
Worker Node
+Protected
choose+- choose
Worker Node(): [number, WorkerNode<Worker, Data>]
+-
+
-
-
+
Chooses a worker node for the next task.
+The default uses a round robin algorithm to distribute the load.
-Returns
Worker.
+Returns
[worker node key, worker node].
Returns Worker
Inherited from FixedClusterPool.chooseWorker
+Returns [number, WorkerNode<Worker, Data>]
Inherited from FixedClusterPool.chooseWorkerNode
-- Defined in src/pools/abstract-pool.ts:283
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:337
Protected
createInherit Doc
Returns a newly created worker.
+Returns Worker
Inherited from FixedClusterPool.createWorker
-- Defined in src/pools/cluster/fixed.ts:84
Workers Tasks
-Protected
decrease-- decrease
Workers Tasks(worker: Worker): void
--
-
-
-
-
-
Decrease the number of tasks that the given worker has applied.
-Parameters
---
-
worker: Worker
-Worker whose tasks are decreased.
-Returns void
Inherited from FixedClusterPool.decreaseWorkersTasks
--- Defined in src/pools/abstract-pool.ts:246
destroy
Inherit Doc
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
destroyInherit Doc
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:65
execute
-- execute(data: Data): Promise<Response>
+- execute(data: Data): Promise<Response>
-
-
-
+
-
-
-
+
Inherit Doc
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:196
find Free Worker
--- find
Free Worker(): false | Worker
--
-
-
-
-
Inherit Doc
Returns false | Worker
Inherited from FixedClusterPool.findFreeWorker
--- Defined in src/pools/abstract-pool.ts:185
get Worker Index
--- get
Worker Index(worker: Worker): number
--
-
-
-
-
-
-
Inherit Doc
Parameters
---
-
worker: Worker
Returns number
Inherited from FixedClusterPool.getWorkerIndex
--- Defined in src/pools/abstract-pool.ts:160
get Worker Running Tasks
+find Free Worker Node Key
-- get
Worker Running Tasks(worker: Worker): undefined | number
+- find
Free Worker Node Key(): number
-
-
-
-
-
-
-
Inherit Doc
Parameters
---
-
worker: Worker
Returns undefined | number
Inherited from FixedClusterPool.getWorkerRunningTasks
--- Defined in src/pools/abstract-pool.ts:155
Workers Task
-Protected
increase-- increase
Workers Task(worker: Worker): void
--
-
-
-
-
-
-
-
-
-- Defined in src/pools/abstract-pool.ts:249
+
+ Busy
+- Defined in src/pools/abstract-pool.ts:244
Main
- is
Main(): boolean
-
-
-
+
-
-
+
+
Increase the number of tasks that the given worker has applied.
+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.Parameters
---
-
worker: Worker
-Worker whose tasks are increased.
-Returns void
Inherited from FixedClusterPool.increaseWorkersTask
--- Defined in src/pools/abstract-pool.ts:237
Execute
-Protected
internal-- internal
Execute(worker: Worker, messageId: number): Promise<Response>
--
-
-
-
-
+
Parameters
---
-
--
-
worker: Worker
messageId: number
Returns Promise<Response>
Inherited from FixedClusterPool.internalExecute
+Returns number
Inherited from FixedClusterPool.findFreeWorkerNodeKey
-- Defined in src/pools/abstract-pool.ts:308
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
isInherit Doc
Should return whether the worker is the main worker or not.
+Returns boolean
Inherited from FixedClusterPool.isMain
-- Defined in src/pools/cluster/fixed.ts:60
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
-
-
-
+
-
-
-
Inherit Doc
Registers a listener callback on the given worker.
+Type Parameters
@@ -479,103 +467,96 @@ When the maximum number of workers is reached, an event is emitted. If you want-
-
+
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:76
Worker
-Protected
remove-- remove
Worker(worker: Worker): void
--
-
-
-
-
-
Removes the given worker from the pool.
-Parameters
---
-
worker: Worker
-Worker that will be removed.
-Returns void
Inherited from FixedClusterPool.removeWorker
--- Defined in src/pools/abstract-pool.ts:270
Protected
send-- send
To Worker(worker: Worker, message: MessageValue<Data, unknown>): void
+- send
To Worker(worker: Worker, message: MessageValue<Data, unknown>): void
-
-
-
+
-
-
+
-
-
+
Inherit Doc
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:71
set Worker Choice Strategy
-- set
Worker Choice Strategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"): void
+- set
Worker Choice Strategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"): void
-
-
-
+
-
-
+
Inherit Doc
Sets the worker choice strategy in this pool.
+Parameters
workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"
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:165
Protected
setupInherit Doc
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:53
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
-
-
@@ -583,15 +564,16 @@ When the maximum number of workers is reached, an event is emitted. If you want
-
-
+
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:361
-
+Settings
Settings
Member Visibility
Theme