Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Improve idle benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 27, 2010
1 parent ac54272 commit aeb9bed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 20 additions & 9 deletions benchmark/idle_clients.js
Expand Up @@ -2,30 +2,41 @@ net = require('net');

var errors = 0, connections = 0;

var lastClose = 0;

function maybeConnect (s) {
var now = new Date();
if (now - lastClose > 5000) {
// Just connect immediately
connect();
} else {
// Otherwise wait a little - see if this one is connected still. Just to
// avoid spinning at 100% cpu when the server totally rejects our
// connections.
setTimeout(function () {
if (s.writable && s.readable) connect();
}, 100);
}
}

function connect () {
process.nextTick(function () {
var s = net.Stream();
var gotConnected = false;
s.connect(9000);

s.on('connect', function () {
gotConnected = true;
connections++;
connect();
maybeConnect(s);
});

var haderror = false;

s.on('close', function () {
if (gotConnected) connections--;
//if (!haderror) connect();
});

s.on('end', function () {
s.end();
lastClose = new Date();
});

s.on('error', function () {
haderror = true;
errors++;
});
});
Expand Down
4 changes: 0 additions & 4 deletions benchmark/idle_server.js
Expand Up @@ -5,10 +5,6 @@ var errors = 0;

server = net.Server(function (socket) {

socket.on('end', function () {
socket.end();
});

socket.on('error', function () {
errors++;
});
Expand Down

0 comments on commit aeb9bed

Please sign in to comment.