X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FDynamicClusterPool.html;h=6ecf7c136e264fad16863ad40a623d58c4fec6d9;hb=95d287d1625c80929657a9f217774c5c8f6668e7;hp=574b94c4990cd3372f3f9fa24993083bbbfa9eba;hpb=b7076c9f9bff47cc233fb67df43ae160680c6d6e;p=poolifier.git diff --git a/docs/classes/DynamicClusterPool.html b/docs/classes/DynamicClusterPool.html index 574b94c4..e63d126d 100644 --- a/docs/classes/DynamicClusterPool.html +++ b/docs/classes/DynamicClusterPool.html @@ -1,4 +1,4 @@ -DynamicClusterPool | poolifier
+DynamicClusterPool | poolifier - v2.6.41
  • Preparing search index...
  • -
  • The search index is not available
poolifier
+
  • The search index is not available
  • poolifier - v2.6.41
    @@ -19,30 +19,33 @@

    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 and workers are busy, an event is emitted. If you want to listen to this event, use the pool's emitter.

    +
    +
    +

    Author

    Christopher Quadflieg

    -

    Author

    Christopher Quadflieg

    - -

    Since

    2.0.0

    +

    Since

    2.0.0

    -
    +

    Type Parameters

    -
      +
      • -

        Data = unknown

        -

        Type of data sent to the worker. This can only be serializable data.

        -
      • +

        Data = unknown

        +

        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.

        -
    +

    Response = unknown

    +

    Type of execution response. This can only be structured-cloneable data.

    +
    +

    Hierarchy

    +
  • Defined in src/pools/cluster/dynamic.ts:15
  • @@ -50,231 +53,309 @@ When the maximum number of workers is reached and workers are busy, an event is

    Constructors

    -
    - -
      - +
      + +
        +
      • Constructs a new poolifier dynamic cluster pool.

        -
        +

        Type Parameters

        -
          +
          • -

            Data = unknown

          • +

            Data = unknown

          • -

            Response = unknown

        +

        Response = unknown

      Parameters

      • -
        min: number
        +
        min: number

        Minimum number of workers which are always active.

      • -
        max: number
        +
        max: number

        Maximum number of workers that can be created by this pool.

      • -
        filePath: string
        +
        filePath: string

        Path to an implementation of a ClusterWorker file, which can be relative or absolute.

      • -
        opts: ClusterPoolOptions = {}
        +
        opts: ClusterPoolOptions = {}

        Options for this dynamic cluster pool.

      -

      Returns DynamicClusterPool<Data, Response>

    +
  • Defined in src/pools/cluster/dynamic.ts:27
  • Properties

    -
    - -
    emitter?: PoolEmitter
    +
    + +
    emitter?: PoolEmitter

    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 concurrently their tasks quota.
    • +
    • '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).
    -
    +
    -
    - -
    filePath: string
    +
  • Defined in src/pools/abstract-pool.ts:68
  • +
    + +
    filePath: string

    Path to the worker file.

    -
    +
    -
    - -
    max: number
    +
  • Defined in src/pools/abstract-pool.ts:117
  • +
    + +
    max: number

    Maximum number of workers that can be created by this pool.

    -
    -
    - -
    numberOfWorkers: number
    +
  • Defined in src/pools/cluster/dynamic.ts:29
  • +
    + +
    numberOfWorkers: number

    Number of workers that this pool should manage.

    -
    -
    - - +
  • Defined in src/pools/abstract-pool.ts:116
  • +
    + +

    Options for this fixed cluster pool.

    -
    -
    - -
    promiseResponseMap: Map<string, PromiseResponseWrapper<Worker, Response>> = ...
    -

    The execution response promise map.

    +
  • Defined in src/pools/cluster/fixed.ts:47
  • +
    + +
    promiseResponseMap: Map<string, PromiseResponseWrapper<Response>> = ...
    +

    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.

    When we receive a message from the worker, we get a map entry with the promise resolve/reject bound to the message id.

    -
    -
    - -
    workerChoiceStrategyContext: WorkerChoiceStrategyContext<Worker, Data, Response>
    +
  • Defined in src/pools/abstract-pool.ts:78
  • +
    + +
    workerChoiceStrategyContext: WorkerChoiceStrategyContext<Worker, Data, Response>

    Worker choice strategy context referencing a worker choice algorithm implementation.

    -

    Default to a round robin algorithm.

    -
    -
    - -
    workerNodes: WorkerNode<Worker, Data>[] = []
    +
  • Defined in src/pools/abstract-pool.ts:84
  • +
    + +
    workerNodes: IWorkerNode<Worker, Data>[] = []

    Pool worker nodes.

    -
    +
  • Defined in src/pools/abstract-pool.ts:65
  • Accessors

    -
    - -
    +
    + +
    • get full(): boolean
    • Whether the pool is full or not.

      The pool filling boolean status.

      -

      Returns boolean

    -
    - -
    +
    + +
      +
    • get info(): PoolInfo
    • -

      Number of tasks queued in the pool.

      +

      Pool information.

      -

      Returns number

    -
    - -
    +
    + +
      +
    • get maxSize(): number
    • -

      Number of tasks running in the pool.

      +

      The pool maximum size.

      -

      Returns number

    -
    - -
    +
    + +
      +
    • get minSize(): number
    • +
    • +

      The pool minimum size.

      +
      +

      Returns number

      +
    +
    + +
      +
    • get ready(): boolean
    • -

      Pool type.

      +

      The pool readiness boolean status.

      +
      +

      Returns boolean

      +
    +
    + +
      +
    • get type(): "fixed" | "dynamic"
    • +
    • +

      The pool type.

      If it is 'dynamic', it provides the max property.

      -

      Returns PoolType

    +
  • Defined in src/pools/cluster/dynamic.ts:38
  • +
    + +
    +
    + +

    Methods

    -
    - -
      - +
      + +
        +
      • Hook executed after the worker task execution. Can be overridden.

        @@ -283,40 +364,42 @@ Can be overridden.

        Parameters

        • -
          worker: Worker
          -

          The worker.

          +
          workerNodeKey: number
          +

          The worker node key.

        • -
          message: MessageValue<Response, unknown>
          +
          message: MessageValue<Response, unknown>

          The received message.

        -

        Returns void

      -
      - -
    +
    + +
      +
    • -

      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 the main-worker<->worker connection if not bind by default.

      +

      Method hooked up after a worker node has been newly created. +Can be overridden.

      Parameters

      • -
        worker: Worker
        -

        The newly created worker.

        +
        workerNodeKey: number
        +

        The newly created worker node key.

      -

      Returns void

    -
    - -
    +
    + +
      +
    • Hook executed before the worker task execution. Can be overridden.

      @@ -325,239 +408,367 @@ Can be overridden.

      Parameters

      • -
        workerNodeKey: number
        +
        workerNodeKey: number

        The worker node key.

        +
      • +
      • +
        task: Task<Data>
        +

        The task to execute.

      -

      Returns void

    -
    - -
    +
    + +
    -
    - -
    +
    + +
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + +
      +
    • -

      Shutdowns the given worker.

      +

      Terminates the worker node given its worker node key.

      Parameters

      • -
        worker: Worker
        -

        A worker within workerNodes.

        +
        workerNodeKey: number
        +

        The worker node key.

      -

      Returns void

    -
    - -
    +
    + +
      +
    • -

      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.

        +
        enable: boolean
        +

        Whether to enable or disable the worker node tasks queue.

      • -
        Optional tasksQueueOptions: TasksQueueOptions
        -

        The worker tasks queue options.

        -
      -

      Returns void

    +

    Returns void

    +
    -
    - -
    +
    + +
      +
    • -

      Executes the function specified in the constructor with the task data input parameter.

      - -

      Returns

      Promise that will be resolved when the task is successfully completed.

      +

      Executes the specified function in the worker constructor with the task data input parameter.

      Parameters

      • -
        data: Data
        -

        The task input data for the specified function. This can only be serializable data.

        -
      -

      Returns Promise<Response>

    • +
    • +
      Optional name: string
      +

      The optional name of the task function to execute. If not specified, the default task function will be executed.

      +
      Optional
    • +
    • +
      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.

      +
      Optional
    +

    Returns Promise<Response>

    Promise that will be fulfilled when the task is completed.

    + +
    -
    - -
    +
    + +
    +
    + +
      +
    • -

      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.

      +

      Gets the worker information given its worker node key.

      +
      +
      +

      Parameters

      +
        +
      • +
        workerNodeKey: number
        +

        The worker node key.

        +
      +

      Returns WorkerInfo

      The worker information.

      -

      Returns

      A worker node key if there is one, -1 otherwise.

      +
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + +
    +
    + +
      +
    • -

      Registers a listener callback on the given worker.

      +

      Registers a listener callback on the worker given its worker node key.

      -
      +

      Type Parameters

      -
        +
        • -

          Message

      +

      Message

    Parameters

    • -
      worker: Worker
      -

      The worker which should register a listener.

      +
      workerNodeKey: number
      +

      The worker node key.

    • -
      listener: ((message: MessageValue<Message, unknown>) => void)
      +
      listener: ((message) => void)

      The message listener callback.

    Returns void

    -

    Returns void

    -
    - -
    +
    + +
    +
    + +
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + + +

    Returns void

    +
    -
    - -
    +
    + +
    -
    - -
    +
    + +
    -
    - -
    +
    + + +
    +
  • Defined in src/pools/abstract-pool.ts:1331
  • -

    On This Page

    +

    On This Page

    +
  • constructor
  • +
  • emitter
  • +
  • filePath
  • +
  • max
  • +
  • numberOfWorkers
  • +
  • opts
  • +
  • promiseResponseMap
  • +
  • workerChoiceStrategyContext
  • +
  • workerNodes
  • +
  • busy
  • +
  • full
  • +
  • info
  • +
  • maxSize
  • +
  • minSize
  • +
  • ready
  • +
  • type
  • +
  • utilization
  • +
  • worker
  • +
  • afterTaskExecutionHook
  • +
  • afterWorkerNodeSetup
  • +
  • beforeTaskExecutionHook
  • +
  • checkDynamicPoolSize
  • +
  • createAndSetupDynamicWorkerNode
  • +
  • createAndSetupWorkerNode
  • +
  • createWorker
  • +
  • destroy
  • +
  • destroyWorkerNode
  • +
  • enableTasksQueue
  • +
  • execute
  • +
  • flushTasksQueue
  • +
  • getWorkerInfo
  • +
  • hasWorkerNodeBackPressure
  • +
  • internalBusy
  • +
  • isMain
  • +
  • listTaskFunctions
  • +
  • registerWorkerMessageListener
  • +
  • sendKillMessageToWorker
  • +
  • sendStartupMessageToWorker
  • +
  • sendToWorker
  • +
  • setTasksQueueOptions
  • +
  • setWorkerChoiceStrategy
  • +
  • setWorkerChoiceStrategyOptions
  • +
  • setupHook
  • +
  • workerListener
  • +
  • AbstractPool
  • +
  • AbstractWorker
  • +
  • CircularArray
  • +
  • ClusterWorker
  • +
  • Deque
  • +
  • DynamicClusterPool
  • +
  • DynamicThreadPool
  • +
  • FixedClusterPool
  • +
  • FixedThreadPool
  • +
  • Node
  • +
  • PoolEmitter
  • +
  • ThreadWorker
  • +
  • WorkerChoiceStrategyContext
  • +
  • ClusterPoolOptions
  • +
  • EventLoopUtilizationMeasurementStatistics
  • +
  • IPool
  • +
  • IWorker
  • +
  • IWorkerChoiceStrategy
  • +
  • IWorkerNode
  • +
  • MeasurementOptions
  • +
  • MeasurementStatistics
  • +
  • MeasurementStatisticsRequirements
  • +
  • MessageValue
  • +
  • PoolInfo
  • +
  • PoolOptions
  • +
  • PromiseResponseWrapper
  • +
  • StrategyPolicy
  • +
  • Task
  • +
  • TaskError
  • +
  • TaskPerformance
  • +
  • TaskStatistics
  • +
  • TaskStatisticsRequirements
  • +
  • TasksQueueOptions
  • +
  • ThreadPoolOptions
  • +
  • WorkerChoiceStrategyOptions
  • +
  • WorkerInfo
  • +
  • WorkerOptions
  • +
  • WorkerStatistics
  • +
  • WorkerUsage
  • +
  • ErrorHandler
  • +
  • ExitHandler
  • +
  • KillBehavior
  • +
  • KillHandler
  • +
  • Measurement
  • +
  • MessageHandler
  • +
  • OnlineHandler
  • +
  • PoolEvent
  • +
  • PoolType
  • +
  • TaskAsyncFunction
  • +
  • TaskFunction
  • +
  • TaskFunctions
  • +
  • TaskSyncFunction
  • +
  • WorkerChoiceStrategy
  • +
  • WorkerNodeEventCallback
  • +
  • WorkerType
  • +
  • Writable
  • +
  • KillBehaviors
  • +
  • Measurements
  • +
  • PoolEvents
  • +
  • PoolTypes
  • +
  • WorkerChoiceStrategies
  • +
  • WorkerTypes
  • +
  • availableParallelism
  • -

    Generated using TypeDoc

    +

    Generated using TypeDoc

    \ No newline at end of file