Skip to content

Commit 8dee48d

Browse files
committed
Added parallel call overhead benchmarks
1 parent a8c580b commit 8dee48d

5 files changed

Lines changed: 928 additions & 700 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"no-useless-catch": 1,
2626
"no-prototype-builtins": 1,
2727
"no-constant-condition": 0,
28-
"no-useless-escape" : 0,
28+
"no-useless-escape": 0,
2929
"no-console": "error",
3030
"eqeqeq": ["error", "smart"],
3131
"capitalized-comments": [
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const logger = new Logger('WorkerManager Bench', LogLevel.WARN, [
1212
new StreamHandler(),
1313
]);
1414

15-
export default async () => {
15+
async function main() {
1616
const cores = os.cpus().length;
1717
logger.warn(`Cores: ${cores}`);
1818
const workerManager = new WorkerManager<WorkerModule>({ logger });
@@ -34,6 +34,30 @@ export default async () => {
3434
await w.sleep(0);
3535
});
3636
}),
37+
b.add('Parallel (2) Call Overhead', async () => {
38+
// Assuming core count greater or equal to 2
39+
// the performance should be similar to Call Overhead
40+
await Promise.all([
41+
workerManager.call(async (w) => {
42+
await w.sleep(0);
43+
}),
44+
workerManager.call(async (w) => {
45+
await w.sleep(0);
46+
}),
47+
]);
48+
}),
49+
b.add('Parallel (2) Queue Overhead', async () => {
50+
// This should be slightly faster than using call
51+
// This avoids an unnecessary wrapper into Promise
52+
await Promise.all([
53+
workerManager.queue(async (w) => {
54+
await w.sleep(0);
55+
}),
56+
workerManager.queue(async (w) => {
57+
await w.sleep(0);
58+
}),
59+
]);
60+
}),
3761
b.add('JSON stringify of 1 MiB of data', () => {
3862
JSON.stringify(bytes);
3963
}),
@@ -92,4 +116,10 @@ export default async () => {
92116
);
93117
await workerManager.stop();
94118
return summary;
95-
};
119+
}
120+
121+
if (require.main === module) {
122+
main();
123+
}
124+
125+
export default main;

benches/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import fs from 'fs';
44
import si from 'systeminformation';
5-
import WorkerManagerBench from './WorkerManager.bench';
5+
import WorkerManagerBench from './WorkerManager';
66

77
async function main(): Promise<void> {
88
await WorkerManagerBench();

benches/results/WorkerManager.chart.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</head>
1717
<body>
1818
<div style="max-width: 800px">
19-
<canvas id="chart1631766991400" width="16" height="9"></canvas>
19+
<canvas id="chart1631846498465" width="16" height="9"></canvas>
2020
</div>
2121
<script>
2222
const format = (num) => {
@@ -34,14 +34,16 @@
3434

3535
return chunked.map((chunk) => chunk.join("")).join(" ");
3636
};
37-
const ctx1631766991400 = document
38-
.getElementById("chart1631766991400")
37+
const ctx1631846498465 = document
38+
.getElementById("chart1631846498465")
3939
.getContext("2d");
40-
const chart1631766991400 = new Chart(ctx1631766991400, {
40+
const chart1631846498465 = new Chart(ctx1631846498465, {
4141
type: "bar",
4242
data: {
4343
labels: [
4444
"Call Overhead",
45+
"Parallel (2) Call Overhead",
46+
"Parallel (2) Queue Overhead",
4547
"JSON stringify of 1 MiB of data",
4648
"Base64 of 1 MiB of data",
4749
"MD5 Hash of 1 MiB of data",
@@ -52,7 +54,7 @@
5254
],
5355
datasets: [
5456
{
55-
data: [698, 21, 744, 707, 443, 651, 642, 3665],
57+
data: [681, 175, 351, 21, 728, 712, 439, 649, 657, 2614],
5658
backgroundColor: [
5759
"rgba(63, 142, 252, 0.8)",
5860
"rgba(116, 165, 127, 0.8)",
@@ -62,6 +64,8 @@
6264
"rgba(113, 128, 172, 0.8)",
6365
"rgba(182, 140, 184, 0.8)",
6466
"rgba(219, 108, 121, 0.8)",
67+
"rgba(189, 79, 108, 0.8)",
68+
"rgba(138, 79, 125, 0.8)",
6569
],
6670
borderColor: [
6771
"rgba(63, 142, 252, 1)",
@@ -72,6 +76,8 @@
7276
"rgba(113, 128, 172, 1)",
7377
"rgba(182, 140, 184, 1)",
7478
"rgba(219, 108, 121, 1)",
79+
"rgba(189, 79, 108, 1)",
80+
"rgba(138, 79, 125, 1)",
7581
],
7682
borderWidth: 1,
7783
},

0 commit comments

Comments
 (0)