Browse Source

benchmark: control HTTP benchmarks run time

PR-URL: https://github.com/nodejs/node/pull/12121
Refs: https://github.com/nodejs/node/issues/12068
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Joyee Cheung 8 years ago
parent
commit
3e3414f45f
  1. 9
      benchmark/fixtures/simple-http-server.js
  2. 4
      benchmark/http/_chunky_http_client.js
  3. 6
      benchmark/http/bench-parser.js
  4. 8
      benchmark/http/chunked.js
  5. 4
      benchmark/http/client-request-body.js
  6. 7
      benchmark/http/cluster.js
  7. 6
      benchmark/http/create-clientrequest.js
  8. 4
      benchmark/http/end-vs-write-end.js
  9. 11
      benchmark/http/simple.js

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

@ -2,8 +2,6 @@
var http = require('http'); var http = require('http');
var port = parseInt(process.env.PORT || 8000);
var fixed = 'C'.repeat(20 * 1024); var fixed = 'C'.repeat(20 * 1024);
var storedBytes = Object.create(null); var storedBytes = Object.create(null);
var storedBuffer = Object.create(null); var storedBuffer = Object.create(null);
@ -22,7 +20,7 @@ if (useDomains) {
gdom.enter(); gdom.enter();
} }
var server = module.exports = http.createServer(function(req, res) { module.exports = http.createServer(function(req, res) {
if (useDomains) { if (useDomains) {
var dom = domain.create(); var dom = domain.create();
dom.add(req); dom.add(req);
@ -142,8 +140,3 @@ var server = module.exports = http.createServer(function(req, res) {
res.end(body); res.end(body);
} }
}); });
server.listen(port, function() {
if (module === require.main)
console.error('Listening at http://127.0.0.1:' + port + '/');
});

4
benchmark/http/_chunky_http_client.js

@ -7,14 +7,14 @@ var test = require('../../test/common.js');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
len: [1, 4, 8, 16, 32, 64, 128], len: [1, 4, 8, 16, 32, 64, 128],
num: [5, 50, 500, 2000], n: [5, 50, 500, 2000],
type: ['send'], type: ['send'],
}); });
function main(conf) { function main(conf) {
var len = +conf.len; var len = +conf.len;
var num = +conf.num; var num = +conf.n;
var todo = []; var todo = [];
var headers = []; var headers = [];
// Chose 7 because 9 showed "Connection error" / "Connection closed" // Chose 7 because 9 showed "Connection error" / "Connection closed"

6
benchmark/http/bench-parser.js

@ -10,17 +10,17 @@ const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
const CRLF = '\r\n'; const CRLF = '\r\n';
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
fields: [4, 8, 16, 32], len: [4, 8, 16, 32],
n: [1e5], n: [1e5],
}); });
function main(conf) { function main(conf) {
const fields = conf.fields >>> 0; const len = conf.len >>> 0;
const n = conf.n >>> 0; const n = conf.n >>> 0;
var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`; var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
for (var i = 0; i < fields; i++) { for (var i = 0; i < len; i++) {
header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`; header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`;
} }
header += CRLF; header += CRLF;

8
benchmark/http/chunked.js

@ -11,14 +11,14 @@
var common = require('../common.js'); var common = require('../common.js');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
num: [1, 4, 8, 16], n: [1, 4, 8, 16],
size: [1, 64, 256], len: [1, 64, 256],
c: [100] c: [100]
}); });
function main(conf) { function main(conf) {
const http = require('http'); const http = require('http');
var chunk = Buffer.alloc(conf.size, '8'); var chunk = Buffer.alloc(conf.len, '8');
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
function send(left) { function send(left) {
@ -28,7 +28,7 @@ function main(conf) {
send(left - 1); send(left - 1);
}, 0); }, 0);
} }
send(conf.num); send(conf.n);
}); });
server.listen(common.PORT, function() { server.listen(common.PORT, function() {

4
benchmark/http/client-request-body.js

@ -7,13 +7,13 @@ var http = require('http');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
dur: [5], dur: [5],
type: ['asc', 'utf', 'buf'], type: ['asc', 'utf', 'buf'],
bytes: [32, 256, 1024], len: [32, 256, 1024],
method: ['write', 'end'] method: ['write', 'end']
}); });
function main(conf) { function main(conf) {
var dur = +conf.dur; var dur = +conf.dur;
var len = +conf.bytes; var len = +conf.len;
var encoding; var encoding;
var chunk; var chunk;

7
benchmark/http/cluster.js

@ -7,11 +7,12 @@ if (cluster.isMaster) {
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
// unicode confuses ab on os x. // unicode confuses ab on os x.
type: ['bytes', 'buffer'], type: ['bytes', 'buffer'],
length: [4, 1024, 102400], len: [4, 1024, 102400],
c: [50, 500] c: [50, 500]
}); });
} else { } else {
require('./_http_simple.js'); var port = parseInt(process.env.PORT || PORT);
require('../fixtures/simple-http-server.js').listen(port);
} }
function main(conf) { function main(conf) {
@ -26,7 +27,7 @@ function main(conf) {
return; return;
setTimeout(function() { setTimeout(function() {
var path = '/' + conf.type + '/' + conf.length; var path = '/' + conf.type + '/' + conf.len;
bench.http({ bench.http({
path: path, path: path,

6
benchmark/http/create-clientrequest.js

@ -4,15 +4,15 @@ var common = require('../common.js');
var ClientRequest = require('http').ClientRequest; var ClientRequest = require('http').ClientRequest;
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
pathlen: [1, 8, 16, 32, 64, 128], len: [1, 8, 16, 32, 64, 128],
n: [1e6] n: [1e6]
}); });
function main(conf) { function main(conf) {
var pathlen = +conf.pathlen; var len = +conf.len;
var n = +conf.n; var n = +conf.n;
var path = '/'.repeat(pathlen); var path = '/'.repeat(len);
var opts = { path: path, createConnection: function() {} }; var opts = { path: path, createConnection: function() {} };
bench.start(); bench.start();

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

@ -12,7 +12,7 @@ var common = require('../common.js');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'], type: ['asc', 'utf', 'buf'],
kb: [64, 128, 256, 1024], len: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024],
c: [100], c: [100],
method: ['write', 'end'] method: ['write', 'end']
}); });
@ -20,7 +20,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
const http = require('http'); const http = require('http');
var chunk; var chunk;
var len = conf.kb * 1024; var len = conf.len;
switch (conf.type) { switch (conf.type) {
case 'buf': case 'buf':
chunk = Buffer.alloc(len, 'x'); chunk = Buffer.alloc(len, 'x');

11
benchmark/http/simple.js

@ -5,7 +5,7 @@ var PORT = common.PORT;
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
// unicode confuses ab on os x. // unicode confuses ab on os x.
type: ['bytes', 'buffer'], type: ['bytes', 'buffer'],
length: [4, 1024, 102400], len: [4, 1024, 102400],
chunks: [0, 1, 4], // chunks=0 means 'no chunked encoding'. chunks: [0, 1, 4], // chunks=0 means 'no chunked encoding'.
c: [50, 500], c: [50, 500],
res: ['normal', 'setHeader', 'setHeaderWH'] res: ['normal', 'setHeader', 'setHeaderWH']
@ -13,9 +13,10 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
process.env.PORT = PORT; process.env.PORT = PORT;
var server = require('./_http_simple.js'); var server = require('../fixtures/simple-http-server.js')
setTimeout(function() { .listen(process.env.PORT || common.PORT)
var path = '/' + conf.type + '/' + conf.length + '/' + conf.chunks + '/' + .on('listening', function() {
var path = '/' + conf.type + '/' + conf.len + '/' + conf.chunks + '/' +
conf.res; conf.res;
bench.http({ bench.http({
@ -24,5 +25,5 @@ function main(conf) {
}, function() { }, function() {
server.close(); server.close();
}); });
}, 2000); });
} }

Loading…
Cancel
Save