X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FFixedThreadPool.html;h=405c43bc4f1eda2ed96899097ca333e09c83ea99;hb=fd98bbb90c7202f5dd734c029f3cee2f997aea24;hp=a1fecefd0d80aef3fcc6686da10fdc2d0c0537c6;hpb=afa30fd0dd5bbc5d305cc30be663966a449efc08;p=poolifier.git diff --git a/docs/classes/FixedThreadPool.html b/docs/classes/FixedThreadPool.html index a1fecefd..c2557b46 100644 --- a/docs/classes/FixedThreadPool.html +++ b/docs/classes/FixedThreadPool.html @@ -1,4 +1,4 @@ -
A thread pool with a fixed number of threads.
-It is possible to perform tasks in sync or asynchronous mode as you prefer.
-This pool selects the threads in a round robin fashion.
Author
Alessandro Pio Ardizio
@@ -30,24 +28,24 @@Data = unknown
-Type of data sent to the worker. This can only be serializable data.
+Type of data sent to the worker. This can only be structured-cloneable data.
Response = unknown
-Type of execution response. This can only be serializable data.
+Type of execution response. This can only be structured-cloneable data.
Hierarchy
-- AbstractPool<ThreadWorkerWithMessageChannel, Data, Response>
+
- AbstractPool<Worker, Data, Response>
- FixedThreadPool
- DynamicThreadPool
@@ -61,6 +59,7 @@emitter?
file Path
+max?
number Of Workers
opts
promise Response Map
@@ -72,26 +71,35 @@
busy
full
info
-max Size
-min Size
+max Size
+min Size
+ready
type
+utilization
worker
after Task Execution Hook
-after Worker Setup
+after Worker Node Setup
before Task Execution Hook
-choose Worker Node
-create And Setup Worker
+check Dynamic Pool Size
+create And Setup Dynamic Worker Node
+create And Setup Worker Node
create Worker
destroy
-destroy Worker
+destroy Worker Node
enable Tasks Queue
execute
+flush Tasks Queue
+get Worker Info
+has Worker Node Back Pressure
internal Busy
is Main
+list Task Functions
register Worker Message Listener
+send Kill Message To Worker
+send Startup Message To Worker
send To Worker
set Tasks Queue Options
set Worker Choice Strategy
@@ -129,7 +137,7 @@
-
-
@@ -137,7 +145,7 @@
Properties
Methods
opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
+opts: ThreadPoolOptions = {}
Options for this fixed thread pool.
Properties
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.'ready'
: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready.'busy'
: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing at least one task.'full'
: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected.destroy
': Emitted when the pool is destroyed.'error'
: Emitted when an uncaught error occurs.'taskError'
: Emitted when an error occurs while executing a task.'backPressure'
: Emitted when all worker nodes have back pressure (i.e. their tasks queue is full: queue size >= maximum queue size).Protected
Readonly
file
+Protected
Optional
Readonly
maxDynamic pool maximum size property placeholder.
+Protected
Readonly
number
-Protected
Readonly
optsOptions for the pool.
+Options for this fixed thread pool.
Response Map
-Protected
promiseThe execution response promise map.
+The task execution response promise map.
key
: The message id of each submitted task.value
: An object that contains the worker, the execution response promise resolve and reject callbacks. Choice Strategy Context
-Protected
workerWorker choice strategy context referencing a worker choice algorithm implementation.
-Default to a round robin algorithm.
Nodes
-Readonly
worker Nodes
+Readonly
Internal
workerPool worker nodes.
Accessors
Protected
full@@ -243,7 +262,7 @@
info
@@ -255,62 +274,87 @@
Size
-Protected
max+- get maxSize(): number
-
-
+- Defined in src/pools/abstract-pool.ts:546
+
Pool maximum size.
+The pool maximum size.
Returns number
- Size
-Protected
min+- get minSize(): number
-
-
- Defined in src/pools/abstract-pool.ts:539
+
+
- get type(): "fixed" | "dynamic"
-
-
- Defined in src/pools/thread/fixed.ts:122
+
+
Pool minimum size.
+The pool minimum size.
Returns number
+
+Private
ready+- get ready(): boolean
+-
+
+
The pool readiness boolean status.
+Returns boolean
+Protected
typePool type.
+The pool type.
If it is
'dynamic'
, it provides themax
property.Returns "fixed" | "dynamic"
+
+Private
utilization+- get utilization(): number
+-
+
+
The approximate pool utilization.
+Returns number
The pool utilization.
+ +Protected
worker-- get worker(): "cluster" | "thread"
+- get worker(): "thread" | "cluster"
-
-
-- Defined in src/pools/thread/fixed.ts:127
Task Execution Hook
Gets the worker type.
+The worker type.
Returns "cluster" | "thread"
+Returns "thread" | "cluster"
+Methods
Protected
after-- after
Task Execution Hook(worker, message): void
+- after
Task Execution Hook(workerNodeKey, message): void
-
-
-
-
-
@@ -332,32 +376,32 @@ Can be overridden.
-
-
+
+
Hook executed after the worker task execution. Can be overridden.
@@ -319,12 +363,12 @@ Can be overridden.Parameters
worker: ThreadWorkerWithMessageChannel
-The worker.
+workerNodeKey: number
+The worker node key.
message: MessageValue<Response, Worker | MessagePort>
+message: MessageValue<Response, unknown>
The received message.
Worker Setup
-Protected
after-- after
Worker Setup(worker): void
+- Defined in src/pools/abstract-pool.ts:872
Worker Node Setup
+Protected
after+- after
Worker Node Setup(workerNodeKey): void
-
-
-
-
+- Defined in src/pools/abstract-pool.ts:1144
Task Execution Hook
-
-- Defined in src/pools/abstract-pool.ts:842
+
+ Dynamic Pool Size
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.Method hooked up after a worker node has been newly created. +Can be overridden.
Parameters
worker: ThreadWorkerWithMessageChannel
-The newly created worker.
+workerNodeKey: number
+The newly created worker node key.
Returns void
Protected
before-- before
Task Execution Hook(workerNodeKey): void
+- before
Task Execution Hook(workerNodeKey, task): void
-
+
+-
+
Hook executed before the worker task execution. Can be overridden.
@@ -369,112 +413,133 @@ Can be overridden.workerNodeKey: number
The worker node key.
task: Task<Data>
+The task to execute.
+Returns void
Worker Node
+Protected
chooseProtected
check-- choose
Worker Node(): number
+- check
Dynamic Pool Size(min, max): void
-
-
+
+
+
-
-- Defined in src/pools/abstract-pool.ts:1087
+
+ And Setup Worker Node
Chooses a worker node for the next task.
-The default worker choice strategy uses a round robin algorithm to distribute the load.
+Parameters
++-
+
+-
+
min: number
max: number
Returns void
+ And Setup Dynamic Worker Node
+Protected
create+- create
And Setup Dynamic Worker Node(): number
+-
+
-
Creates a new, completely set up dynamic worker node.
Returns number
The worker node key
+Returns number
New, completely set up dynamic worker node key.
And Setup Worker
+Protected
createProtected
create-- create
And Setup Worker(): ThreadWorkerWithMessageChannel
+- create
And Setup Worker Node(): number
-
-
-- Defined in src/pools/abstract-pool.ts:1043
Worker
Creates a new worker and sets it up completely in the pool worker nodes.
+Creates a new, completely set up worker node.
Returns ThreadWorkerWithMessageChannel
New, completely set up worker.
+Returns number
New, completely set up worker node key.
+Protected
create-- create
Worker(): ThreadWorkerWithMessageChannel
+- create
Worker(): Worker
-
-
-- Defined in src/pools/thread/fixed.ts:114
- destroy(): Promise<void>
-
-
-- Defined in src/pools/abstract-pool.ts:787
+
+ Worker Node
Returns a newly created worker.
+Creates a new worker.
Returns ThreadWorkerWithMessageChannel
+Returns Worker
Newly created worker.
+ +destroy
Shutdowns every current worker in this pool.
+Terminates all workers in this pool.
Returns Promise<void>
- Worker
+Protected
destroyProtected
destroy-- destroy
Worker(worker): Promise<void>
+- destroy
Worker Node(workerNodeKey): Promise<void>
-
-
-
-
+- Defined in src/pools/thread/fixed.ts:60
- enable
Tasks Queue(enable, tasksQueueOptions?): void
-
-
-
-
+- Defined in src/pools/abstract-pool.ts:627
+- Defined in src/pools/thread/fixed.ts:104
+
+
+
+
To Worker
Shutdowns the given worker.
+Terminates the worker node given its worker node key.
Parameters
worker: ThreadWorkerWithMessageChannel
-A worker within
+workerNodes
.workerNodeKey: number
+The worker node key.
Returns Promise<void>
enable Tasks Queue
Enables/disables the worker tasks queue in this pool.
+Enables/disables the worker node tasks queue in this pool.
Parameters
enable: boolean
-Whether to enable or disable the worker tasks queue.
+Whether to enable or disable the worker node tasks queue.
-Optional
tasksQueueOptions: TasksQueueOptionsThe worker tasks queue options.
+The worker node tasks queue options.
Returns void
execute
-- execute(data?, name?): Promise<Response>
+- execute(data?, name?, transferList?): Promise<Response>
-
@@ -483,12 +548,17 @@ Can be overridden.
-
-
+
+-
+
+- Defined in src/pools/abstract-pool.ts:725
+
+
+
+
+
+
Busy
- internal
Busy(): boolean
-
-
+- Defined in src/pools/abstract-pool.ts:691
Main
+- Defined in src/pools/thread/fixed.ts:55
+
+
Worker Message Listener
Executes the specified function in the worker constructor with the task data input parameter.
-Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
+The optional task input data for the specified task function. This can only be structured-cloneable data.
-Optional
name: stringThe name of the worker function to execute. If not specified, the default worker function will be executed.
+The optional name of the task function to execute. If not specified, the default task function will be executed.
+
+Optional
transferList: TransferListItem[]An optional array of transferable objects to transfer ownership of. Ownership of the transferred objects is given to the pool's worker_threads worker and they should not be used in the main thread afterwards.
Returns Promise<Response>
Promise that will be fulfilled when the task is completed.
@@ -496,16 +566,76 @@ Can be overridden. Tasks Queue
+Protected
flush+- flush
Tasks Queue(workerNodeKey): void
+-
+
+
+
Parameters
++-
+
workerNodeKey: number
Returns void
Worker Info
+Protected
get+- get
Worker Info(workerNodeKey): undefined | WorkerInfo
+-
+
+
+
+
Gets the worker information given its worker node key.
+Parameters
++-
+
+
workerNodeKey: number
+The worker node key.
+Returns undefined | WorkerInfo
The worker information.
+ +has Worker Node Back Pressure
++- has
Worker Node Back Pressure(workerNodeKey): boolean
+
+
+
+
Internal
+Whether the worker node has back pressure (i.e. its tasks queue is full).
+Parameters
++-
+
+
workerNodeKey: number
+The worker node key.
+Returns boolean
+ +true
if the worker node has back pressure,false
otherwise.Protected
internalReturns boolean
Protected
is@@ -517,13 +647,26 @@ Can be overridden.
Overrides AbstractPool.isMain
-- Defined in src/pools/thread/fixed.ts:54
list Task Functions
++- list
Task Functions(): string[]
+-
+
+
+
Lists the names of task function available in this pool.
+Returns string[]
The names of task function available in this pool.
+ +Inherited from AbstractPool.listTaskFunctions
++- Defined in src/pools/abstract-pool.ts:712
Protected
register-- register
Worker Message Listener<Message>(worker, listener): void
+- register
Worker Message Listener<Message>(workerNodeKey, listener): void
-
-
-
-
-
@@ -552,58 +695,99 @@ Can be overridden.
-
-
+
Registers a listener callback on the given worker.
+Registers a listener callback on the worker given its worker node key.
Type Parameters
@@ -534,8 +677,8 @@ Can be overridden.Parameters
worker: ThreadWorkerWithMessageChannel
-The worker which should register a listener.
+workerNodeKey: number
+The worker node key.
Parameters
message: MessageValue<Message, Worker | MessagePort>
message: MessageValue<Message, unknown>
Returns void
Returns void
Overrides AbstractPool.registerWorkerMessageListener
-- Defined in src/pools/thread/fixed.ts:75
Kill Message To Worker
+Protected
send+- send
Kill Message To Worker(workerNodeKey, workerId): Promise<void>
+-
+
+
+
+
Parameters
++-
+
+-
+
workerNodeKey: number
workerId: number
Returns Promise<void>
Inherited from AbstractPool.sendKillMessageToWorker
++- Defined in src/pools/abstract-pool.ts:797
Startup Message To Worker
+Protected
send+- send
Startup Message To Worker(workerNodeKey): void
+-
+
+
+
+
+
Sends the startup message to worker given its worker node key.
+Parameters
++-
+
+
workerNodeKey: number
+The worker node key.
+Returns void
+Overrides AbstractPool.sendStartupMessageToWorker
++- Defined in src/pools/thread/fixed.ts:88
Protected
send-- send
To Worker(worker, message): void
+- send
To Worker(workerNodeKey, message, transferList?): void
-
-
-
-
-
-
+
+-
+
+- Defined in src/pools/thread/fixed.ts:77
- set
Tasks Queue Options(tasksQueueOptions): void
-
-
-
+- Defined in src/pools/abstract-pool.ts:639
+- Defined in src/pools/abstract-pool.ts:594
+- Defined in src/pools/abstract-pool.ts:613
Hook
- setup
Hook(): void
-
-
+- Defined in src/pools/abstract-pool.ts:826
Listener
- worker
Listener(): ((message) => void)
-
-
- (message): void
-
-
-
-
+
+ - Defined in src/pools/abstract-pool.ts:1261
@@ -712,6 +896,7 @@ Can be overridden
- constructor
- emitter
- file
Path
+- max
- number
Of Workers
- opts
- promise
Response Map
@@ -720,23 +905,32 @@ Can be overridden
- busy
- full
- info
-- max
Size
-- min
Size
+- max
Size
+- min
Size
+- ready
- type
+- utilization
- worker
- after
Task Execution Hook
-- after
Worker Setup
+- after
Worker Node Setup
- before
Task Execution Hook
-- choose
Worker Node
-- create
And Setup Worker
+- check
Dynamic Pool Size
+- create
And Setup Dynamic Worker Node
+- create
And Setup Worker Node
- create
Worker
- destroy
-- destroy
Worker
+- destroy
Worker Node
- enable
Tasks Queue
- execute
+- flush
Tasks Queue
+- get
Worker Info
+- has
Worker Node Back Pressure
- internal
Busy
- is
Main
+- list
Task Functions
- register
Worker Message Listener
+- send
Kill Message To Worker
+- send
Startup Message To Worker
- send
To Worker
- set
Tasks Queue Options
- set
Worker Choice Strategy
@@ -744,55 +938,68 @@ Can be overridden
- setup
Hook
- worker
Listener
-
+- Worker
Types
+- available
Parallelism
\ No newline at end of file
Sends a message to the given worker.
+Sends a message to worker given its worker node key.
Parameters
worker: ThreadWorkerWithMessageChannel
-The worker which should receive the message.
+workerNodeKey: number
+The worker node key.
message: MessageValue<Data, Worker | MessagePort>
+message: MessageValue<Data, unknown>
The message.
+Optional
transferList: TransferListItem[]The optional array of transferable objects.
+Returns void
Overrides AbstractPool.sendToWorker
-- Defined in src/pools/thread/fixed.ts:67
set Tasks Queue Options
Sets the worker tasks queue options in this pool.
+Sets the worker node tasks queue options in this pool.
Parameters
tasksQueueOptions: TasksQueueOptions
-The worker tasks queue options.
+The worker node tasks queue options.
Returns void
Inherited from AbstractPool.setTasksQueueOptions
-- Defined in src/pools/abstract-pool.ts:340
set Worker Choice Strategy
@@ -615,7 +799,7 @@ Can be overridden.-
-
@@ -628,7 +812,7 @@ Can be overridden.
Parameters
workerChoiceStrategy: "ROUND_ROBIN" | "LEAST_USED" | "LEAST_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN" | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
+workerChoiceStrategy: "ROUND_ROBIN" | "LEAST_USED" | "LEAST_BUSY" | "LEAST_ELU" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN" | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
The worker choice strategy.
Inherited from AbstractPool.setWorkerChoiceStrategy
-- Defined in src/pools/abstract-pool.ts:285
set Worker Choice Strategy Options
@@ -648,26 +832,26 @@ Can be overridden.
Inherited from AbstractPool.setWorkerChoiceStrategyOptions
-- Defined in src/pools/abstract-pool.ts:317
Protected
setupSetup hook to execute code before worker node are created in the abstract constructor. -Can be overridden
+Setup hook to execute code before worker nodes are created in the abstract constructor. +Can be overridden.
Returns void
Inherited from AbstractPool.setupHook
-- Defined in src/pools/abstract-pool.ts:441
Protected
workerThis function is the listener registered for each worker message.
+This method is the listener registered for each worker message.
Returns ((message) => void)
The listener function to execute when a message is received from a worker.
@@ -676,20 +860,20 @@ Can be overriddenThis function is the listener registered for each worker message.
+This method is the listener registered for each worker message.
Parameters
message: MessageValue<Response, Worker | MessagePort>
message: MessageValue<Response, unknown>
Returns void
The listener function to execute when a message is received from a worker.
Inherited from AbstractPool.workerListener
-- Defined in src/pools/abstract-pool.ts:653
Generated using TypeDoc