poolifier - v6.0.2
    Preparing search index...

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

    2.0.0

    Type Parameters

    • 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 structured-cloneable data.

    Hierarchy (View Summary)

    Index
    • Constructs a new poolifier dynamic cluster pool.

      Type Parameters

      • 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 structured-cloneable data.

      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.

      Returns DynamicClusterPool<Data, Response>

    destroying: boolean

    Whether the pool is destroying or not.

    emitter?: EventEmitterAsyncResource
    filePath: string

    Path to the worker file.

    maximumNumberOfWorkers?: number

    Maximum number of workers that this pool manages.

    minimumNumberOfWorkers: number

    Minimum number of workers that this pool manages.

    opts: PoolOptions<Worker>

    Options for the pool.

    promiseResponseMap: Map<
        `${string}-${string}-${string}-${string}-${string}`,
        PromiseResponseWrapper<Response>,
    > = ...

    The task execution response promise map:

    • key: The message id of each submitted task.
    • value: An object that contains task's worker node key, execution response promise resolve and reject callbacks, async resource.

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

    started: boolean

    Whether the pool is started or not.

    starting: boolean

    Whether the pool is starting or not.

    workerChoiceStrategiesContext?: WorkerChoiceStrategiesContext<
        Worker,
        Data,
        Response,
    >

    Worker choice strategies context referencing worker choice algorithms implementation.

    workerNodes: IWorkerNode<Worker, Data>[] = []
    • get backPressure(): boolean

      Whether the pool is back pressured or not.

      Returns boolean

      The pool back pressure boolean status.

    • get busy(): boolean

      Whether the pool is busy or not.

      Returns boolean

      The pool busyness boolean status.

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

      The pool type.

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

      Returns "fixed" | "dynamic"

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

      The worker type.

      Returns "cluster" | "thread"

    • Hook executed after task execution for a live worker node. Recovered responses from removed worker nodes do not invoke this hook. Can be overridden.

      Parameters

      • workerNodeKey: number

        The live worker node key.

      • message: MessageValue<Response>

        The received message.

      Returns void

    • Deregisters a listener callback on the worker given its worker node key.

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

    • Parameters

      • Optionaldata: Data
      • Optionalname: string
      • OptionalabortSignal: AbortSignal
      • OptionaltransferList: readonly Transferable[]

      Returns Promise<Response>

    • Gets the worker information given its worker node key.

      Parameters

      • workerNodeKey: number

        The worker node key.

      Returns WorkerInfo | undefined

      The worker information.

    • Parameters

      • data: Iterable<Data>
      • Optionalname: string
      • OptionalabortSignals: Iterable<AbortSignal, any, any>
      • OptionaltransferList: readonly Transferable[]

      Returns Promise<Response[]>

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

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

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

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

    • Parameters

      • workerChoiceStrategy:
            | "FAIR_SHARE"
            | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
            | "LEAST_BUSY"
            | "LEAST_ELU"
            | "LEAST_USED"
            | "ROUND_ROBIN"
            | "WEIGHTED_ROUND_ROBIN"
      • OptionalworkerChoiceStrategyOptions: WorkerChoiceStrategyOptions

      Returns void