@@ -43,9 +43,8 @@ class AutocannonBenchmarker{
4343}
4444if ( ! result || ! result . requests || ! result . requests . average ) {
4545return undefined ;
46- } else {
47- return result . requests . average ;
4846}
47+ return result . requests . average ;
4948}
5049}
5150
@@ -58,10 +57,13 @@ class WrkBenchmarker{
5857}
5958
6059create ( options ) {
60+ const duration = typeof options . duration === 'number' ?
61+ Math . max ( options . duration , 1 ) :
62+ options . duration ;
6163const args = [
62- '-d' , options . duration ,
64+ '-d' , duration ,
6365'-c' , options . connections ,
64- '-t' , 8 ,
66+ '-t' , Math . min ( options . connections , require ( 'os' ) . cpus ( ) . length || 8 ) ,
6567`http://127.0.0.1:${ options . port } ${ options . path } ` ,
6668] ;
6769for ( const field in options . headers ) {
@@ -77,9 +79,8 @@ class WrkBenchmarker{
7779const throughput = match && + match [ 1 ] ;
7880if ( ! isFinite ( throughput ) ) {
7981return undefined ;
80- } else {
81- return throughput ;
8282}
83+ return throughput ;
8384}
8485}
8586
@@ -89,18 +90,21 @@ class WrkBenchmarker{
8990 */
9091class TestDoubleBenchmarker {
9192constructor ( 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'.
9395this . name = `test-double-${ type } ` ;
9496this . executable = path . resolve ( __dirname , '_test-double-benchmarker.js' ) ;
9597this . present = fs . existsSync ( this . executable ) ;
9698this . type = type ;
9799}
98100
99101create ( options ) {
100- const env = Object . assign ( {
101- duration : options . duration ,
102+ process . env . duration = process . env . duration || options . duration || 5 ;
103+
104+ const env = {
102105test_url : `http://127.0.0.1:${ options . port } ${ options . path } ` ,
103- } , process . env ) ;
106+ ...process . env
107+ } ;
104108
105109const child = child_process . fork ( this . executable ,
106110[ this . type ] ,
@@ -189,13 +193,14 @@ http_benchmarkers.forEach((benchmarker) =>{
189193} ) ;
190194
191195exports . run = function ( options , callback ) {
192- options = Object . assign ( {
196+ options = {
193197port : exports . PORT ,
194198path : '/' ,
195199connections : 100 ,
196200duration : 5 ,
197201benchmarker : exports . default_http_benchmarker ,
198- } , options ) ;
202+ ...options
203+ } ;
199204if ( ! options . benchmarker ) {
200205callback ( new Error ( 'Could not locate required http benchmarker. See ' +
201206`${ requirementsURL } for further instructions.` ) ) ;
@@ -220,7 +225,8 @@ exports.run = function(options, callback){
220225child . stderr . pipe ( process . stderr ) ;
221226
222227let stdout = '' ;
223- child . stdout . on ( 'data' , ( chunk ) => stdout += chunk . toString ( ) ) ;
228+ child . stdout . setEncoding ( 'utf8' ) ;
229+ child . stdout . on ( 'data' , ( chunk ) => stdout += chunk ) ;
224230
225231child . once ( 'close' , ( code ) => {
226232const elapsed = process . hrtime ( benchmarker_start ) ;
0 commit comments