Skip to content

Commit

Permalink
typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
daveads committed Jul 28, 2024
1 parent a441d16 commit 2914bbb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ jobs:
imageName: graphql-benchmarks
push: never
runCmd: |
bash ./graphql/${{ matrix.service }}/setup.sh
bash ./graphql/${{ matrix.service }}/setup.sha
npm install
sudo npm install -g typescript
tsc run_benchmarks.tx
node run_benchmarks.js ${{ matrix.service }}
- name: List benchmark files
Expand Down
42 changes: 18 additions & 24 deletions run_benchmarks.js → run_benchmarks.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
const { exec, execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const util = require('util');
import { exec, execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';

const execAsync = util.promisify(exec);

// Start services and run benchmarks
function killServerOnPort(port) {
function killServerOnPort(port: number): void {
try {
const pid = execSync(`lsof -t -i:${port}`).toString().trim();
const pid: string = execSync(`lsof -t -i:${port}`).toString().trim();
if (pid) {
execSync(`kill ${pid}`);
console.log(`Killed process running on port ${port}`);
} else {
console.log(`No process found running on port ${port}`);
}
} catch (error) {
console.error(`Error killing server on port ${port}:`, error.message);
console.error(`Error killing server on port ${port}:`, (error as Error).message);
}
}

const bench1Results = [];
const bench2Results = [];
const bench3Results = [];
const bench1Results: string[] = [];
const bench2Results: string[] = [];
const bench3Results: string[] = [];

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

async function runBenchmarkAsync(serviceScript, bench) {
async function runBenchmarkAsync(serviceScript: string, bench: number): Promise<void> {
let graphqlEndpoint = 'http://localhost:8000/graphql';
if (serviceScript.includes('hasura')) {
graphqlEndpoint = 'http://127.0.0.1:8080/v1/graphql';
}

const benchmarkScript = 'wrk/bench.sh';
const sanitizedServiceScriptName = serviceScript.replace(/\//g, '_');
const resultFiles = [
Expand All @@ -54,7 +53,6 @@ async function runBenchmarkAsync(serviceScript, bench) {
console.log(`Running benchmark ${bench} for ${serviceScript}`);
const outputFile = `bench${bench}_${resultFile}`;
await execAsync(`bash ${benchmarkScript} ${graphqlEndpoint} ${bench} > ${outputFile}`);

if (bench === 1) {
bench1Results.push(outputFile);
} else if (bench === 2) {
Expand All @@ -65,21 +63,18 @@ async function runBenchmarkAsync(serviceScript, bench) {
}
}

async function runBenchmark(serviceScript) {
async function runBenchmark(serviceScript: string): Promise<void> {
killServerOnPort(8000);
execSync('sleep 5');

if (serviceScript.includes('hasura')) {
execSync(`bash ${serviceScript}`, { stdio: 'inherit' });
} else {
execSync(`bash ${serviceScript} &`, { stdio: 'inherit' });
}

execSync('sleep 15');

const benchmarks = [1, 2, 3];
const benchmarkPromises = benchmarks.map(bench => runBenchmarkAsync(serviceScript, bench));

const benchmarkPromises: Promise<void>[] = benchmarks.map(bench => runBenchmarkAsync(serviceScript, bench));
await Promise.all(benchmarkPromises);
}

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

const service = process.argv[2];
const validServices = ['apollo_server', 'caliban', 'netflix_dgs', 'gqlgen', 'tailcall', 'async_graphql', 'hasura', 'graphql_jit'];
const service: string = process.argv[2];
const validServices: string[] = ['apollo_server', 'caliban', 'netflix_dgs', 'gqlgen', 'tailcall', 'async_graphql', 'hasura', 'graphql_jit'];

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

async function main() {
async function main(): Promise<void> {
await runBenchmark(`graphql/${service}/run.sh`);

if (service === 'apollo_server') {
process.chdir('graphql/apollo_server');
execSync('npm stop');
Expand All @@ -114,7 +108,7 @@ async function main() {
}
}

main().catch(error => {
main().catch((error: Error) => {
console.error("An error occurred:", error);
process.exit(1);
});
});

1 comment on commit 2914bbb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query Server Requests/sec Latency (ms) Relative
1 { posts { id userId title user { id name email }}}
[Tailcall] 29,872.80 3.33 255.38x
[async-graphql] 2,016.80 49.90 17.24x
[Caliban] 1,396.50 71.25 11.94x
[GraphQL JIT] 1,355.58 73.45 11.59x
[Gqlgen] 802.12 123.74 6.86x
[Netflix DGS] 360.32 182.27 3.08x
[Apollo GraphQL] 261.79 375.37 2.24x
[Hasura] 116.97 665.79 1.00x
2 { posts { title }}
[Tailcall] 58,838.30 1.69 77.45x
[async-graphql] 10,026.40 10.17 13.20x
[Caliban] 8,704.14 11.93 11.46x
[Gqlgen] 2,221.84 46.78 2.92x
[Apollo GraphQL] 1,718.07 58.11 2.26x
[Netflix DGS] 1,575.41 70.70 2.07x
[GraphQL JIT] 1,417.52 70.44 1.87x
[Hasura] 759.72 132.16 1.00x
3 { greet }
[Caliban] 68,048.80 1.09 28.69x
[Tailcall] 59,286.70 1.70 24.99x
[async-graphql] 48,631.30 2.11 20.50x
[Gqlgen] 47,804.70 4.90 20.15x
[Netflix DGS] 8,130.54 14.64 3.43x
[Apollo GraphQL] 7,914.86 12.85 3.34x
[GraphQL JIT] 5,310.41 18.81 2.24x
[Hasura] 2,372.23 42.07 1.00x

Please sign in to comment.