Improve idle benchmarks
This commit is contained in:
parent
ac54272218
commit
aeb9bed63e
@ -2,30 +2,41 @@ net = require('net');
|
|||||||
|
|
||||||
var errors = 0, connections = 0;
|
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 () {
|
function connect () {
|
||||||
process.nextTick(function () {
|
process.nextTick(function () {
|
||||||
var s = net.Stream();
|
var s = net.Stream();
|
||||||
var gotConnected = false;
|
var gotConnected = false;
|
||||||
s.connect(9000);
|
s.connect(9000);
|
||||||
|
|
||||||
s.on('connect', function () {
|
s.on('connect', function () {
|
||||||
gotConnected = true;
|
gotConnected = true;
|
||||||
connections++;
|
connections++;
|
||||||
connect();
|
maybeConnect(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
var haderror = false;
|
|
||||||
|
|
||||||
s.on('close', function () {
|
s.on('close', function () {
|
||||||
if (gotConnected) connections--;
|
if (gotConnected) connections--;
|
||||||
//if (!haderror) connect();
|
lastClose = new Date();
|
||||||
});
|
|
||||||
|
|
||||||
s.on('end', function () {
|
|
||||||
s.end();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
s.on('error', function () {
|
s.on('error', function () {
|
||||||
haderror = true;
|
|
||||||
errors++;
|
errors++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,10 +5,6 @@ var errors = 0;
|
|||||||
|
|
||||||
server = net.Server(function (socket) {
|
server = net.Server(function (socket) {
|
||||||
|
|
||||||
socket.on('end', function () {
|
|
||||||
socket.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('error', function () {
|
socket.on('error', function () {
|
||||||
errors++;
|
errors++;
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user