From 0cd1c585056ddd048d94683a7832fa03768c92b4 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 7 Jun 2012 06:09:24 -0500 Subject: [PATCH] stress_test parameter parsing --- examples/wsperf/stress_handler.cpp | 57 +++++++++++++++++++++++++++++- examples/wsperf/stress_handler.hpp | 29 +++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/examples/wsperf/stress_handler.cpp b/examples/wsperf/stress_handler.cpp index 67e3848b58..0d49911b53 100644 --- a/examples/wsperf/stress_handler.cpp +++ b/examples/wsperf/stress_handler.cpp @@ -64,7 +64,62 @@ stress_handler::stress_handler(wscmd::cmd& cmd) , m_failed_connections(0) , m_next_con_id(0) , m_init(boost::chrono::steady_clock::now()) + , m_con_sync(false) { + if (!wscmd::extract_number(cmd,"msg_count",m_msg_count)) { + m_msg_count = 0; + } + + if (!wscmd::extract_number(cmd,"msg_size",m_msg_size)) { + m_msg_size = 0; + } + + std::string mode; + if (wscmd::extract_string(cmd,"msg_mode",mode)) { + if (mode == "fixed") { + m_msg_mode = msg_mode::FIXED; + } else if (mode == "infinite") { + m_msg_mode = msg_mode::INFINITE; + } else { + m_msg_mode = msg_mode::NONE; + } + } else { + m_msg_mode = msg_mode::NONE; + } + + if (wscmd::extract_string(cmd,"con_lifetime",mode)) { + if (mode == "random") { + m_con_lifetime = con_lifetime::RANDOM; + } else if (mode == "infinite") { + m_con_lifetime = con_lifetime::INFINITE; + } else { + m_con_lifetime = con_lifetime::FIXED; + } + } else { + m_con_lifetime = con_lifetime::FIXED; + } + + if (m_con_lifetime == con_lifetime::FIXED) { + if (!wscmd::extract_number(cmd,"con_duration",m_con_duration)) { + m_con_duration = 5000; + } + } else if (m_con_lifetime == con_lifetime::RANDOM) { + size_t max_dur; + if (!wscmd::extract_number(cmd,"con_duration",max_dur)) { + max_dur = 5000; + } + + // TODO: choose random number between 0 and max_dur + m_con_duration = max_dur; + } + + std::cout << "con_duration: " << m_con_duration + << "msg_count: " << m_msg_count + << "msg_size: " << m_msg_size + << "m_con_sync: " << m_con_sync + << "m_con_lifetime: " << m_con_lifetime + << "m_msg_mode: " << m_msg_mode + << std::endl; } void stress_handler::on_connect(connection_ptr con) { @@ -225,7 +280,7 @@ bool stress_handler::maintenance() { boost::chrono::nanoseconds dur = now - data.on_open; size_t milliseconds = dur.count() / 1000000.; - if (milliseconds > 5000) { + if (milliseconds > m_con_duration) { close(con); } } diff --git a/examples/wsperf/stress_handler.hpp b/examples/wsperf/stress_handler.hpp index 6d5c40e30f..dc0dcd5658 100644 --- a/examples/wsperf/stress_handler.hpp +++ b/examples/wsperf/stress_handler.hpp @@ -42,6 +42,25 @@ using websocketpp::client; namespace wsperf { +namespace con_lifetime { + enum value { + FIXED = 0, + RANDOM = 1, + INFINITE = 2 + }; +} + + + +namespace msg_mode { + enum value { + NONE = 0, + FIXED = 1, + INFINITE = 2 + }; +} + + struct con_data { typedef boost::chrono::steady_clock::time_point time_point; @@ -134,6 +153,16 @@ protected: size_t m_timeout; boost::shared_ptr m_timer; + // test settings pulled from the command + con_lifetime::value m_con_lifetime; + size_t m_con_duration; + bool m_con_sync; + + msg_mode::value m_msg_mode; + size_t m_msg_count; + size_t m_msg_size; + + mutable boost::mutex m_lock; };