@ -12,8 +12,8 @@ if (common.isWindows) {
return ;
return ;
}
}
var body = 'hello world\n' ;
const body = 'hello world\n' ;
var server = http . createServer ( function ( req , res ) {
const server = http . createServer ( function ( req , res ) {
res . writeHead ( 200 , {
res . writeHead ( 200 , {
'Content-Length' : body . length ,
'Content-Length' : body . length ,
'Content-Type' : 'text/plain'
'Content-Type' : 'text/plain'
@ -22,12 +22,12 @@ var server = http.createServer(function(req, res) {
res . end ( ) ;
res . end ( ) ;
} ) ;
} ) ;
var keepAliveReqSec = 0 ;
let keepAliveReqSec = 0 ;
var normalReqSec = 0 ;
let normalReqSec = 0 ;
function runAb ( opts , callback ) {
function runAb ( opts , callback ) {
var args = [
const args = [
'-c' , opts . concurrent || 100 ,
'-c' , opts . concurrent || 100 ,
'-t' , opts . threads || 2 ,
'-t' , opts . threads || 2 ,
'-d' , opts . duration || '10s' ,
'-d' , opts . duration || '10s' ,
@ -41,13 +41,11 @@ function runAb(opts, callback) {
args . push ( url . format ( { hostname : '127.0.0.1' ,
args . push ( url . format ( { hostname : '127.0.0.1' ,
port : common . PORT , protocol : 'http' } ) ) ;
port : common . PORT , protocol : 'http' } ) ) ;
//console.log(comm, args.join(' '));
const child = spawn ( 'wrk' , args ) ;
var child = spawn ( 'wrk' , args ) ;
child . stderr . pipe ( process . stderr ) ;
child . stderr . pipe ( process . stderr ) ;
child . stdout . setEncoding ( 'utf8' ) ;
child . stdout . setEncoding ( 'utf8' ) ;
var stdout ;
let stdout ;
child . stdout . on ( 'data' , function ( data ) {
child . stdout . on ( 'data' , function ( data ) {
stdout += data ;
stdout += data ;
@ -60,11 +58,11 @@ function runAb(opts, callback) {
return ;
return ;
}
}
var matches = /Requests\/sec:\s*(\d+)\./mi . exec ( stdout ) ;
let matches = /Requests\/sec:\s*(\d+)\./mi . exec ( stdout ) ;
var reqSec = parseInt ( matches [ 1 ] ) ;
const reqSec = parseInt ( matches [ 1 ] ) ;
matches = /Keep-Alive requests:\s*(\d+)/mi . exec ( stdout ) ;
matches = /Keep-Alive requests:\s*(\d+)/mi . exec ( stdout ) ;
var keepAliveRequests ;
let keepAliveRequests ;
if ( matches ) {
if ( matches ) {
keepAliveRequests = parseInt ( matches [ 1 ] ) ;
keepAliveRequests = parseInt ( matches [ 1 ] ) ;
} else {
} else {
@ -75,21 +73,19 @@ function runAb(opts, callback) {
} ) ;
} ) ;
}
}
server . listen ( common . PORT , function ( ) {
server . listen ( common . PORT , ( ) => {
runAb ( { keepalive : true } , function ( reqSec ) {
runAb ( { keepalive : true } , ( reqSec ) => {
keepAliveReqSec = reqSec ;
keepAliveReqSec = reqSec ;
console . log ( 'keep-alive:' , keepAliveReqSec , 'req/sec' ) ;
runAb ( { keepalive : false } , function ( reqSec ) {
runAb ( { keepalive : false } , function ( reqSec ) {
normalReqSec = reqSec ;
normalReqSec = reqSec ;
console . log ( 'normal:' + normalReqSec + ' req/sec' ) ;
server . close ( ) ;
server . close ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
process . on ( 'exit' , function ( ) {
process . on ( 'exit' , function ( ) {
assert . e qual( true , normalReqSec > 50 ) ;
assert . strictE qual( true , normalReqSec > 50 ) ;
assert . e qual( true , keepAliveReqSec > 50 ) ;
assert . strictE qual( true , keepAliveReqSec > 50 ) ;
assert . e qual( true , normalReqSec < keepAliveReqSec ) ;
assert . strictE qual( true , normalReqSec < keepAliveReqSec ) ;
} ) ;
} ) ;