X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FDynamicThreadPool.html;h=f6495e279a204f5ba19c7dc378617f980e5bffea;hb=812ad701baefad24cad2df8f9a60bf4d581d8697;hp=b7fba0c61ae31aaa5d6a377084a30609ae4b1385;hpb=248bc34b348a7d8d2b90eecff49d60a3b465da9e;p=poolifier.git diff --git a/docs/classes/DynamicThreadPool.html b/docs/classes/DynamicThreadPool.html index b7fba0c6..f6495e27 100644 --- a/docs/classes/DynamicThreadPool.html +++ b/docs/classes/DynamicThreadPool.html @@ -1,13 +1,15 @@ -
Inherited from FixedThreadPool.setWorkerChoiceStrategy
Protected
setupSetup hook that can be overridden by a Poolifier pool implementation -to run code before workers are created in the abstract constructor.
+Setup hook to execute code before worker node are created in the abstract constructor. +Can be overridden
Inherited from FixedThreadPool.setupHook
Protected
workerThis function is the listener registered for each worker.
+This function is the listener registered for each worker message.
The listener function to execute when a message is received from a worker.
This function is the listener registered for each worker.
+This function is the listener registered for each worker message.
The listener function to execute when a message is received from a worker.
Inherited from FixedThreadPool.workerListener
Generated using TypeDoc
A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
This thread pool creates new threads when the others are busy, up to the maximum number of threads. -When the maximum number of threads 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 threads is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool'semitter
.Author
Alessandro Pio Ardizio
@@ -30,17 +28,21 @@ When the maximum number of threads 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
-- FixedThreadPool<Data, Response>
+
- FixedThreadPool<Data, Response>
- DynamicThreadPool
@@ -54,40 +56,36 @@ When the maximum number of threads 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 Thread Pool<Data, Response>(min: number, max: number, filePath: string, opts??: PoolOptions<ThreadWorkerWithMessageChannel>): DynamicThreadPool<Data, Response>
+- new
Dynamic Thread Pool<Data, Response>(min: number, max: number, filePath: string, opts?: PoolOptions<ThreadWorkerWithMessageChannel>): DynamicThreadPool<Data, Response>
-
@@ -125,95 +123,84 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
Constructs a new poolifier dynamic thread pool.
Path to an implementation of a
ThreadWorker
file, which can be relative or absolute.
+Optional
opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
Options for this dynamic thread pool.
Returns DynamicThreadPool<Data, Response>
Properties
-Optional
Readonly
emitterInherit Doc
Inherited from FixedThreadPool.emitter
-- Defined in src/pools/abstract-pool.ts:36
Path
-Readonly
filePath to the worker-file.
+Inherited from FixedThreadPool.filePath
-- Defined in src/pools/abstract-pool.ts:79
Readonly
maxInherit Doc
Inherited from FixedThreadPool.max
--- Defined in src/pools/thread/dynamic.ts:31
Message Id
-Protected
nextId of the next message.
+Maximum number of threads that can be created by this pool.
Inherited from FixedThreadPool.nextMessageId
-- Defined in src/pools/abstract-pool.ts:57
Of Workers
-Readonly
numberNumber of workers that this pool should manage.
+Inherited from FixedThreadPool.numberOfWorkers
-- Defined in src/pools/abstract-pool.ts:78
-Readonly
optsOptions for the pool.
+Inherited from FixedThreadPool.opts
-- Defined in src/pools/abstract-pool.ts:80
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 FixedThreadPool.promiseMap
--- Defined in src/pools/abstract-pool.ts:49
-Readonly
tasksInherit Doc
Inherited from FixedThreadPool.tasks
+Inherited from FixedThreadPool.promiseResponseMap
-- 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 FixedThreadPool.workerChoiceStrategyContext
-- Defined in src/pools/abstract-pool.ts:64
-Readonly
workers Nodes
+Readonly
workerInherit Doc
Inherited from FixedThreadPool.workers
+Inherited from FixedThreadPool.workerNodes
-- Defined in src/pools/abstract-pool.ts:30
Accessors
Returns boolean
Overrides FixedThreadPool.busy
-- Defined in src/pools/thread/dynamic.ts:44
number Of Running Tasks
--- get numberOfRunningTasks(): number
+- Defined in src/pools/thread/dynamic.ts:49
full
++- get full(): boolean
-
+
+
Inherit Doc
Returns boolean
Overrides FixedThreadPool.full
++- Defined in src/pools/thread/dynamic.ts:44
Of Queued Tasks
+Private
number+- get numberOfQueuedTasks(): number
+-
+
+
+
Number of tasks queued in the pool.
+Returns number
Inherited from FixedThreadPool.numberOfQueuedTasks
++- Defined in src/pools/abstract-pool.ts:182
Of Running Tasks
+Private
number+- get numberOfRunningTasks(): number
+-
+
Number of tasks running in the pool.
+Returns number
Inherited from FixedThreadPool.numberOfRunningTasks
-- Defined in src/pools/abstract-pool.ts:150
type
@@ -248,9 +257,32 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns PoolType
Overrides FixedThreadPool.type
-- Defined in src/pools/thread/dynamic.ts:39
Methods
+ Task Execution Hook
+Protected
after+- after
Task Execution Hook(worker: ThreadWorkerWithMessageChannel, message: MessageValue<Response, unknown>): void
+-
+
+
+
+
+
Hook executed after the worker task execution. +Can be overridden.
+Parameters
++-
+
+-
+
worker: ThreadWorkerWithMessageChannel
+The worker.
+message: MessageValue<Response, unknown>
+The received message.
+Returns void
Inherited from FixedThreadPool.afterTaskExecutionHook
++- Defined in src/pools/abstract-pool.ts:323
Protected
after@@ -266,34 +298,53 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns void
Inherited from FixedThreadPool.afterWorkerSetup
-- Defined in src/pools/thread/fixed.ts:80
Worker
+Protected
choose Task Execution Hook
+Protected
before+- before
Task Execution Hook(workerNodeKey: number): void
+-
+
+
+
+
+
Hook executed before the worker task execution. +Can be overridden.
+Parameters
++-
+
workerNodeKey: number
+The worker node key.
+Returns void
Inherited from FixedThreadPool.beforeTaskExecutionHook
++- Defined in src/pools/abstract-pool.ts:312
Protected
choose-- choose
Worker(): ThreadWorkerWithMessageChannel
+- choose
Worker Node(): [number, WorkerNode<ThreadWorkerWithMessageChannel, Data>]
-
-
-
-
+
+- Defined in src/pools/abstract-pool.ts:356
And Setup Worker
- create
And Setup Worker(): ThreadWorkerWithMessageChannel
-
-
+- Defined in src/pools/abstract-pool.ts:418
Worker
-
-
+- Defined in src/pools/thread/fixed.ts:78
+- Defined in src/pools/abstract-pool.ts:275
+- Defined in src/pools/thread/fixed.ts:54
-
+
+
Choose 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.
+Returns
[worker node key, worker node].
Returns ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.chooseWorker
+Returns [number, WorkerNode<ThreadWorkerWithMessageChannel, Data>]
Inherited from FixedThreadPool.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 ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.createAndSetupWorker
-- Defined in src/pools/abstract-pool.ts:337
Protected
create@@ -304,25 +355,7 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.createWorker
-- Defined in src/pools/thread/fixed.ts:73
Workers Tasks
-Protected
decrease-- decrease
Workers Tasks(worker: ThreadWorkerWithMessageChannel): void
--
-
-
-
-
-
Decrease the number of tasks that the given worker has applied.
-Parameters
---
-
worker: ThreadWorkerWithMessageChannel
-Worker whose tasks are decreased.
-Returns void
Inherited from FixedThreadPool.decreaseWorkersTasks
--- Defined in src/pools/abstract-pool.ts:246
destroy
@@ -333,7 +366,7 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns Promise<void>
Inherited from FixedThreadPool.destroy
-- Defined in src/pools/abstract-pool.ts:208
destroy Worker
@@ -349,11 +382,11 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns Promise<void>
Inherited from FixedThreadPool.destroyWorker
-- Defined in src/pools/thread/fixed.ts:49
execute
-- execute(data: Data): Promise<Response>
+- execute(data: Data): Promise<Response>
-
@@ -361,97 +394,31 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
Inherit Doc
Parameters
data: Data
Returns Promise<Response>
data: Data
Returns Promise<Response>
Inherited from FixedThreadPool.execute
-- Defined in src/pools/abstract-pool.ts:196
find Free Worker
--- find
Free Worker(): false | ThreadWorkerWithMessageChannel
--
-
-
-
-
Inherit Doc
Returns false | ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.findFreeWorker
--- Defined in src/pools/abstract-pool.ts:185
get Worker Index
+find Free Worker Node Key
-- get
Worker Index(worker: ThreadWorkerWithMessageChannel): number
+- find
Free Worker Node Key(): number
-
-
-
-
Inherit Doc
Parameters
---
-
worker: ThreadWorkerWithMessageChannel
Returns number
Inherited from FixedThreadPool.getWorkerIndex
+Inherited from FixedThreadPool.findFreeWorkerNodeKey
-- Defined in src/pools/abstract-pool.ts:160
get Worker Running Tasks
--- get
Worker Running Tasks(worker: ThreadWorkerWithMessageChannel): undefined | number
--
-
-
-
-
-
-
Inherit Doc
Parameters
---
-
worker: ThreadWorkerWithMessageChannel
Returns undefined | number
Inherited from FixedThreadPool.getWorkerRunningTasks
--- Defined in src/pools/abstract-pool.ts:155
Workers Task
+Protected
increaseProtected
internal-- increase
Workers Task(worker: ThreadWorkerWithMessageChannel): void
--
-
-
-
-
-
Increase the number of tasks that the given worker has applied.
-Parameters
---
-
worker: ThreadWorkerWithMessageChannel
-Worker whose tasks are increased.
-Returns void
Inherited from FixedThreadPool.increaseWorkersTask
--- Defined in src/pools/abstract-pool.ts:237
Execute
-Protected
internal-- internal
Execute(worker: ThreadWorkerWithMessageChannel, messageId: number): Promise<Response>
--
-
-
-
-
Parameters
---
-
--
-
worker: ThreadWorkerWithMessageChannel
messageId: number
Returns Promise<Response>
Inherited from FixedThreadPool.internalExecute
--- Defined in src/pools/abstract-pool.ts:308
Get Busy Status
-Protected
internal-- internal
Get Busy Status(): boolean
+- internal
Busy(): boolean
-
-
Returns boolean
Inherited from FixedThreadPool.internalGetBusyStatus
+Inherited from FixedThreadPool.internalBusy
-- Defined in src/pools/abstract-pool.ts:177
Protected
is@@ -462,11 +429,11 @@ When the maximum number of threads is reached, an event is emitted. If you want
Returns boolean
Inherited from FixedThreadPool.isMain
-- Defined in src/pools/thread/fixed.ts:44
register Worker Message Listener
-- register
Worker Message Listener<Message>(messageChannel: ThreadWorkerWithMessageChannel, listener: ((message: MessageValue<Message, unknown>) => void)): void
+- register
Worker Message Listener<Message>(messageChannel: ThreadWorkerWithMessageChannel, listener: ((message: MessageValue<Message, unknown>) => void)): void
-
@@ -481,44 +448,26 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
-
-
Inherit Doc
messageChannel: ThreadWorkerWithMessageChannel
listener: ((message: MessageValue<Message, unknown>) => void)
+listener: ((message: MessageValue<Message, unknown>) => void)
-- (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 FixedThreadPool.registerWorkerMessageListener
-- Defined in src/pools/thread/fixed.ts:65
Worker
-Protected
remove-- remove
Worker(worker: ThreadWorkerWithMessageChannel): void
--
-
-
-
-
-
Removes the given worker from the pool.
-Parameters
---
-
worker: ThreadWorkerWithMessageChannel
-Worker that will be removed.
-Returns void
Inherited from FixedThreadPool.removeWorker
--- Defined in src/pools/abstract-pool.ts:270
Protected
send-- send
To Worker(worker: ThreadWorkerWithMessageChannel, message: MessageValue<Data, unknown>): void
+- send
To Worker(worker: ThreadWorkerWithMessageChannel, message: MessageValue<Data, unknown>): void
-
@@ -528,15 +477,15 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
-
Inherit Doc
worker: ThreadWorkerWithMessageChannel
message: MessageValue<Data, unknown>
message: MessageValue<Data, unknown>
Returns void
Inherited from FixedThreadPool.sendToWorker
-- Defined in src/pools/thread/fixed.ts:57
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
-
@@ -544,39 +493,39 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
Inherit Doc
Parameters
workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"
workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"