@@ -43,9 +43,8 @@ class AutocannonBenchmarker {
43
43
}
44
44
if ( ! result || ! result . requests || ! result . requests . average ) {
45
45
return undefined ;
46
- } else {
47
- return result . requests . average ;
48
46
}
47
+ return result . requests . average ;
49
48
}
50
49
}
51
50
@@ -58,10 +57,13 @@ class WrkBenchmarker {
58
57
}
59
58
60
59
create ( options ) {
60
+ const duration = typeof options . duration === 'number' ?
61
+ Math . max ( options . duration , 1 ) :
62
+ options . duration ;
61
63
const args = [
62
- '-d' , options . duration ,
64
+ '-d' , duration ,
63
65
'-c' , options . connections ,
64
- '-t' , 8 ,
66
+ '-t' , Math . min ( options . connections , require ( 'os' ) . cpus ( ) . length || 8 ) ,
65
67
`http://127.0.0.1:${ options . port } ${ options . path } ` ,
66
68
] ;
67
69
for ( const field in options . headers ) {
@@ -77,9 +79,8 @@ class WrkBenchmarker {
77
79
const throughput = match && + match [ 1 ] ;
78
80
if ( ! isFinite ( throughput ) ) {
79
81
return undefined ;
80
- } else {
81
- return throughput ;
82
82
}
83
+ return throughput ;
83
84
}
84
85
}
85
86
@@ -89,18 +90,21 @@ class WrkBenchmarker {
89
90
*/
90
91
class TestDoubleBenchmarker {
91
92
constructor ( type ) {
92
- // `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
93
+ // `type` is the type of benchmarker. Possible values are 'http' and
94
+ // 'http2'.
93
95
this . name = `test-double-${ type } ` ;
94
96
this . executable = path . resolve ( __dirname , '_test-double-benchmarker.js' ) ;
95
97
this . present = fs . existsSync ( this . executable ) ;
96
98
this . type = type ;
97
99
}
98
100
99
101
create ( options ) {
100
- const env = Object . assign ( {
101
- duration : options . duration ,
102
+ process . env . duration = process . env . duration || options . duration || 5 ;
103
+
104
+ const env = {
102
105
test_url : `http://127.0.0.1:${ options . port } ${ options . path } ` ,
103
- } , process . env ) ;
106
+ ...process . env
107
+ } ;
104
108
105
109
const child = child_process . fork ( this . executable ,
106
110
[ this . type ] ,
@@ -189,13 +193,14 @@ http_benchmarkers.forEach((benchmarker) => {
189
193
} ) ;
190
194
191
195
exports . run = function ( options , callback ) {
192
- options = Object . assign ( {
196
+ options = {
193
197
port : exports . PORT ,
194
198
path : '/' ,
195
199
connections : 100 ,
196
200
duration : 5 ,
197
201
benchmarker : exports . default_http_benchmarker ,
198
- } , options ) ;
202
+ ...options
203
+ } ;
199
204
if ( ! options . benchmarker ) {
200
205
callback ( new Error ( 'Could not locate required http benchmarker. See ' +
201
206
`${ requirementsURL } for further instructions.` ) ) ;
@@ -220,7 +225,8 @@ exports.run = function(options, callback) {
220
225
child . stderr . pipe ( process . stderr ) ;
221
226
222
227
let stdout = '' ;
223
- child . stdout . on ( 'data' , ( chunk ) => stdout += chunk . toString ( ) ) ;
228
+ child . stdout . setEncoding ( 'utf8' ) ;
229
+ child . stdout . on ( 'data' , ( chunk ) => stdout += chunk ) ;
224
230
225
231
child . once ( 'close' , ( code ) => {
226
232
const elapsed = process . hrtime ( benchmarker_start ) ;
0 commit comments