X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=03cecce849a2cb9d71ad04a566795d3588238509;hb=0bc53e954d6d832092db4ea6ccea8b0f8f071ebe;hp=14c8dbe1e1d444f5404e8562c1c59ecf1585d869;hpb=023bd558ccd496d78a0ecc281131a6548989865e;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 14c8dbe1..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. */ @@ -211,31 +234,24 @@ export interface IWorkerNode { * Worker info. */ readonly info: WorkerInfo - /** - * Message channel (worker_threads only). - */ - readonly messageChannel?: MessageChannel /** * Worker usage statistics. */ - usage: WorkerUsage + readonly usage: WorkerUsage /** - * Tasks queue back pressure size. - * This is the number of tasks that can be enqueued before the worker node has back pressure. + * Worker choice strategy data. + * This is used to store data that are specific to the worker choice strategy. */ - tasksQueueBackPressureSize: number + strategyData?: StrategyData /** - * Callback invoked when worker node tasks queue is back pressured. - * - * @param workerId - The worker id. + * Message channel (worker_threads only). */ - onBackPressure?: (workerId: number) => void + readonly messageChannel?: MessageChannel /** - * Callback invoked when worker node tasks queue is empty. - * - * @param workerId - The worker id. + * Tasks queue back pressure size. + * This is the number of tasks that can be enqueued before the worker node has back pressure. */ - onEmptyQueue?: (workerId: number) => void + tasksQueueBackPressureSize: number /** * Tasks queue size. * @@ -293,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 }