0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/idle_clients.js
Rich Trott 1bedeeb41d benchmark: fix lint errors
PR-URL: https://github.com/nodejs/node/pull/5517
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-03 09:53:22 -08:00

48 lines
884 B
JavaScript

'use strict';
const net = require('net');
var errors = 0, connections = 0;
function connect() {
process.nextTick(function() {
var s = net.Stream();
var gotConnected = false;
s.connect(9000);
s.on('connect', function() {
gotConnected = true;
connections++;
connect();
});
s.on('close', function() {
if (gotConnected) connections--;
});
s.on('error', function() {
errors++;
});
});
}
connect();
var oldConnections, oldErrors;
// Try to start new connections every so often
setInterval(connect, 5000);
setInterval(function() {
if (oldConnections != connections) {
oldConnections = connections;
console.log('CLIENT %d connections: %d', process.pid, connections);
}
if (oldErrors != errors) {
oldErrors = errors;
console.log('CLIENT %d errors: %d', process.pid, errors);
}
}, 1000);