Skip to content

Commit 3e3414f

Browse files
committed
benchmark: control HTTP benchmarks run time
PR-URL: #12121 Refs: #12068 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a3e71a8 commit 3e3414f

9 files changed

+27
-32
lines changed

benchmark/http/_http_simple.js benchmark/fixtures/simple-http-server.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
var http = require('http');
44

5-
var port = parseInt(process.env.PORT || 8000);
6-
75
var fixed = 'C'.repeat(20 * 1024);
86
var storedBytes = Object.create(null);
97
var storedBuffer = Object.create(null);
@@ -22,7 +20,7 @@ if (useDomains) {
2220
gdom.enter();
2321
}
2422

25-
var server = module.exports = http.createServer(function(req, res) {
23+
module.exports = http.createServer(function(req, res) {
2624
if (useDomains) {
2725
var dom = domain.create();
2826
dom.add(req);
@@ -142,8 +140,3 @@ var server = module.exports = http.createServer(function(req, res) {
142140
res.end(body);
143141
}
144142
});
145-
146-
server.listen(port, function() {
147-
if (module === require.main)
148-
console.error('Listening at http://127.0.0.1:' + port + '/');
149-
});

benchmark/http/_chunky_http_client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ var test = require('../../test/common.js');
77

88
var bench = common.createBenchmark(main, {
99
len: [1, 4, 8, 16, 32, 64, 128],
10-
num: [5, 50, 500, 2000],
10+
n: [5, 50, 500, 2000],
1111
type: ['send'],
1212
});
1313

1414

1515
function main(conf) {
1616
var len = +conf.len;
17-
var num = +conf.num;
17+
var num = +conf.n;
1818
var todo = [];
1919
var headers = [];
2020
// Chose 7 because 9 showed "Connection error" / "Connection closed"

benchmark/http/bench-parser.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
1010
const CRLF = '\r\n';
1111

1212
const bench = common.createBenchmark(main, {
13-
fields: [4, 8, 16, 32],
13+
len: [4, 8, 16, 32],
1414
n: [1e5],
1515
});
1616

1717

1818
function main(conf) {
19-
const fields = conf.fields >>> 0;
19+
const len = conf.len >>> 0;
2020
const n = conf.n >>> 0;
2121
var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
2222

23-
for (var i = 0; i < fields; i++) {
23+
for (var i = 0; i < len; i++) {
2424
header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`;
2525
}
2626
header += CRLF;

benchmark/http/chunked.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
var common = require('../common.js');
1212

1313
var bench = common.createBenchmark(main, {
14-
num: [1, 4, 8, 16],
15-
size: [1, 64, 256],
14+
n: [1, 4, 8, 16],
15+
len: [1, 64, 256],
1616
c: [100]
1717
});
1818

1919
function main(conf) {
2020
const http = require('http');
21-
var chunk = Buffer.alloc(conf.size, '8');
21+
var chunk = Buffer.alloc(conf.len, '8');
2222

2323
var server = http.createServer(function(req, res) {
2424
function send(left) {
@@ -28,7 +28,7 @@ function main(conf) {
2828
send(left - 1);
2929
}, 0);
3030
}
31-
send(conf.num);
31+
send(conf.n);
3232
});
3333

3434
server.listen(common.PORT, function() {

benchmark/http/client-request-body.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ var http = require('http');
77
var bench = common.createBenchmark(main, {
88
dur: [5],
99
type: ['asc', 'utf', 'buf'],
10-
bytes: [32, 256, 1024],
10+
len: [32, 256, 1024],
1111
method: ['write', 'end']
1212
});
1313

1414
function main(conf) {
1515
var dur = +conf.dur;
16-
var len = +conf.bytes;
16+
var len = +conf.len;
1717

1818
var encoding;
1919
var chunk;

benchmark/http/cluster.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ if (cluster.isMaster) {
77
var bench = common.createBenchmark(main, {
88
// unicode confuses ab on os x.
99
type: ['bytes', 'buffer'],
10-
length: [4, 1024, 102400],
10+
len: [4, 1024, 102400],
1111
c: [50, 500]
1212
});
1313
} else {
14-
require('./_http_simple.js');
14+
var port = parseInt(process.env.PORT || PORT);
15+
require('../fixtures/simple-http-server.js').listen(port);
1516
}
1617

1718
function main(conf) {
@@ -26,7 +27,7 @@ function main(conf) {
2627
return;
2728

2829
setTimeout(function() {
29-
var path = '/' + conf.type + '/' + conf.length;
30+
var path = '/' + conf.type + '/' + conf.len;
3031

3132
bench.http({
3233
path: path,

benchmark/http/create-clientrequest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ var common = require('../common.js');
44
var ClientRequest = require('http').ClientRequest;
55

66
var bench = common.createBenchmark(main, {
7-
pathlen: [1, 8, 16, 32, 64, 128],
7+
len: [1, 8, 16, 32, 64, 128],
88
n: [1e6]
99
});
1010

1111
function main(conf) {
12-
var pathlen = +conf.pathlen;
12+
var len = +conf.len;
1313
var n = +conf.n;
1414

15-
var path = '/'.repeat(pathlen);
15+
var path = '/'.repeat(len);
1616
var opts = { path: path, createConnection: function() {} };
1717

1818
bench.start();

benchmark/http/end-vs-write-end.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ var common = require('../common.js');
1212

1313
var bench = common.createBenchmark(main, {
1414
type: ['asc', 'utf', 'buf'],
15-
kb: [64, 128, 256, 1024],
15+
len: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024],
1616
c: [100],
1717
method: ['write', 'end']
1818
});
1919

2020
function main(conf) {
2121
const http = require('http');
2222
var chunk;
23-
var len = conf.kb * 1024;
23+
var len = conf.len;
2424
switch (conf.type) {
2525
case 'buf':
2626
chunk = Buffer.alloc(len, 'x');

benchmark/http/simple.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ var PORT = common.PORT;
55
var bench = common.createBenchmark(main, {
66
// unicode confuses ab on os x.
77
type: ['bytes', 'buffer'],
8-
length: [4, 1024, 102400],
8+
len: [4, 1024, 102400],
99
chunks: [0, 1, 4], // chunks=0 means 'no chunked encoding'.
1010
c: [50, 500],
1111
res: ['normal', 'setHeader', 'setHeaderWH']
1212
});
1313

1414
function main(conf) {
1515
process.env.PORT = PORT;
16-
var server = require('./_http_simple.js');
17-
setTimeout(function() {
18-
var path = '/' + conf.type + '/' + conf.length + '/' + conf.chunks + '/' +
16+
var server = require('../fixtures/simple-http-server.js')
17+
.listen(process.env.PORT || common.PORT)
18+
.on('listening', function() {
19+
var path = '/' + conf.type + '/' + conf.len + '/' + conf.chunks + '/' +
1920
conf.res;
2021

2122
bench.http({
@@ -24,5 +25,5 @@ function main(conf) {
2425
}, function() {
2526
server.close();
2627
});
27-
}, 2000);
28+
});
2829
}

0 commit comments

Comments
 (0)