workerNodeKey: number,
task: Task<Data>
): void {
- const workerTasksUsage = this.workerNodes[workerNodeKey].tasksUsage
- ++workerTasksUsage.running
- if (this.workerChoiceStrategyContext.getRequiredStatistics().waitTime) {
- const waitTime = performance.now() - (task.submissionTimestamp ?? 0)
- workerTasksUsage.waitTime += waitTime
- if (
- this.workerChoiceStrategyContext.getRequiredStatistics().medWaitTime
- ) {
- workerTasksUsage.waitTimeHistory.push(waitTime)
- workerTasksUsage.medWaitTime = median(workerTasksUsage.waitTimeHistory)
- }
- }
+ ++this.workerNodes[workerNodeKey].tasksUsage.running
}
/**
workerTasksUsage.medRunTime = median(workerTasksUsage.runTimeHistory)
}
}
- if (
- this.workerChoiceStrategyContext.getRequiredStatistics().waitTime &&
- this.workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime &&
- workerTasksUsage.run !== 0
- ) {
- workerTasksUsage.avgWaitTime =
- workerTasksUsage.waitTime / workerTasksUsage.run
+ if (this.workerChoiceStrategyContext.getRequiredStatistics().waitTime) {
+ workerTasksUsage.waitTime += message.waitTime ?? 0
+ if (
+ this.workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime &&
+ workerTasksUsage.run !== 0
+ ) {
+ workerTasksUsage.avgWaitTime =
+ workerTasksUsage.waitTime / workerTasksUsage.run
+ }
+ if (
+ this.workerChoiceStrategyContext.getRequiredStatistics().medWaitTime &&
+ message.waitTime != null
+ ) {
+ workerTasksUsage.waitTimeHistory.push(message.waitTime)
+ workerTasksUsage.medWaitTime = median(workerTasksUsage.waitTimeHistory)
+ }
}
}
): void {
try {
const startTimestamp = performance.now()
+ const waitTime = startTimestamp - (message.submissionTimestamp ?? 0)
const res = fn(message.data)
const runTime = performance.now() - startTimestamp
this.sendToMainWorker({
data: res,
id: message.id,
- runTime
+ runTime,
+ waitTime
})
} catch (e) {
const err = this.handleError(e as Error)
message: MessageValue<Data>
): void {
const startTimestamp = performance.now()
+ const waitTime = startTimestamp - (message.submissionTimestamp ?? 0)
fn(message.data)
.then(res => {
const runTime = performance.now() - startTimestamp
this.sendToMainWorker({
data: res,
id: message.id,
- runTime
+ runTime,
+ waitTime
})
return null
})