Skip to content

Commit

Permalink
based off the review
Browse files Browse the repository at this point in the history
  • Loading branch information
daveads committed Jul 28, 2024
1 parent 14fb080 commit 4c10b34
Show file tree
Hide file tree
Showing 18 changed files with 531 additions and 245 deletions.
242 changes: 0 additions & 242 deletions analyze.js

This file was deleted.

76 changes: 76 additions & 0 deletions analyze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node
import { execSync } from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
import { servers, formattedServerNames } from './analyze/config';
import { createDirectoryIfNotExists, moveFile, readFileContent } from './analyze/fileUtils';
import { parseServerMetrics } from './analyze/parser';
import { writeMetricsDataFiles } from './analyze/dataFileWriter';
import { generateGnuplotScript, writeGnuplotScript } from './analyze/gnuplotGenerator';
import { formatResults, writeResults } from './analyze/resultsFormatter';

const resultFiles: string[] = process.argv.slice(2);

// Read content of result files
const resultContents: string[] = resultFiles.map(file => readFileContent(file));

const serverMetrics = parseServerMetrics(servers, resultContents);

writeMetricsDataFiles(serverMetrics, servers);

let whichBench = 1;
if (resultFiles.length > 0) {
if (resultFiles[0].startsWith("bench2")) {
whichBench = 2;
} else if (resultFiles[0].startsWith("bench3")) {
whichBench = 3;
}
}

function getMaxValue(data: string): number {
try {
return Math.max(...data.split('\n')
.slice(1)
.map(line => {
const [, valueStr] = line.split(' ');
const value = parseFloat(valueStr);
if (isNaN(value)) {
throw new Error(`Invalid number in data: ${valueStr}`);
}
return value;
}));
} catch (error) {
console.error(`Error getting max value: ${(error as Error).message}`);
return 0;
}
}

const reqSecMax = getMaxValue(readFileContent('/tmp/reqSec.dat')) * 1.2;
const latencyMax = getMaxValue(readFileContent('/tmp/latency.dat')) * 1.2;

const gnuplotScript = generateGnuplotScript(whichBench, reqSecMax, latencyMax);
writeGnuplotScript(gnuplotScript);

try {
execSync(`gnuplot /tmp/gnuplot_script.gp`, { stdio: 'inherit' });
console.log('Gnuplot executed successfully');
} catch (error) {
console.error('Error executing gnuplot:', (error as Error).message);
}

const assetsDir = path.join(__dirname, "assets");
createDirectoryIfNotExists(assetsDir);

moveFile(`req_sec_histogram${whichBench}.png`, path.join(assetsDir, `req_sec_histogram${whichBench}.png`));
moveFile(`latency_histogram${whichBench}.png`, path.join(assetsDir, `latency_histogram${whichBench}.png`));

const resultsTable = formatResults(serverMetrics, formattedServerNames, whichBench);
writeResults(resultsTable, whichBench);

resultFiles.forEach((file) => {
try {
fs.unlinkSync(file);
} catch (error) {
console.error(`Error deleting file ${file}: ${(error as Error).message}`);
}
});
14 changes: 14 additions & 0 deletions analyze/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.servers = exports.formattedServerNames = void 0;
exports.formattedServerNames = {
tailcall: "Tailcall",
gqlgen: "Gqlgen",
apollo: "Apollo GraphQL",
netflixdgs: "Netflix DGS",
caliban: "Caliban",
async_graphql: "async-graphql",
hasura: "Hasura",
graphql_jit: "GraphQL JIT",
};
exports.servers = ["apollo", "caliban", "netflixdgs", "gqlgen", "tailcall", "async_graphql", "hasura", "graphql_jit"];
14 changes: 14 additions & 0 deletions analyze/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FormattedServerNames } from './types';

export const formattedServerNames: FormattedServerNames = {
tailcall: "Tailcall",
gqlgen: "Gqlgen",
apollo: "Apollo GraphQL",
netflixdgs: "Netflix DGS",
caliban: "Caliban",
async_graphql: "async-graphql",
hasura: "Hasura",
graphql_jit: "GraphQL JIT",
};

export const servers: string[] = ["apollo", "caliban", "netflixdgs", "gqlgen", "tailcall", "async_graphql", "hasura", "graphql_jit"];
10 changes: 10 additions & 0 deletions analyze/dataFileWriter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeMetricsDataFiles = writeMetricsDataFiles;
var fileUtils_1 = require("./fileUtils");
function writeMetricsDataFiles(serverMetrics, servers) {
var reqSecData = "/tmp/reqSec.dat";
var latencyData = "/tmp/latency.dat";
(0, fileUtils_1.writeDataFile)(reqSecData, "Server Value\n" + servers.map(function (server) { return "".concat(server, " ").concat(serverMetrics[server].reqSec); }).join('\n'));
(0, fileUtils_1.writeDataFile)(latencyData, "Server Value\n" + servers.map(function (server) { return "".concat(server, " ").concat(serverMetrics[server].latency); }).join('\n'));
}
10 changes: 10 additions & 0 deletions analyze/dataFileWriter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { writeDataFile } from './fileUtils';
import { ServerMetrics } from './types';

export function writeMetricsDataFiles(serverMetrics: Record<string, ServerMetrics>, servers: string[]): void {
const reqSecData = "/tmp/reqSec.dat";
const latencyData = "/tmp/latency.dat";

writeDataFile(reqSecData, "Server Value\n" + servers.map(server => `${server} ${serverMetrics[server].reqSec}`).join('\n'));
writeDataFile(latencyData, "Server Value\n" + servers.map(server => `${server} ${serverMetrics[server].latency}`).join('\n'));
}
Loading

1 comment on commit 4c10b34

@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,362.20 3.39 254.82x
[async-graphql] 2,000.36 50.18 17.36x
[Caliban] 1,648.10 60.39 14.30x
[GraphQL JIT] 1,330.08 74.81 11.54x
[Gqlgen] 778.96 127.36 6.76x
[Netflix DGS] 368.91 220.58 3.20x
[Apollo GraphQL] 262.50 374.94 2.28x
[Hasura] 115.23 565.87 1.00x
2 { posts { title }}
[Tailcall] 57,987.30 1.71 68.87x
[async-graphql] 9,720.48 10.48 11.54x
[Caliban] 9,478.06 10.92 11.26x
[Gqlgen] 2,173.76 47.59 2.58x
[Apollo GraphQL] 1,730.98 57.69 2.06x
[Netflix DGS] 1,615.09 69.93 1.92x
[GraphQL JIT] 1,358.33 73.51 1.61x
[Hasura] 841.98 118.47 1.00x
3 { greet }
[Caliban] 67,796.20 1.07 25.61x
[Tailcall] 58,066.80 1.74 21.94x
[async-graphql] 47,524.50 2.12 17.96x
[Gqlgen] 46,781.00 5.19 17.67x
[Netflix DGS] 8,394.70 14.69 3.17x
[Apollo GraphQL] 7,949.55 12.74 3.00x
[GraphQL JIT] 5,225.25 19.12 1.97x
[Hasura] 2,646.78 37.79 1.00x

Please sign in to comment.