- Fix race condition between ready and task functions worker message handling at startup.
- Fix duplicate task usage statistics computation per task function.
+- Update task function worker usage statistics if and only if there's at least two different task functions.
### Added
const workerUsage = this.workerNodes[workerNodeKey].usage
++workerUsage.tasks.executing
this.updateWaitTimeWorkerUsage(workerUsage, task)
- if (this.canUpdateTaskWorkerUsage(workerNodeKey)) {
- const taskWorkerUsage = this.workerNodes[
+ if (this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey)) {
+ const taskFunctionWorkerUsage = this.workerNodes[
workerNodeKey
- ].getTaskWorkerUsage(task.name as string) as WorkerUsage
- ++taskWorkerUsage.tasks.executing
- this.updateWaitTimeWorkerUsage(taskWorkerUsage, task)
+ ].getTaskFunctionWorkerUsage(task.name as string) as WorkerUsage
+ ++taskFunctionWorkerUsage.tasks.executing
+ this.updateWaitTimeWorkerUsage(taskFunctionWorkerUsage, task)
}
}
this.updateTaskStatisticsWorkerUsage(workerUsage, message)
this.updateRunTimeWorkerUsage(workerUsage, message)
this.updateEluWorkerUsage(workerUsage, message)
- if (this.canUpdateTaskWorkerUsage(workerNodeKey)) {
- const taskWorkerUsage = this.workerNodes[
+ if (this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey)) {
+ const taskFunctionWorkerUsage = this.workerNodes[
workerNodeKey
- ].getTaskWorkerUsage(
+ ].getTaskFunctionWorkerUsage(
message.taskPerformance?.name ?? DEFAULT_TASK_NAME
) as WorkerUsage
- this.updateTaskStatisticsWorkerUsage(taskWorkerUsage, message)
- this.updateRunTimeWorkerUsage(taskWorkerUsage, message)
- this.updateEluWorkerUsage(taskWorkerUsage, message)
+ this.updateTaskStatisticsWorkerUsage(taskFunctionWorkerUsage, message)
+ this.updateRunTimeWorkerUsage(taskFunctionWorkerUsage, message)
+ this.updateEluWorkerUsage(taskFunctionWorkerUsage, message)
}
}
- private canUpdateTaskWorkerUsage (workerNodeKey: number): boolean {
+ /**
+ * Whether the worker node shall update its task function worker usage or not.
+ *
+ * @param workerNodeKey - The worker node key.
+ * @returns `true` if the worker node shall update its task function worker usage, `false` otherwise.
+ */
+ private shallUpdateTaskFunctionWorkerUsage (workerNodeKey: number): boolean {
const workerInfo = this.getWorkerInfo(workerNodeKey)
return (
Array.isArray(workerInfo.taskFunctions) &&
- workerInfo.taskFunctions.length > 1
+ workerInfo.taskFunctions.length > 2
)
}
public messageChannel?: MessageChannel
/** @inheritdoc */
public usage: WorkerUsage
- private readonly tasksUsage: Map<string, WorkerUsage>
+ private readonly taskFunctionsUsage: Map<string, WorkerUsage>
private readonly tasksQueue: Queue<Task<Data>>
private readonly tasksQueueBackPressureSize: number
this.messageChannel = new MessageChannel()
}
this.usage = this.initWorkerUsage()
- this.tasksUsage = new Map<string, WorkerUsage>()
+ this.taskFunctionsUsage = new Map<string, WorkerUsage>()
this.tasksQueue = new Queue<Task<Data>>()
this.tasksQueueBackPressureSize = Math.pow(poolMaxSize, 2)
}
/** @inheritdoc */
public resetUsage (): void {
this.usage = this.initWorkerUsage()
- this.tasksUsage.clear()
+ this.taskFunctionsUsage.clear()
}
/** @inheritdoc */
}
/** @inheritdoc */
- public getTaskWorkerUsage (name: string): WorkerUsage | undefined {
+ public getTaskFunctionWorkerUsage (name: string): WorkerUsage | undefined {
if (!Array.isArray(this.info.taskFunctions)) {
throw new Error(
- `Cannot get task worker usage for task function name '${name}' when task function names list is not yet defined`
+ `Cannot get task function worker usage for task function name '${name}' when task function names list is not yet defined`
)
}
if (
- name === DEFAULT_TASK_NAME &&
Array.isArray(this.info.taskFunctions) &&
- this.info.taskFunctions.length > 1
+ this.info.taskFunctions.length < 3
) {
+ throw new Error(
+ `Cannot get task function worker usage for task function name '${name}' when task function names list has less than 3 elements`
+ )
+ }
+ if (name === DEFAULT_TASK_NAME) {
name = this.info.taskFunctions[1]
}
- if (!this.tasksUsage.has(name)) {
- this.tasksUsage.set(name, this.initTaskWorkerUsage(name))
+ if (!this.taskFunctionsUsage.has(name)) {
+ this.taskFunctionsUsage.set(name, this.initTaskFunctionWorkerUsage(name))
}
- return this.tasksUsage.get(name)
+ return this.taskFunctionsUsage.get(name)
}
private initWorkerInfo (worker: Worker, workerType: WorkerType): WorkerInfo {
}
}
- private initTaskWorkerUsage (name: string): WorkerUsage {
+ private initTaskFunctionWorkerUsage (name: string): WorkerUsage {
const getTaskQueueSize = (): number => {
let taskQueueSize = 0
for (const task of this.tasksQueue) {
* @param name - The task function name.
* @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
*/
- readonly getTaskWorkerUsage: (name: string) => WorkerUsage | undefined
+ readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined
}