src: move debug agent from deps/ to src/
[platform/upstream/nodejs.git] / benchmark / idle_clients.js
1 net = require('net');
2
3 var errors = 0, connections = 0;
4
5 var lastClose = 0;
6
7 function connect () {
8   process.nextTick(function () {
9     var s = net.Stream();
10     var gotConnected = false;
11     s.connect(9000);
12
13     s.on('connect', function () {
14       gotConnected = true;
15       connections++;
16       connect();
17     });
18
19     s.on('close', function () {
20       if (gotConnected) connections--;
21       lastClose = new Date();
22     });
23
24     s.on('error', function () {
25       errors++;
26     });
27   });
28 }
29
30 connect();
31
32
33 var oldConnections, oldErrors;
34
35 // Try to start new connections every so often
36 setInterval(connect, 5000);
37
38 setInterval(function () {
39   if (oldConnections != connections) {
40     oldConnections = connections;
41     console.log("CLIENT %d connections: %d", process.pid, connections);
42   }
43
44   if (oldErrors != errors) {
45     oldErrors = errors;
46     console.log("CLIENT %d errors: %d", process.pid, errors);
47   }
48 }, 1000);
49