X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FFixedThreadPool.html;h=405c43bc4f1eda2ed96899097ca333e09c83ea99;hb=2a6631992868d900762f62e4c228dce4e4ee549a;hp=4fe8d4d8294782ccb3938f560acc16bb1fa607aa;hpb=e39450c0889208d6dcde666fc05b95fe7a98ee29;p=poolifier.git diff --git a/docs/classes/FixedThreadPool.html b/docs/classes/FixedThreadPool.html index 4fe8d4d8..405c43bc 100644 --- a/docs/classes/FixedThreadPool.html +++ b/docs/classes/FixedThreadPool.html @@ -1,4 +1,4 @@ -FixedThreadPool | poolifier
+FixedThreadPool | poolifier

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

+
+
+

Author

Alessandro Pio Ardizio

-

Since

0.0.1

+

Since

0.0.1

-
+

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

@@ -52,216 +53,288 @@

Constructors

-
- -
    - +
    + +
      +
    • Constructs a new poolifier fixed thread pool.

      -
      +

      Type Parameters

      -
        +
        • -

          Data = unknown

        • +

          Data = unknown

        • -

          Response = unknown

      +

      Response = unknown

    Parameters

    • -
      numberOfThreads: number
      +
      numberOfThreads: number

      Number of threads for this pool.

      -
    • +
    +
  • -
    filePath: string
    +
    filePath: string

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

    -
  • +
+
  • -
    opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
    +
    opts: ThreadPoolOptions = {}

    Options for this fixed thread pool.

    -
  • -

    Returns FixedThreadPool<Data, Response>

    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.
    • +
    • 'error': Emitted when an uncaught error occurs.
    • +
    • 'taskError': Emitted when an error occurs while executing a task.
    -
    -
    - -
    filePath: string
    -

    Path to the worker-file.

    -
    +
    + +
    filePath: string
    +

    Path to the worker file.

    +
    +
    -
    - -
    numberOfWorkers: number
    +
  • Defined in src/pools/abstract-pool.ts:96
  • +
    + +
    numberOfWorkers: number

    Number of workers that this pool should manage.

    -
    -
    - - -

    Options for the pool.

    -
    +
    + + +

    Options for this fixed thread pool.

    +
    +
    -
    - -
    promiseResponseMap: Map<string, PromiseResponseWrapper<ThreadWorkerWithMessageChannel, Response>> = ...
    +
  • Defined in src/pools/thread/fixed.ts:51
  • +
    + +
    promiseResponseMap: Map<string, PromiseResponseWrapper<Worker, Response>> = ...

    The 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<ThreadWorkerWithMessageChannel, Data, Response>
    +
  • Defined in src/pools/abstract-pool.ts:68
  • +
    + +
    workerChoiceStrategyContext: WorkerChoiceStrategyContext<Worker, Data, Response>

    Worker choice strategy context referencing a worker choice algorithm implementation.

    -

    Default to a round robin algorithm.

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

    Pool worker nodes.

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

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

      The pool filling boolean status.

      -

      Returns boolean

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

      Number of tasks running in the pool.

      +

      Pool maximum size.

      -

      Returns number

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

      Pool minimum size.

      +
      +

      Returns number

      +
    +
    + +
      +
    • get runTime(): number
    • +
    • +

      Gets the pool run time.

      +
      +

      Returns number

      The pool run time in milliseconds.

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

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

      -

      Returns PoolType

    +
  • Defined in src/pools/thread/fixed.ts:81
  • +
    + +
      +
    • get utilization(): number
    • +
    • +

      Gets the approximate pool utilization.

      +
      +

      Returns number

      The pool utilization.

      + +
    +
    + +
      +
    • get worker(): "cluster" | "thread"
    • +
    • +

      Gets the worker type.

      +
      +

      Returns "cluster" | "thread"

      +

    Methods

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

        @@ -270,40 +343,45 @@ Can be overridden.

        Parameters

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

        The received message.

        -
      -

      Returns void

    +

    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.

      +

      Function that can be hooked up when a worker has been newly created and moved to the pool worker nodes. +Can be overridden.

      Parameters

      -

      Returns void

    -
    - -
      - + +
    +

    Returns void

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

      @@ -312,258 +390,303 @@ Can be overridden.

      Parameters

      • -
        workerNodeKey: number
        +
        workerNodeKey: number

        The worker node key.

        -
      -

      Returns void

    • +
    • +
      task: Task<Data>
      +

      The task to execute.

      +
      +
    +

    Returns void

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

      Shutdowns every current worker in this pool.

      +

      Terminates every current worker in this pool.

      -

      Returns Promise<void>

    -
    - -
    +
    + +
      +
    • -

      Shutdowns the given worker.

      +

      Terminates the given worker.

      Parameters

      -

      Returns Promise<void>

      +
    +

    Returns Promise<void>

    +
    -
    - -
    +
    + +
      +
    • -

      Performs the task specified in the constructor with the data parameter.

      - -

      Returns

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

      +

      Enables/disables the worker tasks queue in this pool.

      Parameters

      • -
        data: Data
        -

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

        -
      -

      Returns Promise<Response>

    -
    - -
      - +
      enable: boolean
      +

      Whether to enable or disable the worker tasks queue.

      +
      +
      +
    • +
      Optional tasksQueueOptions: TasksQueueOptions
      +

      The worker tasks queue options.

      +
      +
    +

    Returns void

    +
    +
    + +
      +
    • -

      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.

      +

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

      +
      +
      +

      Parameters

      +
        +
      • +
        Optional data: Data
        +

        The task input data for the specified worker function. This can only be structured-cloneable data.

        -

        Returns number

      • +
      • +
        Optional name: string
        +

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

        +
        +
      +

      Returns Promise<Response>

      Promise that will be fulfilled when the task is completed.

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

      Registers a listener callback on the given worker.

      +

      Sends a message to the given worker.

      -
      -

      Type Parameters

      -
        -
      • -

        Message

      Parameters

    +
    + +
      +
    • +

      Sets the worker tasks queue options in this pool.

      +

      Parameters

      -

      Returns void

    -

    Returns void

    -
    - - +

    Returns void

    +
    +
    + +
      +
    • -

      Sends a message to the given worker.

      +

      Sets the worker choice strategy in this pool.

      Parameters

      • -
        worker: ThreadWorkerWithMessageChannel
        -

        The worker which should receive the message.

        -
      • +
        workerChoiceStrategy: "ROUND_ROBIN" | "LEAST_USED" | "LEAST_BUSY" | "LEAST_ELU" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN" | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
        +

        The worker choice strategy.

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

        The message.

        -
      -

      Returns void

    +

    Returns void

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

      Sets the worker choice strategy in this pool.

      +

      Sets the worker choice strategy options in this pool.

      Parameters

      • -
        workerChoiceStrategy: "ROUND_ROBIN" | "LESS_USED" | "LESS_BUSY" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"
        -

        The worker choice strategy.

        -
      -

      Returns void

    -
    - - +

    Returns void

    +
    +
    + +
      +
    • -

      Setup 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

    -
    - -
    +
    + +
      +
    • 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)

      The listener function to execute when a message is received from a worker.

      +
      • -
          -
        • (message: MessageValue<Response, unknown>): void
        • +
            +
          • (message): void
          • 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

            -

            Returns void

      +

      Returns void

      The listener function to execute when a message is received from a worker.

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

    On This Page

    +

    On This Page

    +
  • constructor
  • +
  • emitter
  • +
  • filePath
  • +
  • numberOfWorkers
  • +
  • opts
  • +
  • promiseResponseMap
  • +
  • workerChoiceStrategyContext
  • +
  • workerNodes
  • +
  • busy
  • +
  • full
  • +
  • info
  • +
  • maxSize
  • +
  • minSize
  • +
  • runTime
  • +
  • type
  • +
  • utilization
  • +
  • worker
  • +
  • afterTaskExecutionHook
  • +
  • afterWorkerSetup
  • +
  • beforeTaskExecutionHook
  • +
  • createAndSetupDynamicWorker
  • +
  • createAndSetupWorker
  • +
  • createWorker
  • +
  • destroy
  • +
  • destroyWorker
  • +
  • enableTasksQueue
  • +
  • execute
  • +
  • internalBusy
  • +
  • isMain
  • +
  • sendToWorker
  • +
  • setTasksQueueOptions
  • +
  • setWorkerChoiceStrategy
  • +
  • setWorkerChoiceStrategyOptions
  • +
  • setupHook
  • +
  • workerListener
  • +
  • AbstractPool
  • +
  • AbstractWorker
  • +
  • CircularArray
  • +
  • ClusterWorker
  • +
  • DynamicClusterPool
  • +
  • DynamicThreadPool
  • +
  • FixedClusterPool
  • +
  • FixedThreadPool
  • +
  • PoolEmitter
  • +
  • Queue
  • +
  • ThreadWorker
  • +
  • WorkerChoiceStrategyContext
  • +
  • ClusterPoolOptions
  • +
  • EventLoopUtilizationMeasurementStatistics
  • +
  • IPool
  • +
  • IWorker
  • +
  • IWorkerChoiceStrategy
  • +
  • MeasurementOptions
  • +
  • MeasurementStatistics
  • +
  • MeasurementStatisticsRequirements
  • +
  • MessageValue
  • +
  • PoolInfo
  • +
  • PoolOptions
  • +
  • PromiseResponseWrapper
  • +
  • StrategyPolicy
  • +
  • Task
  • +
  • TaskError
  • +
  • TaskPerformance
  • +
  • TaskStatistics
  • +
  • TaskStatisticsRequirements
  • +
  • TasksQueueOptions
  • +
  • ThreadPoolOptions
  • +
  • WorkerChoiceStrategyOptions
  • +
  • WorkerInfo
  • +
  • WorkerNode
  • +
  • WorkerOptions
  • +
  • WorkerStatistics
  • +
  • WorkerUsage
  • +
  • ErrorHandler
  • +
  • ExitHandler
  • +
  • KillBehavior
  • +
  • Measurement
  • +
  • MessageHandler
  • +
  • OnlineHandler
  • +
  • PoolEvent
  • +
  • PoolType
  • +
  • TaskFunctions
  • +
  • WorkerAsyncFunction
  • +
  • WorkerChoiceStrategy
  • +
  • WorkerFunction
  • +
  • WorkerSyncFunction
  • +
  • WorkerType
  • +
  • KillBehaviors
  • +
  • Measurements
  • +
  • PoolEvents
  • +
  • PoolTypes
  • +
  • WorkerChoiceStrategies
  • +
  • WorkerTypes
  • +
  • availableParallelism
  • Generated using TypeDoc

    \ No newline at end of file