Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 2914bbb

Browse files
committed
typescript
1 parent a441d16 commit 2914bbb

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

.github/workflows/bench.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ jobs:
4141
imageName: graphql-benchmarks
4242
push: never
4343
runCmd: |
44-
bash ./graphql/${{ matrix.service }}/setup.sh
44+
45+
bash ./graphql/${{ matrix.service }}/setup.sha
46+
47+
npm install
48+
sudo npm install -g typescript
49+
50+
tsc run_benchmarks.tx
4551
node run_benchmarks.js ${{ matrix.service }}
4652
4753
- name: List benchmark files

run_benchmarks.js renamed to run_benchmarks.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
const { exec, execSync } = require('child_process');
2-
const fs = require('fs');
3-
const path = require('path');
4-
const util = require('util');
1+
import { exec, execSync } from 'child_process';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import * as util from 'util';
55

66
const execAsync = util.promisify(exec);
77

88
// Start services and run benchmarks
9-
function killServerOnPort(port) {
9+
function killServerOnPort(port: number): void {
1010
try {
11-
const pid = execSync(`lsof -t -i:${port}`).toString().trim();
11+
const pid: string = execSync(`lsof -t -i:${port}`).toString().trim();
1212
if (pid) {
1313
execSync(`kill ${pid}`);
1414
console.log(`Killed process running on port ${port}`);
1515
} else {
1616
console.log(`No process found running on port ${port}`);
1717
}
1818
} catch (error) {
19-
console.error(`Error killing server on port ${port}:`, error.message);
19+
console.error(`Error killing server on port ${port}:`, (error as Error).message);
2020
}
2121
}
2222

23-
const bench1Results = [];
24-
const bench2Results = [];
25-
const bench3Results = [];
23+
const bench1Results: string[] = [];
24+
const bench2Results: string[] = [];
25+
const bench3Results: string[] = [];
2626

2727
killServerOnPort(3000);
2828
execSync('sh nginx/run.sh');
2929

30-
async function runBenchmarkAsync(serviceScript, bench) {
30+
async function runBenchmarkAsync(serviceScript: string, bench: number): Promise<void> {
3131
let graphqlEndpoint = 'http://localhost:8000/graphql';
3232
if (serviceScript.includes('hasura')) {
3333
graphqlEndpoint = 'http://127.0.0.1:8080/v1/graphql';
3434
}
35-
3635
const benchmarkScript = 'wrk/bench.sh';
3736
const sanitizedServiceScriptName = serviceScript.replace(/\//g, '_');
3837
const resultFiles = [
@@ -54,7 +53,6 @@ async function runBenchmarkAsync(serviceScript, bench) {
5453
console.log(`Running benchmark ${bench} for ${serviceScript}`);
5554
const outputFile = `bench${bench}_${resultFile}`;
5655
await execAsync(`bash ${benchmarkScript} ${graphqlEndpoint} ${bench} > ${outputFile}`);
57-
5856
if (bench === 1) {
5957
bench1Results.push(outputFile);
6058
} else if (bench === 2) {
@@ -65,21 +63,18 @@ async function runBenchmarkAsync(serviceScript, bench) {
6563
}
6664
}
6765

68-
async function runBenchmark(serviceScript) {
66+
async function runBenchmark(serviceScript: string): Promise<void> {
6967
killServerOnPort(8000);
7068
execSync('sleep 5');
71-
7269
if (serviceScript.includes('hasura')) {
7370
execSync(`bash ${serviceScript}`, { stdio: 'inherit' });
7471
} else {
7572
execSync(`bash ${serviceScript} &`, { stdio: 'inherit' });
7673
}
77-
7874
execSync('sleep 15');
7975

8076
const benchmarks = [1, 2, 3];
81-
const benchmarkPromises = benchmarks.map(bench => runBenchmarkAsync(serviceScript, bench));
82-
77+
const benchmarkPromises: Promise<void>[] = benchmarks.map(bench => runBenchmarkAsync(serviceScript, bench));
8378
await Promise.all(benchmarkPromises);
8479
}
8580

@@ -90,8 +85,8 @@ if (process.argv.length < 3) {
9085
process.exit(1);
9186
}
9287

93-
const service = process.argv[2];
94-
const validServices = ['apollo_server', 'caliban', 'netflix_dgs', 'gqlgen', 'tailcall', 'async_graphql', 'hasura', 'graphql_jit'];
88+
const service: string = process.argv[2];
89+
const validServices: string[] = ['apollo_server', 'caliban', 'netflix_dgs', 'gqlgen', 'tailcall', 'async_graphql', 'hasura', 'graphql_jit'];
9590

9691
if (!validServices.includes(service)) {
9792
console.log(`Invalid service name. Available services: ${validServices.join(', ')}`);
@@ -102,9 +97,8 @@ if (fs.existsSync('results.md')) {
10297
fs.unlinkSync('results.md');
10398
}
10499

105-
async function main() {
100+
async function main(): Promise<void> {
106101
await runBenchmark(`graphql/${service}/run.sh`);
107-
108102
if (service === 'apollo_server') {
109103
process.chdir('graphql/apollo_server');
110104
execSync('npm stop');
@@ -114,7 +108,7 @@ async function main() {
114108
}
115109
}
116110

117-
main().catch(error => {
111+
main().catch((error: Error) => {
118112
console.error("An error occurred:", error);
119113
process.exit(1);
120-
});
114+
});

0 commit comments

Comments
 (0)