Skip to content

Commit b59c461

Browse files
committed
benchmark: control HTTP benchmarks run time
PR-URL: nodejs#12121 Refs: nodejs#12068
1 parent 9432cae commit b59c461

File tree

9 files changed

+27
-32
lines changed

9 files changed

+27
-32
lines changed

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

Lines changed: 1 addition & 8 deletions
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
storedBytes = {},
97
storedBuffer = {},
@@ -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);
@@ -114,8 +112,3 @@ var server = module.exports = http.createServer(function(req, res) {
114112
res.end(body);
115113
}
116114
});
117-
118-
server.listen(port, function() {
119-
if (module === require.main)
120-
console.error('Listening at http://127.0.0.1:' + port + '/');
121-
});

benchmark/http/_chunky_http_client.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ 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
});
1212

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

1920
bench.http({
2021
path: path,
2122
connections: conf.c
2223
}, function() {
2324
server.close();
2425
});
25-
}, 2000);
26+
});
2627
}

0 commit comments

Comments
 (0)