ErrorHandler,
ExitHandler,
IWorker,
+ MeasurementStatistics,
MessageHandler,
OnlineHandler,
Task,
- WorkerUsage,
- WorkerNode
+ TaskStatistics,
+ WorkerNode,
+ WorkerUsage
} from './pools/worker'
export { WorkerChoiceStrategies } from './pools/selection-strategies/selection-strategies-types'
export type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
} from './pools/selection-strategies/selection-strategies-types'
Draft,
MessageValue,
PromiseResponseWrapper,
+ TaskError,
TaskPerformance,
WorkerStatistics
} from './utility-types'
workerUsage: WorkerUsage,
message: MessageValue<Response>
): void {
- if (this.workerChoiceStrategyContext.getTaskStatistics().runTime) {
+ if (
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+ ) {
workerUsage.runTime.aggregation += message.taskPerformance?.runTime ?? 0
if (
- this.workerChoiceStrategyContext.getTaskStatistics().avgRunTime &&
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .avgRunTime &&
workerUsage.tasks.executed !== 0
) {
workerUsage.runTime.average =
workerUsage.runTime.aggregation / workerUsage.tasks.executed
}
if (
- this.workerChoiceStrategyContext.getTaskStatistics().medRunTime &&
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .medRunTime &&
message.taskPerformance?.runTime != null
) {
workerUsage.runTime.history.push(message.taskPerformance.runTime)
workerUsage: WorkerUsage,
message: MessageValue<Response>
): void {
- if (this.workerChoiceStrategyContext.getTaskStatistics().waitTime) {
+ if (
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements().waitTime
+ ) {
workerUsage.waitTime.aggregation += message.taskPerformance?.waitTime ?? 0
if (
- this.workerChoiceStrategyContext.getTaskStatistics().avgWaitTime &&
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .avgWaitTime &&
workerUsage.tasks.executed !== 0
) {
workerUsage.waitTime.average =
workerUsage.waitTime.aggregation / workerUsage.tasks.executed
}
if (
- this.workerChoiceStrategyContext.getTaskStatistics().medWaitTime &&
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .medWaitTime &&
message.taskPerformance?.waitTime != null
) {
workerUsage.waitTime.history.push(message.taskPerformance.waitTime)
workerTasksUsage: WorkerUsage,
message: MessageValue<Response>
): void {
- if (this.workerChoiceStrategyContext.getTaskStatistics().elu) {
+ if (this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu) {
if (
workerTasksUsage.elu != null &&
message.taskPerformance?.elu != null
private setWorkerStatistics (worker: Worker): void {
this.sendToWorker(worker, {
statistics: {
- runTime: this.workerChoiceStrategyContext.getTaskStatistics().runTime,
- waitTime: this.workerChoiceStrategyContext.getTaskStatistics().waitTime,
- elu: this.workerChoiceStrategyContext.getTaskStatistics().elu
+ runTime:
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .runTime,
+ waitTime:
+ this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .waitTime,
+ elu: this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ .elu
}
})
}
import type { IWorker } from '../worker'
import type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
*/
private toggleFindLastFreeWorkerNodeKey: boolean = false
/** @inheritDoc */
- public readonly taskStatistics: TaskStatistics = {
+ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
runTime: false,
avgRunTime: false,
medRunTime: false,
}
protected setTaskStatistics (opts: WorkerChoiceStrategyOptions): void {
- if (this.taskStatistics.avgRunTime && opts.medRunTime === true) {
- this.taskStatistics.avgRunTime = false
- this.taskStatistics.medRunTime = opts.medRunTime as boolean
+ if (
+ this.taskStatisticsRequirements.avgRunTime &&
+ opts.medRunTime === true
+ ) {
+ this.taskStatisticsRequirements.avgRunTime = false
+ this.taskStatisticsRequirements.medRunTime = opts.medRunTime as boolean
}
- if (this.taskStatistics.medRunTime && opts.medRunTime === false) {
- this.taskStatistics.avgRunTime = true
- this.taskStatistics.medRunTime = opts.medRunTime as boolean
+ if (
+ this.taskStatisticsRequirements.medRunTime &&
+ opts.medRunTime === false
+ ) {
+ this.taskStatisticsRequirements.avgRunTime = true
+ this.taskStatisticsRequirements.medRunTime = opts.medRunTime as boolean
}
- if (this.taskStatistics.avgWaitTime && opts.medWaitTime === true) {
- this.taskStatistics.avgWaitTime = false
- this.taskStatistics.medWaitTime = opts.medWaitTime as boolean
+ if (
+ this.taskStatisticsRequirements.avgWaitTime &&
+ opts.medWaitTime === true
+ ) {
+ this.taskStatisticsRequirements.avgWaitTime = false
+ this.taskStatisticsRequirements.medWaitTime = opts.medWaitTime as boolean
}
- if (this.taskStatistics.medWaitTime && opts.medWaitTime === false) {
- this.taskStatistics.avgWaitTime = true
- this.taskStatistics.medWaitTime = opts.medWaitTime as boolean
+ if (
+ this.taskStatisticsRequirements.medWaitTime &&
+ opts.medWaitTime === false
+ ) {
+ this.taskStatisticsRequirements.avgWaitTime = true
+ this.taskStatisticsRequirements.medWaitTime = opts.medWaitTime as boolean
}
}
/**
* Gets the worker task runtime.
- * If the task statistics wants `avgRunTime`, the average runtime is returned.
- * If the task statistics wants `medRunTime`, the median runtime is returned.
+ * If the task statistics require `avgRunTime`, the average runtime is returned.
+ * If the task statistics require `medRunTime`, the median runtime is returned.
*
* @param workerNodeKey - The worker node key.
* @returns The worker task runtime.
*/
protected getWorkerTaskRunTime (workerNodeKey: number): number {
- return this.taskStatistics.medRunTime
+ return this.taskStatisticsRequirements.medRunTime
? this.pool.workerNodes[workerNodeKey].workerUsage.runTime.median
: this.pool.workerNodes[workerNodeKey].workerUsage.runTime.average
}
/**
* Gets the worker task wait time.
- * If the task statistics wants `avgWaitTime`, the average wait time is returned.
- * If the task statistics wants `medWaitTime`, the median wait time is returned.
+ * If the task statistics require `avgWaitTime`, the average wait time is returned.
+ * If the task statistics require `medWaitTime`, the median wait time is returned.
*
* @param workerNodeKey - The worker node key.
* @returns The worker task wait time.
*/
protected getWorkerWaitTime (workerNodeKey: number): number {
- return this.taskStatistics.medWaitTime
+ return this.taskStatisticsRequirements.medWaitTime
? this.pool.workerNodes[workerNodeKey].workerUsage.runTime.median
: this.pool.workerNodes[workerNodeKey].workerUsage.runTime.average
}
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
/** @inheritDoc */
- public readonly taskStatistics: TaskStatistics = {
+ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
runTime: true,
avgRunTime: true,
medRunTime: false,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
/** @inheritDoc */
- public readonly taskStatistics: TaskStatistics = {
+ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
runTime: true,
avgRunTime: false,
medRunTime: false,
*
* @internal
*/
-export interface TaskStatistics {
+export interface TaskStatisticsRequirements {
/**
* Require tasks runtime.
*/
*/
export interface IWorkerChoiceStrategy {
/**
- * Required tasks statistics.
+ * Tasks statistics requirements.
*/
- readonly taskStatistics: TaskStatistics
+ readonly taskStatisticsRequirements: TaskStatisticsRequirements
/**
* Resets strategy internals.
*
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
/** @inheritDoc */
- public readonly taskStatistics: TaskStatistics = {
+ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
runTime: true,
avgRunTime: true,
medRunTime: false,
import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- TaskStatistics,
+ TaskStatisticsRequirements,
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
}
/**
- * Gets the worker choice strategy task statistics in the context.
+ * Gets the worker choice strategy task statistics requirements in the context.
*
- * @returns The task statistics.
+ * @returns The task statistics requirements.
*/
- public getTaskStatistics (): TaskStatistics {
+ public getTaskStatisticsRequirements (): TaskStatisticsRequirements {
return (
this.workerChoiceStrategies.get(
this.workerChoiceStrategy
) as IWorkerChoiceStrategy
- ).taskStatistics
+ ).taskStatisticsRequirements
}
/**
medWaitTime: false
})
}
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
.workerChoiceStrategies) {
expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: true })
}
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: false,
medRunTime: true,
.workerChoiceStrategies) {
expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: false })
}
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: true,
avgRunTime: true,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
runTime: false,
avgRunTime: false,
medRunTime: false,
medRunTime: true
}
)
- expect(workerChoiceStrategyContext.getTaskStatistics().avgRunTime).toBe(
- false
- )
- expect(workerChoiceStrategyContext.getTaskStatistics().medRunTime).toBe(
- true
- )
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+ ).toBe(false)
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+ ).toBe(true)
workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool,
wwrWorkerChoiceStrategy,
medRunTime: true
}
)
- expect(workerChoiceStrategyContext.getTaskStatistics().avgRunTime).toBe(
- false
- )
- expect(workerChoiceStrategyContext.getTaskStatistics().medRunTime).toBe(
- true
- )
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+ ).toBe(false)
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+ ).toBe(true)
const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool,
medRunTime: true
}
)
- expect(workerChoiceStrategyContext.getTaskStatistics().avgRunTime).toBe(
- false
- )
- expect(workerChoiceStrategyContext.getTaskStatistics().medRunTime).toBe(
- true
- )
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+ ).toBe(false)
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+ ).toBe(true)
workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool,
fsWorkerChoiceStrategy,
medRunTime: true
}
)
- expect(workerChoiceStrategyContext.getTaskStatistics().avgRunTime).toBe(
- false
- )
- expect(workerChoiceStrategyContext.getTaskStatistics().medRunTime).toBe(
- true
- )
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+ ).toBe(false)
+ expect(
+ workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+ ).toBe(true)
})
})