Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-10-27 13:52:49 +0400
committerRyan Dahl <ry@tinyclouds.org>2010-10-27 13:52:49 +0400
commitaeb9bed63e3521088aef3b919ac5129a9822e83c (patch)
tree0f67f068d1cc88d5bb22fbc82353e3831fd8382d /benchmark
parentac54272218a4d82f486aa163369962c98ba614c2 (diff)
Improve idle benchmarks
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/idle_clients.js29
-rw-r--r--benchmark/idle_server.js4
2 files changed, 20 insertions, 13 deletions
diff --git a/benchmark/idle_clients.js b/benchmark/idle_clients.js
index 9bb78628072..65988ab3ad0 100644
--- a/benchmark/idle_clients.js
+++ b/benchmark/idle_clients.js
@@ -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++;
});
});
diff --git a/benchmark/idle_server.js b/benchmark/idle_server.js
index 5d08897d199..53afc77901d 100644
--- a/benchmark/idle_server.js
+++ b/benchmark/idle_server.js
@@ -5,10 +5,6 @@ var errors = 0;
server = net.Server(function (socket) {
- socket.on('end', function () {
- socket.end();
- });
-
socket.on('error', function () {
errors++;
});