Browse Source

benchmark: make concurrent requests configurable

In http_bench.js, allow the concurrent requests per client
to be configurable.

This also changes the launch of clients to wait until all
forked servers are online. This eliminates spurious error
messages at the start of the run.

PR-URL: https://github.com/nodejs/io.js/pull/2068
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v4.0.0-rc
Rich Trott 10 years ago
parent
commit
05a73c0f25
  1. 23
      benchmark/http_bench.js

23
benchmark/http_bench.js

@ -8,7 +8,8 @@ var options = {
port: 22344, port: 22344,
path: '/', path: '/',
servers: 1, servers: 1,
clients: 1 clients: 1,
clientConcurrentRequests: 2
}; };
for (var i = 2; i < process.argv.length; ++i) { for (var i = 2; i < process.argv.length; ++i) {
@ -44,13 +45,25 @@ function patch(fun) {
function startMaster() { function startMaster() {
if (!cluster.isMaster) return startServer(); if (!cluster.isMaster) return startServer();
for (var i = ~~options.servers; i > 0; --i) cluster.fork(); var forkCount = 0;
cluster.on('online', function () {
forkCount = forkCount + 1;
if (forkCount === ~~options.servers) {
var args = [
__filename,
'mode=client',
'clientConcurrentRequests=' + options.clientConcurrentRequests
];
for (var i = ~~options.clients; i > 0; --i) { for (var i = ~~options.clients; i > 0; --i) {
var cp = spawn(process.execPath, [__filename, 'mode=client']); var cp = spawn(process.execPath, args);
cp.stdout.pipe(process.stdout); cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr); cp.stderr.pipe(process.stderr);
} }
}
});
for (var i = ~~options.servers; i > 0; --i) cluster.fork();
} }
function startServer() { function startServer() {
@ -73,9 +86,9 @@ function startServer() {
function startClient() { function startClient() {
// send off a bunch of concurrent requests // send off a bunch of concurrent requests
// TODO make configurable for (var i = ~~options.clientConcurrentRequests; i > 0; --i) {
sendRequest();
sendRequest(); sendRequest();
}
function sendRequest() { function sendRequest() {
var req = http.request(options, onConnection); var req = http.request(options, onConnection);

Loading…
Cancel
Save