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' ;
5
5
6
6
const execAsync = util . promisify ( exec ) ;
7
7
8
8
// Start services and run benchmarks
9
- function killServerOnPort ( port ) {
9
+ function killServerOnPort ( port : number ) : void {
10
10
try {
11
- const pid = execSync ( `lsof -t -i:${ port } ` ) . toString ( ) . trim ( ) ;
11
+ const pid : string = execSync ( `lsof -t -i:${ port } ` ) . toString ( ) . trim ( ) ;
12
12
if ( pid ) {
13
13
execSync ( `kill ${ pid } ` ) ;
14
14
console . log ( `Killed process running on port ${ port } ` ) ;
15
15
} else {
16
16
console . log ( `No process found running on port ${ port } ` ) ;
17
17
}
18
18
} 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 ) ;
20
20
}
21
21
}
22
22
23
- const bench1Results = [ ] ;
24
- const bench2Results = [ ] ;
25
- const bench3Results = [ ] ;
23
+ const bench1Results : string [ ] = [ ] ;
24
+ const bench2Results : string [ ] = [ ] ;
25
+ const bench3Results : string [ ] = [ ] ;
26
26
27
27
killServerOnPort ( 3000 ) ;
28
28
execSync ( 'sh nginx/run.sh' ) ;
29
29
30
- async function runBenchmarkAsync ( serviceScript , bench ) {
30
+ async function runBenchmarkAsync ( serviceScript : string , bench : number ) : Promise < void > {
31
31
let graphqlEndpoint = 'http://localhost:8000/graphql' ;
32
32
if ( serviceScript . includes ( 'hasura' ) ) {
33
33
graphqlEndpoint = 'http://127.0.0.1:8080/v1/graphql' ;
34
34
}
35
-
36
35
const benchmarkScript = 'wrk/bench.sh' ;
37
36
const sanitizedServiceScriptName = serviceScript . replace ( / \/ / g, '_' ) ;
38
37
const resultFiles = [
@@ -54,7 +53,6 @@ async function runBenchmarkAsync(serviceScript, bench) {
54
53
console . log ( `Running benchmark ${ bench } for ${ serviceScript } ` ) ;
55
54
const outputFile = `bench${ bench } _${ resultFile } ` ;
56
55
await execAsync ( `bash ${ benchmarkScript } ${ graphqlEndpoint } ${ bench } > ${ outputFile } ` ) ;
57
-
58
56
if ( bench === 1 ) {
59
57
bench1Results . push ( outputFile ) ;
60
58
} else if ( bench === 2 ) {
@@ -65,21 +63,18 @@ async function runBenchmarkAsync(serviceScript, bench) {
65
63
}
66
64
}
67
65
68
- async function runBenchmark ( serviceScript ) {
66
+ async function runBenchmark ( serviceScript : string ) : Promise < void > {
69
67
killServerOnPort ( 8000 ) ;
70
68
execSync ( 'sleep 5' ) ;
71
-
72
69
if ( serviceScript . includes ( 'hasura' ) ) {
73
70
execSync ( `bash ${ serviceScript } ` , { stdio : 'inherit' } ) ;
74
71
} else {
75
72
execSync ( `bash ${ serviceScript } &` , { stdio : 'inherit' } ) ;
76
73
}
77
-
78
74
execSync ( 'sleep 15' ) ;
79
75
80
76
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 ) ) ;
83
78
await Promise . all ( benchmarkPromises ) ;
84
79
}
85
80
@@ -90,8 +85,8 @@ if (process.argv.length < 3) {
90
85
process . exit ( 1 ) ;
91
86
}
92
87
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' ] ;
95
90
96
91
if ( ! validServices . includes ( service ) ) {
97
92
console . log ( `Invalid service name. Available services: ${ validServices . join ( ', ' ) } ` ) ;
@@ -102,9 +97,8 @@ if (fs.existsSync('results.md')) {
102
97
fs . unlinkSync ( 'results.md' ) ;
103
98
}
104
99
105
- async function main ( ) {
100
+ async function main ( ) : Promise < void > {
106
101
await runBenchmark ( `graphql/${ service } /run.sh` ) ;
107
-
108
102
if ( service === 'apollo_server' ) {
109
103
process . chdir ( 'graphql/apollo_server' ) ;
110
104
execSync ( 'npm stop' ) ;
@@ -114,7 +108,7 @@ async function main() {
114
108
}
115
109
}
116
110
117
- main ( ) . catch ( error => {
111
+ main ( ) . catch ( ( error : Error ) => {
118
112
console . error ( "An error occurred:" , error ) ;
119
113
process . exit ( 1 ) ;
120
- } ) ;
114
+ } ) ;
0 commit comments