22 #include "zmqpp/zmqpp.hpp"
23 #include <boost/property_tree/ptree.hpp>
25 #include <zmqpp/context.hpp>
26 #include <zmqpp/message.hpp>
32 bool send_request(std::shared_ptr<zmqpp::socket> target,
const std::string &cmd1)
38 p.add(*target.get(), zmqpp::poller::poll_in);
41 INFO(
"No response from target (" << target <<
")");
50 INFO(
"response = " << rep);
61 start_module(
zmqpp::socket *pipe, boost::property_tree::ptree cfg,
62 zmqpp::context &zmq_ctx)
64 INFO(
"Bench-Toggle will start");
65 std::string endpoint_to_bench =
66 cfg.get_child(
"module_config").get_child(
"target").data();
67 int itr = cfg.get_child(
"module_config").get<
int>(
"iterations");
68 int wait_for = cfg.get_child(
"module_config").get<
int>(
"pause");
69 pipe->send(zmqpp::signal::ok);
72 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
74 std::shared_ptr<zmqpp::socket> sock(
75 new zmqpp::socket(zmq_ctx, zmqpp::socket_type::req));
77 sock->connect(
"inproc://" + endpoint_to_bench);
78 INFO(
"should take about " << itr * wait_for <<
"ms to run");
79 std::chrono::system_clock::time_point clock = std::chrono::system_clock::now();
81 for (
int i = 0; i < itr; i++)
85 std::this_thread::sleep_for(std::chrono::milliseconds(wait_for));
87 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
88 std::chrono::system_clock::now() - clock);
89 DEBUG(
"TOOK " << elapsed.count() <<
"ms");
91 INFO(
"Module Bench-Toggle shutting down");