Skip to content

Commit aa63d3d

Browse files
committed
fix: fix worker usage statistics computation
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 2aed691 commit aa63d3d

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

deno.json

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"version": "0.5.1",
44
"exports": "./src/mod.ts",
55
"compilerOptions": {
6-
"lib": [
7-
"deno.worker"
8-
],
6+
"lib": ["deno.worker"],
97
"strict": true
108
},
119
"tasks": {
@@ -26,9 +24,7 @@
2624
"documentation": "deno doc ./src/mod.ts"
2725
},
2826
"test": {
29-
"include": [
30-
"./tests/**/*.test.mjs"
31-
]
27+
"include": ["./tests/**/*.test.mjs"]
3228
},
3329
"fmt": {
3430
"semiColons": false,
@@ -41,18 +37,8 @@
4137
"@std/testing": "jsr:@std/testing@^1.0.14"
4238
},
4339
"publish": {
44-
"include": [
45-
"LICENSE",
46-
"README.md",
47-
"deno.json",
48-
"src/**/*.ts"
49-
]
40+
"include": ["LICENSE", "README.md", "deno.json", "src/**/*.ts"]
5041
},
5142
"lock": false,
52-
"exclude": [
53-
"./coverage",
54-
"./dist/browser",
55-
"./dist/esm",
56-
"./npm"
57-
]
43+
"exclude": ["./coverage", "./dist/browser", "./dist/esm", "./npm"]
5844
}

src/pools/selection-strategies/fair-share-worker-choice-strategy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ export class FairShareWorkerChoiceStrategy<
8181
this.pool.workerNodes[workerNodeKey]?.strategyData
8282
?.virtualTaskEndTimestamp != null
8383
) {
84-
this.pool.workerNodes[workerNodeKey].strategyData
85-
.virtualTaskEndTimestamp = undefined
84+
this.pool.workerNodes[
85+
workerNodeKey
86+
].strategyData.virtualTaskEndTimestamp = undefined
8687
}
8788
return true
8889
}

src/pools/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import worker from '../../examples/deno/typescript/worker.ts'
12
import type { MessageValue, Task } from '../utility-types.ts'
23
import {
34
average,
@@ -277,14 +278,14 @@ const updateMeasurementStatistics = (
277278
measurementStatistics.history.toArray(),
278279
)
279280
} else if (measurementStatistics.average != null) {
280-
delete measurementStatistics.average
281+
measurementStatistics.average = undefined
281282
}
282283
if (measurementRequirements.median) {
283284
measurementStatistics.median = median(
284285
measurementStatistics.history.toArray(),
285286
)
286287
} else if (measurementStatistics.median != null) {
287-
delete measurementStatistics.median
288+
measurementStatistics.median = undefined
288289
}
289290
}
290291
}
@@ -380,13 +381,11 @@ export const updateEluWorkerUsage = <
380381
)
381382
if (eluTaskStatisticsRequirements?.aggregate === true) {
382383
if (message.taskPerformance?.elu != null) {
383-
if (workerUsage.elu.utilization != null) {
384-
workerUsage.elu.utilization = (workerUsage.elu.utilization +
384+
workerUsage.elu.count = (workerUsage.elu.count ?? 0) + 1
385+
workerUsage.elu.utilization =
386+
((workerUsage.elu.utilization ?? 0) * (workerUsage.elu.count - 1) +
385387
message.taskPerformance.elu.utilization) /
386-
2
387-
} else {
388-
workerUsage.elu.utilization = message.taskPerformance.elu.utilization
389-
}
388+
workerUsage.elu.count
390389
}
391390
}
392391
}

src/pools/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ export interface MeasurementStatistics {
6666
* @internal
6767
*/
6868
export interface EventLoopUtilizationMeasurementStatistics {
69-
readonly idle: MeasurementStatistics
7069
readonly active: MeasurementStatistics
70+
count?: number
71+
readonly idle: MeasurementStatistics
7172
utilization?: number
7273
}
7374

0 commit comments

Comments
 (0)