summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-09 18:01:23 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-09 18:01:23 -0800
commit32ec378e3b5e9c584d45c7316142c73c362dd032 (patch)
treee1986cf92feb930753290e1970444beb33459626
parent2cc50bdb10c0a7849763ae1dfa37ca7707299a16 (diff)
downloadinfinitytier-32ec378e3b5e9c584d45c7316142c73c362dd032.tar.gz
infinitytier-32ec378e3b5e9c584d45c7316142c73c362dd032.zip
Announce that we have peers on the cluster when we first see them to improve startup times, and add a result crunching script to tests/http.
-rw-r--r--node/Cluster.cpp11
-rw-r--r--node/Cluster.hpp9
-rw-r--r--node/Peer.cpp5
-rw-r--r--tests/http/crunch-results.js58
-rw-r--r--tests/http/server.js2
5 files changed, 84 insertions, 1 deletions
diff --git a/node/Cluster.cpp b/node/Cluster.cpp
index a819372e..ab074b6d 100644
--- a/node/Cluster.cpp
+++ b/node/Cluster.cpp
@@ -363,6 +363,17 @@ void Cluster::handleIncomingStateMessage(const void *msg,unsigned int len)
}
}
+void Cluster::broadcastHavePeer(const Identity &id)
+{
+ Buffer<1024> buf;
+ id.serialize(buf);
+ Mutex::Lock _l(_memberIds_m);
+ for(std::vector<uint16_t>::const_iterator mid(_memberIds.begin());mid!=_memberIds.end();++mid) {
+ Mutex::Lock _l2(_members[*mid].lock);
+ _send(*mid,CLUSTER_MESSAGE_HAVE_PEER,buf.data(),buf.size());
+ }
+}
+
void Cluster::sendViaCluster(const Address &fromPeerAddress,const Address &toPeerAddress,const void *data,unsigned int len,bool unite)
{
if (len > ZT_PROTO_MAX_PACKET_LENGTH) // sanity check
diff --git a/node/Cluster.hpp b/node/Cluster.hpp
index 1c4331b4..6a7cf7ad 100644
--- a/node/Cluster.hpp
+++ b/node/Cluster.hpp
@@ -245,6 +245,15 @@ public:
void handleIncomingStateMessage(const void *msg,unsigned int len);
/**
+ * Broadcast that we have a given peer
+ *
+ * This should be done when new peers are first contacted.
+ *
+ * @param id Identity of peer
+ */
+ void broadcastHavePeer(const Identity &id);
+
+ /**
* Send this packet via another node in this cluster if another node has this peer
*
* This is used in the outgoing packet and relaying logic in Switch to
diff --git a/node/Peer.cpp b/node/Peer.cpp
index de6f00c2..d728cf4c 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -187,6 +187,11 @@ void Peer::received(
_sortPaths(now);
}
+#ifdef ZT_ENABLE_CLUSTER
+ if ((RR->cluster)&&(!suboptimalPath))
+ RR->cluster->broadcastHavePeer(_id);
+#endif
+
} else {
/* If this path is not known, send a HELLO. We don't learn
diff --git a/tests/http/crunch-results.js b/tests/http/crunch-results.js
new file mode 100644
index 00000000..85c021d7
--- /dev/null
+++ b/tests/http/crunch-results.js
@@ -0,0 +1,58 @@
+//
+// Pipe the output of server.js into this to convert raw test results into bracketed statistics
+// suitable for graphing.
+//
+
+// Average over this interval of time
+var GRAPH_INTERVAL = 60000;
+
+// Number of bytes expected from each test
+var EXPECTED_BYTES = 5000;
+
+var readline = require('readline');
+var rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ terminal: false
+});
+
+var startTS = 0;
+
+var count = 0.0;
+var totalFailures = 0;
+var totalPartialFailures = 0;
+var totalMs = 0;
+var totalData = 0;
+
+rl.on('line',function(line) {
+ line = line.trim();
+ var ls = line.split(',');
+ if (ls.length == 7) {
+ var ts = parseInt(ls[0]);
+ var from = ls[1];
+ var to = ls[2];
+ var ms = parseFloat(ls[3]);
+ var bytes = parseInt(ls[4]);
+ var timedOut = (ls[5] == 'true') ? true : false;
+ var errMsg = ls[6];
+
+ count += 1.0;
+ if ((bytes <= 0)||(timedOut))
+ ++totalFailures;
+ if (bytes !== EXPECTED_BYTES)
+ ++totalPartialFailures;
+ totalMs += ms;
+ totalData += bytes;
+
+ if (startTS === 0) {
+ startTS = ts;
+ } else if (((ts - startTS) >= GRAPH_INTERVAL)&&(count > 0.0)) {
+ console.log(count.toString()+','+(totalMs / count)+','+totalFailures+','+totalPartialFailures+','+totalData);
+
+ count = 0.0;
+ totalFailures = 0;
+ totalPartialFailures = 0;
+ totalMs = 0;
+ }
+ } // else ignore junk
+});
diff --git a/tests/http/server.js b/tests/http/server.js
index 57109392..1abe624b 100644
--- a/tests/http/server.js
+++ b/tests/http/server.js
@@ -30,7 +30,7 @@ app.post('/:agentId',function(req,res) {
var resultData = null;
try {
resultData = JSON.parse(req.rawBody);
- console.log(resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
+ console.log(Date.now()+','+resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
} catch (e) {}
}