X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=c1af1cf79c99d05e7c803e7d072529301b6d678a;hb=b7ea53bbd96886c5bc95c13943e5c92a3206f8a5;hp=ffe92e0cbaac75b7b041e5cf1c632f826450aed1;hpb=54aa8d5a576b22bfdbebea90021502035a5e1c8c;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index ffe92e0c..c1af1cf7 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -1,7 +1,7 @@ import type { EventEmitter } from 'node:events' import type { MessageChannel, WorkerOptions } from 'node:worker_threads' -import type { CircularArray } from '../circular-array.js' +import type { CircularBuffer } from '../circular-buffer.js' import type { Task, TaskFunctionProperties } from '../utility-types.js' /** @@ -52,6 +52,11 @@ export type EventHandler = | ErrorHandler | ExitHandler +/** + * Measurement history size. + */ +export const MeasurementHistorySize = 386 + /** * Measurement statistics. * @@ -81,7 +86,7 @@ export interface MeasurementStatistics { /** * Measurement history. */ - readonly history: CircularArray + readonly history: CircularBuffer } /** @@ -172,6 +177,11 @@ export interface WorkerInfo { * This flag is set to `true` when worker node is stealing tasks from another worker node. */ stealing: boolean + /** + * Back pressure flag. + * This flag is set to `true` when worker node tasks queue has back pressure. + */ + backPressure: boolean /** * Task functions properties. */ @@ -267,6 +277,8 @@ export interface WorkerNodeOptions { workerOptions?: WorkerOptions env?: Record tasksQueueBackPressureSize: number | undefined + tasksQueueBucketSize: number | undefined + tasksQueuePriority: boolean | undefined } /** @@ -304,6 +316,12 @@ export interface IWorkerNode * This is the number of tasks that can be enqueued before the worker node has back pressure. */ tasksQueueBackPressureSize: number + /** + * Sets tasks queue priority. + * + * @param enablePriority - Whether to enable tasks queue priority. + */ + readonly setTasksQueuePriority: (enablePriority: boolean) => void /** * Tasks queue size. * @@ -317,25 +335,19 @@ export interface IWorkerNode * @returns The tasks queue size. */ readonly enqueueTask: (task: Task) => number - /** - * Prepends a task to the tasks queue. - * - * @param task - The task to prepend. - * @returns The tasks queue size. - */ - readonly unshiftTask: (task: Task) => number /** * Dequeue task. * + * @param bucket - The prioritized bucket to dequeue from. @defaultValue 0 * @returns The dequeued task. */ - readonly dequeueTask: () => Task | undefined + readonly dequeueTask: (bucket?: number) => Task | undefined /** - * Pops a task from the tasks queue. + * Dequeue last prioritized task. * - * @returns The popped task. + * @returns The dequeued task. */ - readonly popTask: () => Task | undefined + readonly dequeueLastPrioritizedTask: () => Task | undefined /** * Clears tasks queue. */