X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2Fdynamicclusterpool.html;h=65d2065cf7912919365e05555b76a72940fda07d;hb=refs%2Ftags%2Fv2.2.0;hp=f661b0b4fa3ccdb604baa3ff16ba04375a83f2d0;hpb=849e05470ba75db08bb8def0c547ab4d8c35c9a0;p=poolifier.git diff --git a/docs/classes/dynamicclusterpool.html b/docs/classes/dynamicclusterpool.html index f661b0b4..65d2065c 100644 --- a/docs/classes/dynamicclusterpool.html +++ b/docs/classes/dynamicclusterpool.html @@ -1,1183 +1,54 @@ - - - - - - DynamicClusterPool | poolifier - - - - - - -
-
-
-
- -
-
- Options -
-
- All -
    -
  • Public
  • -
  • Public/Protected
  • -
  • All
  • -
-
- - - - -
-
- Menu -
-
-
-
-
-
- -

Class DynamicClusterPool<Data, Response>

-
-
-
-
-
-
-
-
-
-

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

-
-
author
-

Christopher Quadflieg

-
-
since
-

2.0.0

-
-
-
-
-
-

Type parameters

-
    -
  • -

    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.

    -
    -
    -
  • -
-
-
-

Hierarchy

- -
-
-

Index

-
- -
-
-
-

Constructors

-
- -

constructor

- -
    -
  • - -
    -
    -

    Constructs a new poolifier dynamic cluster pool.

    -
    -
    -

    Type parameters

    -
      -
    • -

      Data = unknown

      -
    • -
    • -

      Response = unknown

      -
    • -
    -

    Parameters

    -
      -
    • -
      min: number
      -
      -

      Minimum number of workers which are always active.

      -
      -
    • -
    • -
      max: number
      -
      -

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

      -
      -
    • -
    • -
      filePath: string
      -
      -

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

      -
      -
    • -
    • -
      opts: ClusterPoolOptions = ...
      -
      -

      Options for this dynamic cluster pool. Default: {}

      -
      -
    • -
    -

    Returns DynamicClusterPool<Data, Response>

    -
  • -
-
-
-
-

Properties

-
- -

Optional Readonly emitter

-
emitter: undefined | PoolEmitter
- -
-
- -

Readonly filePath

-
filePath: string
- -
-
- -

Readonly max

-
max: number
- -
-
- -

Protected nextMessageId

-
nextMessageId: number = 0
- -
-
-

ID of the next message.

-
-
-
-
- -

Readonly numberOfWorkers

-
numberOfWorkers: number
- -
-
- -

Readonly opts

-
opts: ClusterPoolOptions = ...
- -
-
- -

Protected promiseMap

-
promiseMap: Map<number, PromiseWorkerResponseWrapper<Worker, Response>> = ...
- -
-
-

The 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.
  • -
-

When we receive a message from the worker we get a map entry and resolve/reject the promise based on the message.

-
-
-
- -

Readonly tasks

-
tasks: Map<Worker, number> = ...
- -
-
- -

Protected workerChoiceStrategyContext

-
workerChoiceStrategyContext: WorkerChoiceStrategyContext<Worker, Data, Response>
- -
-
-

Worker choice strategy instance implementing the worker choice algorithm.

-
-

Default to a strategy implementing a round robin algorithm.

-
-
-
- -

Readonly workers

-
workers: Worker[] = ...
- -
-
-
-

Accessors

-
- -

busy

-
    -
  • get busy(): boolean
  • -
- -
-
- -

numberOfRunningTasks

-
    -
  • get numberOfRunningTasks(): number
  • -
- -
-
- -

type

-
    -
  • get type(): PoolType
  • -
- -
-
-
-

Methods

-
- -

Protected afterWorkerSetup

-
    -
  • afterWorkerSetup(worker: Worker): void
  • -
- -
-
- -

Protected chooseWorker

-
    -
  • chooseWorker(): Worker
  • -
- -
-
- -

Protected createAndSetupWorker

-
    -
  • createAndSetupWorker(): Worker
  • -
- -
-
- -

Protected createWorker

-
    -
  • createWorker(): Worker
  • -
- -
-
- -

Protected decreaseWorkersTasks

-
    -
  • decreaseWorkersTasks(worker: Worker): void
  • -
- -
-
- -

destroy

-
    -
  • destroy(): Promise<void>
  • -
- -
-
- -

destroyWorker

-
    -
  • destroyWorker(worker: Worker): void
  • -
- -
-
- -

execute

-
    -
  • execute(data: Data): Promise<Response>
  • -
- -
-
- -

findFreeTasksMapEntry

-
    -
  • findFreeTasksMapEntry(): false | [Worker, number]
  • -
- -
-
- -

Protected increaseWorkersTask

-
    -
  • increaseWorkersTask(worker: Worker): void
  • -
- -
-
- -

Protected internalExecute

-
    -
  • internalExecute(worker: Worker, messageId: number): Promise<Response>
  • -
- -
-
- -

Protected internalGetBusyStatus

-
    -
  • internalGetBusyStatus(): boolean
  • -
- -
-
- -

Protected isMain

-
    -
  • isMain(): boolean
  • -
- -
-
- -

registerWorkerMessageListener

-
    -
  • registerWorkerMessageListener<Message>(worker: Worker, listener: (message: MessageValue<Message, unknown>) => void): void
  • -
-
    -
  • - -
    -
    -
    inheritdoc
    -
    -
    -
    -

    Type parameters

    -
      -
    • -

      Message

      -
    • -
    -

    Parameters

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

          Parameters

          -
            -
          • -
            message: MessageValue<Message, unknown>
            -
          • -
          -

          Returns void

          -
        • -
        -
      • -
      -
    • -
    -

    Returns void

    -
  • -
-
-
- -

Protected removeWorker

-
    -
  • removeWorker(worker: Worker): void
  • -
- -
-
- -

Protected sendToWorker

-
    -
  • sendToWorker(worker: Worker, message: MessageValue<Data, unknown>): void
  • -
- -
-
- -

setWorkerChoiceStrategy

-
    -
  • setWorkerChoiceStrategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"): void
  • -
- -
-
- -

Protected setupHook

-
    -
  • setupHook(): void
  • -
- -
-
- -

Protected workerListener

-
    -
  • workerListener(): (message: MessageValue<Response, unknown>) => void
  • -
-
    -
  • - -
    -
    -

    This function is the listener registered for each worker.

    -
    -
    -

    Returns (message: MessageValue<Response, unknown>) => void

    -

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

    -
      -
    • -
        -
      • (message: MessageValue<Response, unknown>): void
      • -
      -
        -
      • -

        Parameters

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

        Returns void

        -
      • -
      -
    • -
    -
  • -
-
-
-
- -
-
- -
-

Generated using TypeDoc

-
-
- - - \ No newline at end of file +DynamicClusterPool | poolifier
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DynamicClusterPool<Data, Response>

+

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

+
template DataType

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

+
template ResponseType

of response of execution. This can only be serializable data.

+
author

Christopher Quadflieg

+
since

2.0.0

+

Type parameters

  • Data = unknown

  • Response = unknown

Hierarchy

Index

Constructors

constructor

  • +

    Constructs a new poolifier dynamic cluster pool.

    +

    Type parameters

    • Data = unknown

    • Response = unknown

    Parameters

    • min: number
      +

      Minimum number of workers which are always active.

      +
    • max: number
      +

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

      +
    • filePath: string
      +

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

      +
    • opts: ClusterPoolOptions = {}

    Returns DynamicClusterPool<Data, Response>

Properties

Optional Readonly emitter

emitter?: PoolEmitter

Readonly filePath

filePath: string

Readonly max

max: number

Protected nextMessageId

nextMessageId: number = 0
+

Id of the next message.

+

Readonly numberOfWorkers

numberOfWorkers: number

Readonly opts

Protected promiseMap

promiseMap: Map<number, PromiseWorkerResponseWrapper<Worker, Response>> = ...
+

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

When we receive a message from the worker we get a map entry and resolve/reject the promise based on the message.

+

Readonly tasks

tasks: Map<Worker, number> = ...

Protected workerChoiceStrategyContext

workerChoiceStrategyContext: WorkerChoiceStrategyContext<Worker, Data, Response>
+

Worker choice strategy instance implementing the worker choice algorithm.

+

Default to a strategy implementing a round robin algorithm.

+

Readonly workers

workers: Worker[] = []

Accessors

busy

  • get busy(): boolean

numberOfRunningTasks

  • get numberOfRunningTasks(): number

type

  • get type(): PoolType

Methods

Protected afterWorkerSetup

  • afterWorkerSetup(worker: Worker): void

Protected chooseWorker

  • chooseWorker(): Worker

Protected createAndSetupWorker

  • createAndSetupWorker(): Worker

Protected createWorker

  • createWorker(): Worker

Protected decreaseWorkersTasks

  • decreaseWorkersTasks(worker: Worker): void

destroy

  • destroy(): Promise<void>

destroyWorker

  • destroyWorker(worker: Worker): void

execute

  • execute(data: Data): Promise<Response>

findFreeTasksMapEntry

  • findFreeTasksMapEntry(): false | [Worker, number]

Protected increaseWorkersTask

  • increaseWorkersTask(worker: Worker): void

Protected internalExecute

  • internalExecute(worker: Worker, messageId: number): Promise<Response>

Protected internalGetBusyStatus

  • internalGetBusyStatus(): boolean

Protected isMain

  • isMain(): boolean

registerWorkerMessageListener

  • registerWorkerMessageListener<Message>(worker: Worker, listener: (message: MessageValue<Message, unknown>) => void): void

Protected removeWorker

  • removeWorker(worker: Worker): void

Protected sendToWorker

  • sendToWorker(worker: Worker, message: MessageValue<Data, unknown>): void

setWorkerChoiceStrategy

  • setWorkerChoiceStrategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"): void

Protected setupHook

  • setupHook(): void

Protected workerListener

  • workerListener(): (message: MessageValue<Response, unknown>) => void
  • +

    This function is the listener registered for each worker.

    +

    Returns (message: MessageValue<Response, unknown>) => void

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

    +
      • (message: MessageValue<Response, unknown>): void
      • +

        This function is the listener registered for each worker.

        +

        Parameters

        • message: MessageValue<Response, unknown>

        Returns void

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

        +

Generated using TypeDoc

\ No newline at end of file