Skip to content

Commit 93bf81b

Browse files
authored
Extract perfTest enhancements from #474 (#507)
2 parents 601a66c + 55a85c6 commit 93bf81b

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

Diff for: perfTest/graphile.config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// import "graphile-config";
1+
// @ts-check
22

3-
// import { WorkerProPreset } from "../graphile-pro-worker/dist/index.js";
3+
/** @typedef {import("../dist/index.js")} Worker */
44
// import type {} from "../src/index.js";
55

6+
// import { WorkerProPreset } from "../graphile-pro-worker/dist/index.js";
7+
68
/** @type {GraphileConfig.Preset} */
79
const preset = {
810
// extends: [WorkerProPreset],

Diff for: perfTest/graphile.config.ts

-14
This file was deleted.

Diff for: perfTest/latencyTest.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
// @ts-check
12
const assert = require("assert");
23
const { Pool } = require("pg");
34
const { runTaskList } = require("../dist/main");
45
const { default: deferred } = require("../dist/deferred");
6+
const preset = require("./graphile.config.js");
57

8+
/** @type {(ms: number) => Promise<void>} */
69
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
710

11+
/** @type {import('../dist/index.js').WorkerPoolOptions} */
812
const options = {
913
concurrency: 1,
14+
preset,
1015
};
1116

1217
async function main() {
1318
const pgPool = new Pool({ connectionString: process.env.PERF_DATABASE_URL });
1419
const startTimes = {};
1520
let latencies = [];
1621
const deferreds = {};
22+
/** @type {import('../dist/index.js').TaskList} */
1723
const tasks = {
1824
latency: ({ id }) => {
1925
latencies.push(process.hrtime(startTimes[id]));
@@ -86,6 +92,7 @@ main().catch((e) => {
8692
process.exit(1);
8793
});
8894

95+
/** @type {(pgPool: Pool) => Promise<void>} */
8996
async function forEmptyQueue(pgPool) {
9097
let remaining;
9198
do {

Diff for: perfTest/run.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ async function main() {
5050
console.log();
5151
console.log();
5252
console.log("Timing startup/shutdown time...");
53-
const startupTime = await time(() => {
54-
execSync("node ../dist/cli.js --once", execOptions);
53+
let result;
54+
const startupTime = await time(async () => {
55+
result = await exec(
56+
`node ../dist/cli.js --once -j ${CONCURRENCY} -m ${CONCURRENCY + 1}`,
57+
execOptions,
58+
);
5559
});
60+
logResult(result);
5661
console.log();
5762

5863
if (STUCK_JOB_COUNT > 0) {
@@ -83,17 +88,7 @@ async function main() {
8388
),
8489
);
8590
}
86-
(await Promise.all(promises)).map(({ error, stdout, stderr }) => {
87-
if (error) {
88-
throw error;
89-
}
90-
if (stdout) {
91-
console.log(stdout);
92-
}
93-
if (stderr) {
94-
console.error(stderr);
95-
}
96-
});
91+
(await Promise.all(promises)).map(logResult);
9792
});
9893
console.log(
9994
`Jobs per second: ${((1000 * JOB_COUNT) / (dur - startupTime)).toFixed(2)}`,
@@ -112,3 +107,15 @@ main().catch((e) => {
112107
console.error(e);
113108
process.exit(1);
114109
});
110+
111+
function logResult({ error, stdout, stderr }) {
112+
if (error) {
113+
throw error;
114+
}
115+
if (stdout) {
116+
console.log(stdout);
117+
}
118+
if (stderr) {
119+
console.error(stderr);
120+
}
121+
}

Diff for: perfTest/types.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare global {
2+
namespace GraphileWorker {
3+
interface Tasks {
4+
latency: { id: number };
5+
}
6+
}
7+
}
8+
9+
// Has to be a module, so export something
10+
export type Foo = "Foo";

0 commit comments

Comments
 (0)