1- import http2 from " node:http2" ;
1+ import http2 from ' node:http2' ;
22
3- const REQUEST_COUNT = parseInt ( process . env . REQUEST_COUNT ?? " 10000" , 10 ) ;
4- const NUM_CONNECTIONS = parseInt ( process . env . NUM_CONNECTIONS ?? "10" , 10 ) ;
5- const BASE_URL = process . env . RUNLOOP_BASE_URL ?? " https://api.runloop.pro" ;
3+ const REQUEST_COUNT = parseInt ( process . env . REQUEST_COUNT ?? ' 10000' , 10 ) ;
4+ const NUM_CONNECTIONS = parseInt ( process . env . NUM_CONNECTIONS ?? '10' , 10 ) ;
5+ const BASE_URL = process . env . RUNLOOP_BASE_URL ?? ' https://api.runloop.pro' ;
66const API_KEY = process . env . RUNLOOP_API_KEY ! ;
77
88const body = JSON . stringify ( {
9- blueprint_id : " bp_nonexistent_loadtest_00000" ,
10- name : " loadtest-h2-0" ,
11- environment_variables : { TEST_VAR_1 : " value_one" , TEST_VAR_2 : " value_two" } ,
12- metadata : { test_run : "h2" , index : "0" } ,
13- launch_parameters : { resource_size_request : " SMALL" , keep_alive_time_seconds : 300 } ,
9+ blueprint_id : ' bp_nonexistent_loadtest_00000' ,
10+ name : ' loadtest-h2-0' ,
11+ environment_variables : { TEST_VAR_1 : ' value_one' , TEST_VAR_2 : ' value_two' } ,
12+ metadata : { test_run : 'h2' , index : '0' } ,
13+ launch_parameters : { resource_size_request : ' SMALL' , keep_alive_time_seconds : 300 } ,
1414} ) ;
1515
1616function percentile ( sorted : number [ ] , p : number ) : number {
@@ -21,44 +21,38 @@ function percentile(sorted: number[], p: number): number {
2121function connectH2 ( origin : string ) : Promise < http2 . ClientHttp2Session > {
2222 return new Promise ( ( resolve , reject ) => {
2323 const client = http2 . connect ( origin ) ;
24- client . on ( " connect" , ( ) => resolve ( client ) ) ;
25- client . on ( " error" , reject ) ;
24+ client . on ( ' connect' , ( ) => resolve ( client ) ) ;
25+ client . on ( ' error' , reject ) ;
2626 } ) ;
2727}
2828
29- function sendRequest (
30- client : http2 . ClientHttp2Session ,
31- ) : Promise < { latencyMs : number ; status : number } > {
29+ function sendRequest ( client : http2 . ClientHttp2Session ) : Promise < { latencyMs : number ; status : number } > {
3230 return new Promise ( ( resolve , reject ) => {
3331 const start = performance . now ( ) ;
3432 const req = client . request ( {
35- " :method" : " POST" ,
36- " :path" : " /v1/devboxes" ,
37- " content-type" : " application/json" ,
33+ ' :method' : ' POST' ,
34+ ' :path' : ' /v1/devboxes' ,
35+ ' content-type' : ' application/json' ,
3836 authorization : `Bearer ${ API_KEY } ` ,
3937 } ) ;
40- req . on ( " response" , ( headers ) => {
41- const status = headers [ " :status" ] as number ;
42- req . on ( " data" , ( ) => { } ) ;
43- req . on ( " end" , ( ) => resolve ( { latencyMs : performance . now ( ) - start , status } ) ) ;
38+ req . on ( ' response' , ( headers ) => {
39+ const status = headers [ ' :status' ] as number ;
40+ req . on ( ' data' , ( ) => { } ) ;
41+ req . on ( ' end' , ( ) => resolve ( { latencyMs : performance . now ( ) - start , status } ) ) ;
4442 } ) ;
45- req . on ( " error" , reject ) ;
43+ req . on ( ' error' , reject ) ;
4644 req . end ( body ) ;
4745 } ) ;
4846}
4947
5048async function main ( ) {
51- console . log (
52- `HTTP/2 test: ${ REQUEST_COUNT } requests, ${ NUM_CONNECTIONS } connections to ${ BASE_URL } ` ,
53- ) ;
49+ console . log ( `HTTP/2 test: ${ REQUEST_COUNT } requests, ${ NUM_CONNECTIONS } connections to ${ BASE_URL } ` ) ;
5450
5551 const url = new URL ( BASE_URL ) ;
56- const clients = await Promise . all (
57- Array . from ( { length : NUM_CONNECTIONS } , ( ) => connectH2 ( url . origin ) ) ,
58- ) ;
52+ const clients = await Promise . all ( Array . from ( { length : NUM_CONNECTIONS } , ( ) => connectH2 ( url . origin ) ) ) ;
5953
6054 const maxStreams = clients [ 0 ] . remoteSettings ?. maxConcurrentStreams ;
61- console . log ( `Server MAX_CONCURRENT_STREAMS: ${ maxStreams ?? " unknown" } ` ) ;
55+ console . log ( `Server MAX_CONCURRENT_STREAMS: ${ maxStreams ?? ' unknown' } ` ) ;
6256 console . log ( `${ NUM_CONNECTIONS } connections established\n` ) ;
6357
6458 let completed = 0 ;
0 commit comments