Update FairMQStateMachine & introduce FairMQChannels

Organize sockets as a map of vectors of FairMQChannels.

Update FairMQStateMachine by removing SETTINGINPUT, SETTINGOUTPUT,
BIND and CONNECT states and by adding INITIALIZING_TASK, RESETTING_TASK
and RESETTING_DEVICE states. Run states functions in their own thread.
This commit is contained in:
Alexey Rybalchenko
2015-04-29 13:25:42 +02:00
parent a2ebbbe450
commit 7fda980710
54 changed files with 1674 additions and 1573 deletions

View File

@@ -9,7 +9,7 @@
* runBenchmarkSampler.cxx
*
* @since 2013-04-23
* @author D. Klein, A. Rybalchenko
* @author: D. Klein, A. Rybalchenko
*/
#include <iostream>
@@ -32,12 +32,11 @@ FairMQBenchmarkSampler sampler;
static void s_signal_handler(int signal)
{
cout << endl << "Caught signal " << signal << endl;
LOG(INFO) << "Caught signal " << signal;
sampler.ChangeState(FairMQBenchmarkSampler::STOP);
sampler.ChangeState(FairMQBenchmarkSampler::END);
cout << "Shutdown complete. Bye!" << endl;
LOG(INFO) << "Shutdown complete";
exit(1);
}
@@ -55,7 +54,8 @@ typedef struct DeviceOptions
{
DeviceOptions() :
id(), eventSize(0), eventRate(0), ioThreads(0),
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress() {}
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress()
{}
string id;
int eventSize;
@@ -80,7 +80,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
("event-rate", bpo::value<int>()->default_value(0), "Event rate limit in maximum number of events per second")
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
("output-buff-size", bpo::value<int>()->default_value(1000), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://*:5555\"")
("help", "Print help messages");
@@ -88,7 +88,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
bpo::variables_map vm;
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
if ( vm.count("help") )
if (vm.count("help"))
{
LOG(INFO) << "FairMQ Benchmark Sampler" << endl << desc;
return false;
@@ -96,28 +96,28 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
bpo::notify(vm);
if ( vm.count("id") )
if (vm.count("id"))
_options->id = vm["id"].as<string>();
if ( vm.count("event-size") )
if (vm.count("event-size"))
_options->eventSize = vm["event-size"].as<int>();
if ( vm.count("event-rate") )
if (vm.count("event-rate"))
_options->eventRate = vm["event-rate"].as<int>();
if ( vm.count("io-threads") )
if (vm.count("io-threads"))
_options->ioThreads = vm["io-threads"].as<int>();
if ( vm.count("output-socket-type") )
if (vm.count("output-socket-type"))
_options->outputSocketType = vm["output-socket-type"].as<string>();
if ( vm.count("output-buff-size") )
if (vm.count("output-buff-size"))
_options->outputBufSize = vm["output-buff-size"].as<int>();
if ( vm.count("output-method") )
if (vm.count("output-method"))
_options->outputMethod = vm["output-method"].as<string>();
if ( vm.count("output-address") )
if (vm.count("output-address"))
_options->outputAddress = vm["output-address"].as<string>();
return true;
@@ -151,35 +151,35 @@ int main(int argc, char** argv)
sampler.SetTransport(transportFactory);
FairMQChannel channel(options.outputSocketType, options.outputMethod, options.outputAddress);
channel.fSndBufSize = options.outputBufSize;
channel.fRcvBufSize = options.outputBufSize;
channel.fRateLogging = 1;
sampler.fChannels["data-out"].push_back(channel);
sampler.SetProperty(FairMQBenchmarkSampler::Id, options.id);
sampler.SetProperty(FairMQBenchmarkSampler::EventSize, options.eventSize);
sampler.SetProperty(FairMQBenchmarkSampler::EventRate, options.eventRate);
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, options.ioThreads);
sampler.SetProperty(FairMQBenchmarkSampler::NumInputs, 0);
sampler.SetProperty(FairMQBenchmarkSampler::NumOutputs, 1);
sampler.ChangeState(FairMQBenchmarkSampler::INIT_DEVICE);
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_DEVICE);
sampler.ChangeState(FairMQBenchmarkSampler::INIT);
sampler.ChangeState(FairMQBenchmarkSampler::INIT_TASK);
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_TASK);
sampler.SetProperty(FairMQBenchmarkSampler::OutputSocketType, options.outputSocketType);
sampler.SetProperty(FairMQBenchmarkSampler::OutputSndBufSize, options.outputBufSize);
sampler.SetProperty(FairMQBenchmarkSampler::OutputMethod, options.outputMethod);
sampler.SetProperty(FairMQBenchmarkSampler::OutputAddress, options.outputAddress);
sampler.ChangeState(FairMQBenchmarkSampler::SETOUTPUT);
sampler.ChangeState(FairMQBenchmarkSampler::SETINPUT);
sampler.ChangeState(FairMQBenchmarkSampler::BIND);
sampler.ChangeState(FairMQBenchmarkSampler::CONNECT);
sampler.ChangeState(FairMQBenchmarkSampler::RUN);
// wait until the running thread has finished processing.
boost::unique_lock<boost::mutex> lock(sampler.fRunningMutex);
while (!sampler.fRunningFinished)
{
sampler.fRunningCondition.wait(lock);
}
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RUN);
sampler.ChangeState(FairMQBenchmarkSampler::STOP);
sampler.ChangeState(FairMQBenchmarkSampler::RESET_TASK);
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_TASK);
sampler.ChangeState(FairMQBenchmarkSampler::RESET_DEVICE);
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_DEVICE);
sampler.ChangeState(FairMQBenchmarkSampler::END);
return 0;