X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=docs%2Fclasses%2FDynamicThreadPool.html;h=35dd313b267e7d2887550439a3f9574075b9285b;hb=437d25258782c8801daa58829575d5a51c05dcee;hp=c9b126cc88102e3da49055f46db881b6943aaf74;hpb=79458fb6e10234a237757111e710f8f71424fa06;p=poolifier.git diff --git a/docs/classes/DynamicThreadPool.html b/docs/classes/DynamicThreadPool.html index c9b126cc..35dd313b 100644 --- a/docs/classes/DynamicThreadPool.html +++ b/docs/classes/DynamicThreadPool.html @@ -1,4 +1,4 @@ -
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
+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
.emitter
.Author
Alessandro Pio Ardizio
@@ -28,21 +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
-Type of response of execution. This can only be serializable data.
+Response = unknown
+Type of execution response. This can only be serializable data.
Hierarchy
-- FixedThreadPool<Data, Response>
+
- FixedThreadPool<Data, Response>
- DynamicThreadPool
@@ -50,52 +50,55 @@ When the maximum number of threads is reached, an event is emitted. If you want
constructor
+constructor
emitter?
-file Path
-max
-number Of Workers
-opts
-promise Response Map
-worker Choice Strategy Context
-workers
+emitter?
+file Path
+max
+number Of Workers
+opts
+promise Response Map
+worker Choice Strategy Context
+worker Nodes
busy
-number Of Running Tasks
-type
+busy
+full
+number Of Queued Tasks
+number Of Running Tasks
+type
after Promise Response Hook
-after Worker Setup
-before Promise Response Hook
-choose Worker
-create And Setup Worker
-create Worker
-destroy
-destroy Worker
-execute
-find Free Worker Key
-internal Get Busy Status
-is Main
-register Worker Message Listener
-remove Worker
-send To Worker
-set Worker Choice Strategy
-setup Hook
-worker Listener
+after Task Execution Hook
+after Worker Setup
+before Task Execution Hook
+choose Worker Node
+create And Setup Worker
+create Worker
+destroy
+destroy Worker
+enable Tasks Queue
+execute
+internal Busy
+is Main
+register Worker Message Listener
+send To Worker
+set Tasks Queue Options
+set Worker Choice Strategy
+set Worker Choice Strategy Options
+setup Hook
+worker Listener
+
+
-
-
-
-
-
-
-
-
-
+- Defined in src/pools/thread/dynamic.ts:29
+
emitter?: PoolEmitter
-emitter?: PoolEmitter
+
-
+- Defined in src/pools/abstract-pool.ts:42
+
file Path: string
-file Path: string
+
-
-max: number
+- Defined in src/pools/abstract-pool.ts:77
+
+max: number
-
+- Defined in src/pools/thread/dynamic.ts:31
+
number Of Workers: number
+number Of Workers: number
-
+- Defined in src/pools/abstract-pool.ts:76
+
opts: PoolOptions<ThreadWorkerWithMessageChannel>
+opts: PoolOptions<ThreadWorkerWithMessageChannel>
-
+- Defined in src/pools/abstract-pool.ts:78
+
promise Response Map: Map<string, PromiseResponseWrapper<ThreadWorkerWithMessageChannel, Response>> = ...
-promise Response Map: Map<string, PromiseResponseWrapper<ThreadWorkerWithMessageChannel, Response>> = ...
+
-
+
-
-
+- Defined in src/pools/abstract-pool.ts:52
+
worker Choice Strategy Context: WorkerChoiceStrategyContext<ThreadWorkerWithMessageChannel, Data, Response>
-worker Choice Strategy Context: WorkerChoiceStrategyContext<ThreadWorkerWithMessageChannel, Data, Response>
+
-
-workers: WorkerType<ThreadWorkerWithMessageChannel>[] = []
-- Defined in src/pools/abstract-pool.ts:62
+
+worker Nodes: WorkerNode<ThreadWorkerWithMessageChannel, Data>[] = []
+
-
+- Defined in src/pools/abstract-pool.ts:39
-
Constructors
-Properties
-Accessors
-Methods
-Constructors
-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, max, filePath, opts?): DynamicThreadPool<Data, Response>
-
@@ -103,424 +106,506 @@ When the maximum number of threads is reached, an event is emitted. If you want
-
-
+
-
-
Constructs a new poolifier dynamic thread pool.
Type Parameters
Data = unknown
Data = unknown
Response = unknown
Response = unknown
Parameters
min: number
+min: number
Minimum number of threads which are always active.
max: number
+max: number
Maximum number of threads that can be created by this pool.
filePath: string
+filePath: string
Path to an implementation of a
ThreadWorker
file, which can be relative or absolute.opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
+opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
Options for this dynamic thread pool.
Returns DynamicThreadPool<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 FixedThreadPool.emitter
-- Defined in src/pools/abstract-pool.ts:32
Path
-Readonly
filePath to the worker-file.
+Path to the worker file.
Inherited from FixedThreadPool.filePath
-- Defined in src/pools/abstract-pool.ts:67
-Protected
Readonly
max
+Readonly
maxMaximum number of threads that can be created by this pool.
-- Defined in src/pools/thread/dynamic.ts:31
Of Workers
-Readonly
numberNumber of workers that this pool should manage.
Inherited from FixedThreadPool.numberOfWorkers
-- Defined in src/pools/abstract-pool.ts:66
-Readonly
optsOptions for the pool.
Inherited from FixedThreadPool.opts
-- Defined in src/pools/abstract-pool.ts:68
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 FixedThreadPool.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 FixedThreadPool.workerChoiceStrategyContext
-- Defined in src/pools/abstract-pool.ts:52
-Readonly
workers{@inheritDoc}
+ Nodes
+Readonly
workerPool worker nodes.
Inherited from FixedThreadPool.workers
+Inherited from FixedThreadPool.workerNodes
-- Defined in src/pools/abstract-pool.ts:29
Accessors
-busy
-+
+- get busy(): boolean
-
-
-
-
+
+
+
+
+
+- get numberOfRunningTasks(): number
-
-
-
+- Defined in src/pools/abstract-pool.ts:185
+
+Protected
busy{@inheritDoc}
+Whether the pool is busy or not.
+The pool busyness boolean status.
Returns boolean
Overrides FixedThreadPool.busy
-- Defined in src/pools/thread/dynamic.ts:44
number Of Running Tasks
-+- Defined in src/pools/thread/dynamic.ts:49
+Protected
full+- get full(): boolean
+-
+
+
+
Whether the pool is full or not.
+The pool filling boolean status.
+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:195
Of Running Tasks
+Private
number{@inheritDoc}
+Number of tasks running in the pool.
Returns number
Inherited from FixedThreadPool.numberOfRunningTasks
-- Defined in src/pools/abstract-pool.ts:141
type
--- get type(): PoolType
+
+- get type(): PoolType
-
-
-
+
+- Defined in src/pools/thread/dynamic.ts:39
-
{@inheritDoc}
+Pool type.
+If it is
'dynamic'
, it provides themax
property.Returns PoolType
Returns PoolType
Overrides FixedThreadPool.type
-- Defined in src/pools/thread/dynamic.ts:39
Methods
- Promise Response Hook
-Protected
after-- after
Promise Response Hook(worker: ThreadWorkerWithMessageChannel, message: MessageValue<Response, unknown>): void
+
+
Task Execution Hook
+Protected
after+- after
Task Execution Hook(worker, message): void
-
-
-
-
-
-
-
-
+- Defined in src/pools/abstract-pool.ts:386
+
-
-
+
+
Hook executed after the worker task promise resolution. +
Hook executed after the worker task execution. Can be overridden.
Parameters
worker: ThreadWorkerWithMessageChannel
+worker: ThreadWorkerWithMessageChannel
The worker.
message: MessageValue<Response, unknown>
+message: MessageValue<Response, unknown>
The received message.
Returns void
Inherited from FixedThreadPool.afterPromiseResponseHook
+Inherited from FixedThreadPool.afterTaskExecutionHook
-- Defined in src/pools/abstract-pool.ts:253
Worker Setup
-Protected
after-- after
Worker Setup(worker: ThreadWorkerWithMessageChannel): void
+
+- after
Worker Setup(worker): void
-
-
-
-
+
{@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: ThreadWorkerWithMessageChannel
worker: ThreadWorkerWithMessageChannel
+The newly created worker.
+Returns void
Inherited from FixedThreadPool.afterWorkerSetup
-- Defined in src/pools/thread/fixed.ts:85
Promise Response Hook
-Protected
before-- before
Promise Response Hook(workerKey: number): void
+- Defined in src/pools/thread/fixed.ts:85
Task Execution Hook
+Protected
before+- before
Task Execution Hook(workerNodeKey): void
-
-
-
-
-
-
-
+
+
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 FixedThreadPool.beforePromiseResponseHook
+Inherited from FixedThreadPool.beforeTaskExecutionHook
-- Defined in src/pools/abstract-pool.ts:242
Worker
-Protected
choose-- choose
Worker(): [number, ThreadWorkerWithMessageChannel]
+- Defined in src/pools/abstract-pool.ts:375
Worker Node
+Protected
choose+- choose
Worker Node(): [number, WorkerNode<ThreadWorkerWithMessageChannel, Data>]
-
-
-
-
+
-
+- Defined in src/pools/abstract-pool.ts:419
+
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, ThreadWorkerWithMessageChannel]
Inherited from FixedThreadPool.chooseWorker
+Returns [number, WorkerNode<ThreadWorkerWithMessageChannel, Data>]
Inherited from FixedThreadPool.chooseWorkerNode
-- Defined in src/pools/abstract-pool.ts:290
And Setup Worker
-Protected
create-- create
And Setup Worker(): ThreadWorkerWithMessageChannel
+
+- create
And Setup Worker(): ThreadWorkerWithMessageChannel
-
-
-
+
-
+- Defined in src/pools/abstract-pool.ts:481
+
Creates 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
Returns ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.createAndSetupWorker
-- Defined in src/pools/abstract-pool.ts:335
Worker
-Protected
create-- create
Worker(): ThreadWorkerWithMessageChannel
+
+- create
Worker(): ThreadWorkerWithMessageChannel
-
-
-
+
-
+- Defined in src/pools/thread/fixed.ts:78
+
+
-
\ No newline at end of file
+
\ No newline at end of file
{@inheritDoc}
+Returns a newly created worker.
Returns ThreadWorkerWithMessageChannel
Returns ThreadWorkerWithMessageChannel
Inherited from FixedThreadPool.createWorker
-- Defined in src/pools/thread/fixed.ts:78
destroy
--- destroy(): Promise<void>
+
+- destroy(): Promise<void>
-
-
-
+
-
-
+
+
-
-
+
+
-
-
+
+
{@inheritDoc}
+Shutdowns every current worker in this pool.
Returns Promise<void>
Returns Promise<void>
Inherited from FixedThreadPool.destroy
-- Defined in src/pools/abstract-pool.ts:208
destroy Worker
--- destroy
Worker(worker: ThreadWorkerWithMessageChannel): Promise<void>
+- Defined in src/pools/abstract-pool.ts:338
Worker
+Protected
destroy+- destroy
Worker(worker): Promise<void>
-
-
-
-
-
+
+
{@inheritDoc}
+Shutdowns the given worker.
Parameters
worker: ThreadWorkerWithMessageChannel
Returns Promise<void>
worker: ThreadWorkerWithMessageChannel
+A worker within
+workerNodes
.Returns Promise<void>
Inherited from FixedThreadPool.destroyWorker
-- Defined in src/pools/thread/fixed.ts:54
execute
--- execute(data: Data): Promise<Response>
+- Defined in src/pools/thread/fixed.ts:54
enable Tasks Queue
++- enable
Tasks Queue(enable, tasksQueueOptions?): void
-
-
-
-
-
-
+-
+
+
+
{@inheritDoc}
+Enables/disables the worker tasks queue in this pool.
Parameters
data: Data
Returns Promise<Response>
Inherited from FixedThreadPool.execute
+enable: boolean
+Whether to enable or disable the worker tasks queue.
+
+Optional
tasksQueueOptions: TasksQueueOptionsThe worker tasks queue options.
+Returns void
Inherited from FixedThreadPool.enableTasksQueue
-- Defined in src/pools/abstract-pool.ts:193
find Free Worker Key
--- find
Free Worker Key(): number | false
+- Defined in src/pools/abstract-pool.ts:254
execute
++- execute(data?): Promise<Response>
-
-
-
-
-
-
+
+
-
+- Defined in src/pools/abstract-pool.ts:298
+
+
+
{@inheritDoc}
+Executes the function specified in the worker constructor with the task data input parameter.
+ +Returns
Promise that will be fulfilled when the task is completed.
Returns number | false
Inherited from FixedThreadPool.findFreeWorkerKey
--- Defined in src/pools/abstract-pool.ts:185
Get Busy Status
-Protected
internal-- internal
Get Busy Status(): boolean
+
+
+
+
Parameters
++-
+
+Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
+Returns Promise<Response>
Inherited from FixedThreadPool.execute
++- Defined in src/pools/abstract-pool.ts:307
Busy
+Protected
internal+- internal
Busy(): boolean
-
-
Returns boolean
Inherited from FixedThreadPool.internalGetBusyStatus
+Inherited from FixedThreadPool.internalBusy
-- Defined in src/pools/abstract-pool.ts:177
Main
-Protected
is-- is
Main(): boolean
+
+- is
Main(): boolean
-
-
-
-
+
+
-
-
+
+
-
+- 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
+- enable
Tasks Queue
+- execute
+- internal
Busy
+- is
Main
+- register
Worker Message Listener
+- send
To Worker
+- set
Tasks Queue Options
+- set
Worker Choice Strategy
+- set
Worker Choice Strategy Options
+- setup
Hook
+- worker
Listener
{@inheritDoc}
+Should return whether the worker is the main worker or not.
Returns boolean
Inherited from FixedThreadPool.isMain
-- Defined in src/pools/thread/fixed.ts:49
register Worker Message Listener
--- register
Worker Message Listener<Message>(messageChannel: ThreadWorkerWithMessageChannel, listener: ((message: MessageValue<Message, unknown>) => void)): void
+- Defined in src/pools/thread/fixed.ts:49
Worker Message Listener
+Protected
register+- register
Worker Message Listener<Message>(worker, listener): void
-
-
-
-
+
-
-
+
-
-
-
-
{@inheritDoc}
+Registers a listener callback on the given worker.
Type Parameters
Message
Message
Parameters
messageChannel: ThreadWorkerWithMessageChannel
worker: ThreadWorkerWithMessageChannel
+The worker which should register a listener.
+listener: ((message: MessageValue<Message, unknown>) => void)
+listener: ((message) => void)
+The message listener callback.
+-- (message: MessageValue<Message, unknown>): void
+
+- (message): 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:70
Worker
-Protected
remove-- remove
Worker(worker: ThreadWorkerWithMessageChannel): void
+- Defined in src/pools/thread/fixed.ts:70
To Worker
+Protected
send+- send
To Worker(worker, message): void
-
-
-
-
+-
+
-
-
-
+
+
-
+- Defined in src/pools/abstract-pool.ts:266
+
-
+- Defined in src/pools/abstract-pool.ts:218
+
+
+
+
-
Removes the given worker from the pool.
+Sends a message to the given worker.
Parameters
worker: ThreadWorkerWithMessageChannel
-The worker that will be removed.
+worker: ThreadWorkerWithMessageChannel
+The worker which should receive the message.
+message: MessageValue<Data, unknown>
+The message.
Returns void
Inherited from FixedThreadPool.removeWorker
+Inherited from FixedThreadPool.sendToWorker
-- Defined in src/pools/abstract-pool.ts:277
To Worker
-Protected
send-- send
To Worker(worker: ThreadWorkerWithMessageChannel, message: MessageValue<Data, unknown>): void
+- Defined in src/pools/thread/fixed.ts:62
set Tasks Queue Options
++- set
Tasks Queue Options(tasksQueueOptions): void
-
-
-
-
--
-
+
-
{@inheritDoc}
+Sets the worker tasks queue options in this pool.
Parameters
worker: ThreadWorkerWithMessageChannel
message: MessageValue<Data, unknown>
tasksQueueOptions: TasksQueueOptions
+The worker tasks queue options.
+Returns void
Inherited from FixedThreadPool.sendToWorker
+Inherited from FixedThreadPool.setTasksQueueOptions
-- Defined in src/pools/thread/fixed.ts:62
set Worker Choice Strategy
--- set
Worker Choice Strategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"): void
+
+- set
Worker Choice Strategy(workerChoiceStrategy, workerChoiceStrategyOptions?): void
-
-
-
-
+
+-
+
{@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.
+
+Optional
workerChoiceStrategyOptions: WorkerChoiceStrategyOptionsThe worker choice strategy options.
+Returns void
Inherited from FixedThreadPool.setWorkerChoiceStrategy
-- Defined in src/pools/abstract-pool.ts:156
set Worker Choice Strategy Options
++- set
Worker Choice Strategy Options(workerChoiceStrategyOptions): void
+-
+
+
+
+
+
Sets the worker choice strategy options in this pool.
+Parameters
++-
+
workerChoiceStrategyOptions: WorkerChoiceStrategyOptions
+The worker choice strategy options.
+Returns void
Inherited from FixedThreadPool.setWorkerChoiceStrategyOptions
++- Defined in src/pools/abstract-pool.ts:244
Hook
-Protected
setup-- setup
Hook(): void
+
+- setup
Hook(): void
-
-
-
+- Defined in src/pools/abstract-pool.ts:360
+
-
+- Defined in src/pools/abstract-pool.ts:504
+
+
-
-
Setup 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
Returns void
Inherited from FixedThreadPool.setupHook
-- Defined in src/pools/abstract-pool.ts:227
Listener
-Protected
worker-- worker
Listener(): ((message: MessageValue<Response, unknown>) => void)
+
+- worker
Listener(): ((message) => 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) => void)
-- (message: MessageValue<Response, unknown>): void
+
+- (message): void
-
-
@@ -528,15 +613,16 @@ to run code before workers are created in the abstract constructor.
-
-
+
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 FixedThreadPool.workerListener
-- Defined in src/pools/abstract-pool.ts:364
-
+Settings
Settings
Member Visibility
Theme
+
On This Page
-- poolifier
-
Generated using TypeDoc