more efficient broadcast_admin connection counting

This commit is contained in:
Peter Thorson
2011-12-15 06:47:29 -06:00
parent 57fb71d61d
commit 217a81add8
2 changed files with 23 additions and 20 deletions

View File

@@ -50,11 +50,11 @@ function connect() {
ws.onclose = function(e) {
document.getElementById("messages").innerHTML += "Client: The connection to "+url+" was closed.<br />";
clear_hud()
clear_hud();
};
ws.onmessage = function(e) {
foo = JSON.parse(e.data);
foo = JSON.parse(e.data);
if (foo.type == "message") {
if (options.console_enabled) {
@@ -63,13 +63,12 @@ function connect() {
} else if (foo.type == "con") {
document.getElementById("connected_clients").innerHTML = foo.value;
} else if (foo.type == "stats") {
console.log(foo);
for (var i in foo.messages) {
var hash = foo.messages[i].hash;
if (hash in msgs) {
msgs[hash]["sent"] += foo.messages[i].sent;
msgs[hash]["acked"] += foo.messages[i].acked;
msgs[hash]["sent"] = foo.messages[i].sent;
msgs[hash]["acked"] = foo.messages[i].acked;
msgs[hash]["time"] = foo.messages[i].time;
} else {
msgs[hash] = {"id":foo.messages[i].id,
@@ -80,13 +79,13 @@ function connect() {
}
}
var foo = "";
var o = "";
for (i in msgs) {
foo += "<tr><td>"+msgs[i].id+"</td><td>"+msgs[i].sent+"</td><td>"+msgs[i].acked+"</td><td>"+msgs[i].size+"</td><td>"+msgs[i].time+"</td></tr>";
o += "<tr><td>"+msgs[i].id+"</td><td>"+msgs[i].sent+"</td><td>"+msgs[i].acked+"</td><td>"+format_data(msgs[i].size)+"</td><td>"+msgs[i].time+"</td><td>"+(msgs[i].time != 0 ? (msgs[i].acked/(msgs[i].time/1000.0)).toFixed(0)+"/s" : "")+"</td><td>"+(msgs[i].time != 0 ? format_data(msgs[i].acked*msgs[i].size/(msgs[i].time/1000.0))+"/s" : "")+"</td></tr>";
}
$("#sent_messages").html(foo);
$("#sent_messages").html(o);
/*document.getElementById("messages_per_sec").innerHTML = foo.messages+"/s";
document.getElementById("bytes_per_sec").innerHTML = format_data(foo.bytes)+"/s";
@@ -94,13 +93,16 @@ function connect() {
document.getElementById("messages_acked").innerHTML = foo.messages_acked;
document.getElementById("bytes_sent").innerHTML = format_data(foo.bytes_sent);*/
document.getElementById("admin_connections").innerHTML = foo.admin_connections;
document.getElementById("connected_clients").innerHTML = foo.connections;
client_history.push([foo.timestamp,foo.connections]);
if (client_history.length > total_points) {
client_history = client_history.slice(client_history.length-total_points);
}
/*data2.push([foo.timestamp,foo.bytes]);
if (data2.length > total_points) {
data2 = data2.slice(data2.length-total_points);
@@ -279,7 +281,7 @@ body,html {
<div>
<table>
<thead>
<tr><th>id</th><th>sent</th><th>acked</th><th>size</th><th>time</th></tr>
<tr><th>id</th><th>sent</th><th>acked</th><th>size</th><th>time</th><th>message rate</th><th>data rate</th></tr>
</thead>
<tbody id="sent_messages">
</tbody>

View File

@@ -95,9 +95,9 @@ public:
}
void on_open(connection_ptr connection) {
if (!m_timer) {
if (!m_timer) {
m_timer.reset(new boost::asio::deadline_timer(connection->get_io_service(),boost::posix_time::seconds(0)));
m_timer->expires_from_now(boost::posix_time::milliseconds(1000));
m_timer->expires_from_now(boost::posix_time::milliseconds(500));
m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
m_last_time = boost::posix_time::microsec_clock::local_time();
}
@@ -108,7 +108,7 @@ public:
m_connections.insert(connection);
}
typename std::set<connection_ptr>::iterator it;
/*typename std::set<connection_ptr>::iterator it;
std::stringstream foo;
foo << "{\"type\":\"con\""
@@ -118,7 +118,7 @@ public:
for (it = m_admin_connections.begin(); it != m_admin_connections.end(); it++) {
(*it)->send(foo.str(),false);
}
}*/
}
void on_close(connection_ptr connection) {
@@ -126,7 +126,7 @@ public:
m_connections.erase(connection);
m_admin_connections.erase(connection);
typename std::set<connection_ptr>::iterator it;
/*typename std::set<connection_ptr>::iterator it;
std::stringstream foo;
foo << "{\"type\":\"con\""
@@ -136,7 +136,7 @@ public:
for (it = m_admin_connections.begin(); it != m_admin_connections.end(); it++) {
(*it)->send(foo.str(),false);
}
}*/
}
@@ -207,7 +207,8 @@ public:
std::map<std::string,struct msg>::iterator it = m_msgs.find(hash);
if (it == m_msgs.end()) {
std::cout << "ack for message we didn't send" << std::endl;
std::cout << "ack for message we didn't send: " << hash
<< "(" << hash.size() << ")" << std::endl;
return;
}
@@ -347,12 +348,12 @@ public:
<< ",\"acked\":" << (*msg_it).second.acked
<< ",\"size\":" << (*msg_it).second.size
<< ",\"time\":" << (*msg_it).second.time
<< "}";
<< "}" << (msg_it == last ? "" : ",");
}
foo << "]}";
m_msgs.clear();
//m_msgs.clear();
//<< ((m_messages_cache * seconds)*1000) << ",\"data\":"
//<< ((m_data_cache * seconds)*1000) << ",\"messages_sent\":"
@@ -368,7 +369,7 @@ public:
//m_data = 0;
//}
m_timer->expires_from_now(boost::posix_time::milliseconds(1000));
m_timer->expires_from_now(boost::posix_time::milliseconds(500));
m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
}
@@ -391,7 +392,7 @@ private:
int m_nextid;
std::map<std::string,struct msg> m_msgs;
std::set<connection_ptr> m_connections;
std::set<connection_ptr> m_admin_connections;
};