Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: make concurrent requests configurable #2068

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions benchmark/http_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var options = {
port: 22344,
path: '/',
servers: 1,
clients: 1
clients: 1,
clientConcurrentRequests: 2
};

for (var i = 2; i < process.argv.length; ++i) {
Expand Down Expand Up @@ -44,13 +45,25 @@ function patch(fun) {
function startMaster() {
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) {
var cp = spawn(process.execPath, args);
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr);
}
}
});

for (var i = ~~options.clients; i > 0; --i) {
var cp = spawn(process.execPath, [__filename, 'mode=client']);
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr);
}
for (var i = ~~options.servers; i > 0; --i) cluster.fork();
}

function startServer() {
Expand All @@ -73,9 +86,9 @@ function startServer() {

function startClient() {
// send off a bunch of concurrent requests
// TODO make configurable
sendRequest();
sendRequest();
for (var i = ~~options.clientConcurrentRequests; i > 0; --i) {
sendRequest();
}

function sendRequest() {
var req = http.request(options, onConnection);
Expand Down