stress client measures handshake speed

This commit is contained in:
Peter Thorson
2011-12-15 07:02:43 -06:00
parent 241985c2ee
commit 9c1473ee91
3 changed files with 22 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ var options = {"console_enabled": true};
var ws;
var url;
var data2 = [], total_points = 60;
var data2 = [], total_points = 240;
var stale_data = null;
var message_history = [];

View File

@@ -97,7 +97,7 @@ public:
void on_open(connection_ptr connection) {
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(500));
m_timer->expires_from_now(boost::posix_time::milliseconds(250));
m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
m_last_time = boost::posix_time::microsec_clock::local_time();
}
@@ -369,7 +369,7 @@ public:
//m_data = 0;
//}
m_timer->expires_from_now(boost::posix_time::milliseconds(500));
m_timer->expires_from_now(boost::posix_time::milliseconds(250));
m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
}

View File

@@ -61,7 +61,9 @@ public:
typedef stress_client_handler type;
typedef plain_endpoint_type::connection_ptr connection_ptr;
stress_client_handler(int num_connections) : m_connections(num_connections) {
stress_client_handler(int num_connections)
: m_connections_max(num_connections),
m_connections_cur(0) {
}
@@ -71,12 +73,22 @@ public:
m_timer->expires_from_now(boost::posix_time::milliseconds(250));
m_timer->async_wait(boost::bind(&type::on_timer,this,connection,boost::asio::placeholders::error));
}
m_connections_cur++;
if (m_connections_cur == m_connections_max) {
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_period period(m_start_time,now);
int ms = period.length().total_milliseconds();
std::cout << "Started " << m_connections_cur << " in " << ms << "ms" << " (" << m_connections_cur/(ms/1000.0) << "/s)" << std::endl;
}
}
void on_message(connection_ptr connection, websocketpp::message::data_ptr msg) {
m_msg_stats[websocketpp::md5_hash_hex(msg->get_payload())]++;
if (m_msg_stats[websocketpp::md5_hash_hex(msg->get_payload())] == m_connections) {
if (m_msg_stats[websocketpp::md5_hash_hex(msg->get_payload())] == m_connections_max) {
send_stats_update(connection);
}
@@ -102,6 +114,8 @@ public:
void on_close(connection_ptr connection) {
m_timer->cancel();
}
boost::posix_time::ptime m_start_time;
private:
void send_stats_update(connection_ptr connection) {
if (m_msg_stats.empty()) {
@@ -126,7 +140,8 @@ private:
m_msg_stats.clear();
}
int m_connections;
int m_connections_max;
int m_connections_cur;
std::map<std::string,size_t> m_msg_stats;
boost::shared_ptr<boost::asio::deadline_timer> m_timer;
};
@@ -197,6 +212,7 @@ int main(int argc, char* argv[]) {
std::cout << "launching " << num_connections << " connections to " << uri << " in batches of " << batch_size << std::endl;
boost::dynamic_pointer_cast<stress_client_handler>(handler)->m_start_time = boost::posix_time::microsec_clock::local_time();
for (int i = 0; i < num_connections-1; i++) {
if (i % batch_size == 0) {
//sleep(1);