X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=03cecce849a2cb9d71ad04a566795d3588238509;hb=d91689fda0fa7a85014ac25276cf2cf0a9d81ce2;hp=1d0c4e22e47f073384bdf8c69e3c477ea9cb1d2b;hpb=a25c335d7e5573a171fc96c445cb6092852b2c4a;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 1d0c4e22..03cecce8 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -96,6 +96,10 @@ export interface TaskStatistics { * Maximum number of queued tasks. */ readonly maxQueued?: number + /** + * Number of stolen tasks. + */ + stolen: number /** * Number of failed tasks. */ @@ -128,7 +132,7 @@ export interface WorkerInfo { /** * Worker type. */ - type: WorkerType + readonly type: WorkerType /** * Dynamic flag. */ @@ -140,7 +144,7 @@ export interface WorkerInfo { /** * Task function names. */ - taskFunctions?: string[] + taskFunctionNames?: string[] } /** @@ -167,6 +171,15 @@ export interface WorkerUsage { readonly elu: EventLoopUtilizationMeasurementStatistics } +/** + * Worker choice strategy data. + * + * @internal + */ +export interface StrategyData { + virtualTaskEndTimestamp?: number +} + /** * Worker interface. */ @@ -189,12 +202,21 @@ export interface IWorker { /** * Registers a listener to the exit event that will only be performed once. * - * @param event - `'exit'`. + * @param event - The `'exit'` event. * @param handler - The exit handler. */ readonly once: (event: 'exit', handler: ExitHandler) => void } +/** + * Worker node event detail. + * + * @internal + */ +export interface WorkerNodeEventDetail { + workerId: number +} + /** * Worker node interface. * @@ -202,7 +224,8 @@ export interface IWorker { * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. * @internal */ -export interface IWorkerNode { +export interface IWorkerNode + extends EventTarget { /** * Worker. */ @@ -212,13 +235,23 @@ export interface IWorkerNode { */ readonly info: WorkerInfo /** - * Message channel. + * Worker usage statistics. + */ + readonly usage: WorkerUsage + /** + * Worker choice strategy data. + * This is used to store data that are specific to the worker choice strategy. + */ + strategyData?: StrategyData + /** + * Message channel (worker_threads only). */ readonly messageChannel?: MessageChannel /** - * Worker usage statistics. + * Tasks queue back pressure size. + * This is the number of tasks that can be enqueued before the worker node has back pressure. */ - usage: WorkerUsage + tasksQueueBackPressureSize: number /** * Tasks queue size. * @@ -232,12 +265,25 @@ 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. * * @returns The dequeued task. */ readonly dequeueTask: () => Task | undefined + /** + * Pops a task from the tasks queue. + * + * @returns The popped task. + */ + readonly popTask: () => Task | undefined /** * Clears tasks queue. */ @@ -263,4 +309,11 @@ export interface IWorkerNode { * @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise. */ readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined + /** + * Deletes task function worker usage statistics. + * + * @param name - The task function name. + * @returns `true` if the task function worker usage statistics were deleted, `false` otherwise. + */ + readonly deleteTaskFunctionWorkerUsage: (name: string) => boolean }