Add a cmd option to control state change mechanism

This commit is contained in:
Alexey Rybalchenko 2016-04-27 15:04:29 +02:00
parent b9883d3b13
commit 5421922668
9 changed files with 94 additions and 197 deletions

View File

@ -614,6 +614,7 @@ void FairMQDevice::SetTransport(const string& transport)
void FairMQDevice::SetConfig(FairMQProgOptions& config) void FairMQDevice::SetConfig(FairMQProgOptions& config)
{ {
LOG(DEBUG) << "PID: " << getpid();
fConfig = &config; fConfig = &config;
fChannels = config.GetFairMQMap(); fChannels = config.GetFairMQMap();
SetTransport(config.GetValue<string>("transport")); SetTransport(config.GetValue<string>("transport"));

View File

@ -173,29 +173,32 @@ void FairMQProgOptions::InitOptionDescription()
if (fUseConfigFile) if (fUseConfigFile)
{ {
fMQOptionsInCmd.add_options() fMQOptionsInCmd.add_options()
("id", po::value<string>(), "Device ID (required argument).") ("id", po::value<string>(), "Device ID (required argument).")
("io-threads", po::value<int>()->default_value(1), "Number of I/O threads.") ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').") ("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).") ("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
; ;
fMQOptionsInCfg.add_options() fMQOptionsInCfg.add_options()
("id", po::value<string>()->required(), "Device ID (required argument).") ("id", po::value<string>()->required(), "Device ID (required argument).")
("io-threads", po::value<int>()->default_value(1), "Number of I/O threads.") ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').") ("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).") ("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
; ;
} }
else else
{ {
fMQOptionsInCmd.add_options() fMQOptionsInCmd.add_options()
("id", po::value<string>()->required(), "Device ID (required argument)") ("id", po::value<string>()->required(), "Device ID (required argument)")
("io-threads", po::value<int>()->default_value(1), "Number of I/O threads") ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').") ("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).") ("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
; ;
} }

View File

@ -17,69 +17,42 @@
#include "boost/program_options.hpp" #include "boost/program_options.hpp"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQTools.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
#include "FairMQBenchmarkSampler.h" #include "FairMQBenchmarkSampler.h"
#include "runSimpleMQStateMachine.h"
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options; using namespace boost::program_options;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
FairMQBenchmarkSampler sampler;
sampler.CatchSignals();
FairMQProgOptions config;
try try
{ {
int msgSize; int msgSize;
int numMsgs; int numMsgs;
options_description sampler_options("Sampler options"); options_description samplerOptions("Sampler options");
sampler_options.add_options() samplerOptions.add_options()
("msg-size", value<int>(&msgSize)->default_value(1000), "Message size in bytes") ("msg-size", value<int>(&msgSize)->default_value(1000), "Message size in bytes")
("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to send"); ("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to send");
config.AddToCmdLineOptions(sampler_options); FairMQProgOptions config;
config.AddToCmdLineOptions(samplerOptions);
if (config.ParseAll(argc, argv)) if (config.ParseAll(argc, argv))
{ {
return 0; return 0;
} }
string filename = config.GetValue<string>("config-json-file"); FairMQBenchmarkSampler sampler;
string id = config.GetValue<string>("id");
config.UserParser<JSON>(filename, id);
sampler.fChannels = config.GetFairMQMap();
LOG(INFO) << "PID: " << getpid();
sampler.SetTransport(config.GetValue<std::string>("transport"));
sampler.SetProperty(FairMQBenchmarkSampler::Id, id);
sampler.SetProperty(FairMQBenchmarkSampler::MsgSize, msgSize); sampler.SetProperty(FairMQBenchmarkSampler::MsgSize, msgSize);
sampler.SetProperty(FairMQBenchmarkSampler::NumMsgs, numMsgs); sampler.SetProperty(FairMQBenchmarkSampler::NumMsgs, numMsgs);
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, config.GetValue<int>("io-threads"));
sampler.ChangeState("INIT_DEVICE"); runStateMachine(sampler, config);
sampler.WaitForEndOfState("INIT_DEVICE");
sampler.ChangeState("INIT_TASK");
sampler.WaitForEndOfState("INIT_TASK");
sampler.ChangeState("RUN");
sampler.InteractiveStateLoop();
} }
catch (exception& e) catch (std::exception& e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << "Unhandled Exception reached the top of main: "
LOG(INFO) << "Command line options are the following : "; << e.what() << ", application will now exit";
config.PrintHelp();
return 1; return 1;
} }

View File

@ -15,40 +15,28 @@
#include <iostream> #include <iostream>
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
#include "FairMQMerger.h" #include "FairMQMerger.h"
#include "runSimpleMQStateMachine.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
FairMQMerger merger;
merger.CatchSignals();
FairMQProgOptions config;
try try
{ {
FairMQProgOptions config;
if (config.ParseAll(argc, argv)) if (config.ParseAll(argc, argv))
{ {
return 0; return 0;
} }
merger.SetConfig(config); FairMQMerger merger;
runStateMachine(merger, config);
merger.ChangeState("INIT_DEVICE");
merger.WaitForEndOfState("INIT_DEVICE");
merger.ChangeState("INIT_TASK");
merger.WaitForEndOfState("INIT_TASK");
merger.ChangeState("RUN");
merger.InteractiveStateLoop();
} }
catch (std::exception& e) catch (std::exception& e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << "Unhandled Exception reached the top of main: "
LOG(INFO) << "Command line options are the following: "; << e.what() << ", application will now exit";
config.PrintHelp();
return 1; return 1;
} }

View File

@ -15,42 +15,28 @@
#include <iostream> #include <iostream>
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
#include "FairMQProxy.h" #include "FairMQProxy.h"
#include "runSimpleMQStateMachine.h"
using namespace std;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
FairMQProxy proxy;
proxy.CatchSignals();
FairMQProgOptions config;
try try
{ {
FairMQProgOptions config;
if (config.ParseAll(argc, argv)) if (config.ParseAll(argc, argv))
{ {
return 0; return 0;
} }
proxy.SetConfig(config); FairMQProxy proxy;
runStateMachine(proxy, config);
proxy.ChangeState("INIT_DEVICE");
proxy.WaitForEndOfState("INIT_DEVICE");
proxy.ChangeState("INIT_TASK");
proxy.WaitForEndOfState("INIT_TASK");
proxy.ChangeState("RUN");
proxy.InteractiveStateLoop();
} }
catch (std::exception& e) catch (std::exception& e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << "Unhandled Exception reached the top of main: "
LOG(INFO) << "Command line options are the following: "; << e.what() << ", application will now exit";
config.PrintHelp();
return 1; return 1;
} }

View File

@ -17,66 +17,39 @@
#include "boost/program_options.hpp" #include "boost/program_options.hpp"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
#include "FairMQSink.h" #include "FairMQSink.h"
#include "runSimpleMQStateMachine.h"
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options; using namespace boost::program_options;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
FairMQSink sink;
sink.CatchSignals();
FairMQProgOptions config;
try try
{ {
int numMsgs; int numMsgs;
options_description sink_options("Sink options"); options_description sinkOptions("Sink options");
sink_options.add_options() sinkOptions.add_options()
("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to receive"); ("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to receive");
config.AddToCmdLineOptions(sink_options); FairMQProgOptions config;
config.AddToCmdLineOptions(sinkOptions);
if (config.ParseAll(argc, argv)) if (config.ParseAll(argc, argv))
{ {
return 0; return 0;
} }
string filename = config.GetValue<string>("config-json-file"); FairMQSink sink;
string id = config.GetValue<string>("id");
// int ioThreads = config.GetValue<int>("io-threads");
config.UserParser<JSON>(filename, id);
sink.fChannels = config.GetFairMQMap();
LOG(INFO) << "PID: " << getpid();
sink.SetTransport(config.GetValue<std::string>("transport"));
sink.SetProperty(FairMQSink::Id, id);
sink.SetProperty(FairMQSink::NumMsgs, numMsgs); sink.SetProperty(FairMQSink::NumMsgs, numMsgs);
sink.SetProperty(FairMQSink::NumIoThreads, config.GetValue<int>("io-threads"));
sink.ChangeState("INIT_DEVICE"); runStateMachine(sink, config);
sink.WaitForEndOfState("INIT_DEVICE");
sink.ChangeState("INIT_TASK");
sink.WaitForEndOfState("INIT_TASK");
sink.ChangeState("RUN");
sink.InteractiveStateLoop();
} }
catch (exception& e) catch (std::exception& e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << "Unhandled Exception reached the top of main: "
LOG(INFO) << "Started with: "; << e.what() << ", application will now exit";
config.PrintHelp();
return 1; return 1;
} }

View File

@ -15,40 +15,28 @@
#include <iostream> #include <iostream>
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
#include "FairMQSplitter.h" #include "FairMQSplitter.h"
#include "runSimpleMQStateMachine.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
FairMQSplitter splitter;
splitter.CatchSignals();
FairMQProgOptions config;
try try
{ {
FairMQProgOptions config;
if (config.ParseAll(argc, argv)) if (config.ParseAll(argc, argv))
{ {
return 0; return 0;
} }
splitter.SetConfig(config); FairMQSplitter splitter;
runStateMachine(splitter, config);
splitter.ChangeState("INIT_DEVICE");
splitter.WaitForEndOfState("INIT_DEVICE");
splitter.ChangeState("INIT_TASK");
splitter.WaitForEndOfState("INIT_TASK");
splitter.ChangeState("RUN");
splitter.InteractiveStateLoop();
} }
catch (std::exception& e) catch (std::exception& e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << "Unhandled Exception reached the top of main: "
LOG(INFO) << "Command line options are the following: "; << e.what() << ", application will now exit";
config.PrintHelp();
return 1; return 1;
} }

View File

@ -25,16 +25,18 @@ echo "Usage: startBenchmark [message size=1000000] [number of messages=0]"
SAMPLER="bsampler" SAMPLER="bsampler"
SAMPLER+=" --id bsampler1" SAMPLER+=" --id bsampler1"
#SAMPLER+=" --io-threads 2" #SAMPLER+=" --io-threads 2"
#SAMPLER+=" --control static"
#SAMPLER+=" --transport nanomsg" #SAMPLER+=" --transport nanomsg"
SAMPLER+=" --msg-size $msgSize" SAMPLER+=" --msg-size $msgSize"
SAMPLER+=" --num-msgs $numMsgs" SAMPLER+=" --num-msgs $numMsgs"
SAMPLER+=" --config-json-file @CMAKE_BINARY_DIR@/bin/config/benchmark.json" SAMPLER+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+0+0 -hold -e taskset 0x1 @CMAKE_BINARY_DIR@/bin/$SAMPLER & xterm -geometry 80x23+0+0 -hold -e @CMAKE_BINARY_DIR@/bin/$SAMPLER &
SINK="sink" SINK="sink"
SINK+=" --id sink1" SINK+=" --id sink1"
#SINK+=" --io-threads 2" #SINK+=" --io-threads 2"
#SINK+=" --control static"
#SINK+=" --transport nanomsg" #SINK+=" --transport nanomsg"
SINK+=" --num-msgs $numMsgs" SINK+=" --num-msgs $numMsgs"
SINK+=" --config-json-file @CMAKE_BINARY_DIR@/bin/config/benchmark.json" SINK+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+500+0 -hold -e taskset 0x2 @CMAKE_BINARY_DIR@/bin/$SINK & xterm -geometry 80x23+500+0 -hold -e @CMAKE_BINARY_DIR@/bin/$SINK &

View File

@ -21,24 +21,14 @@
#include "FairMQParser.h" #include "FairMQParser.h"
#include "FairMQProgOptions.h" #include "FairMQProgOptions.h"
// template function that take any device, // template function that takes any device
// and run a simple MQ state machine configured from a JSON file // and runs a simple MQ state machine configured from a JSON file
template<typename TMQDevice> template<typename TMQDevice>
inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config) inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
{ {
device.CatchSignals(); device.CatchSignals();
std::string id = config.GetValue<std::string>("id");
int ioThreads = config.GetValue<int>("io-threads");
device.fChannels = config.GetFairMQMap();
device.SetProperty(TMQDevice::Id, id);
device.SetProperty(TMQDevice::NumIoThreads, ioThreads);
LOG(INFO) << "PID: " << getpid();
device.SetTransport(config.GetValue<std::string>("transport"));
device.SetConfig(config);
device.ChangeState(TMQDevice::INIT_DEVICE); device.ChangeState(TMQDevice::INIT_DEVICE);
device.WaitForEndOfState(TMQDevice::INIT_DEVICE); device.WaitForEndOfState(TMQDevice::INIT_DEVICE);
@ -46,43 +36,36 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
device.WaitForEndOfState(TMQDevice::INIT_TASK); device.WaitForEndOfState(TMQDevice::INIT_TASK);
device.ChangeState(TMQDevice::RUN); device.ChangeState(TMQDevice::RUN);
device.InteractiveStateLoop();
return 0; std::string control = config.GetValue<std::string>("control");
}
template<typename TMQDevice> // TODO: Extend this with DDS (requires optional dependency?)?
inline int runNonInteractiveStateMachine(TMQDevice& device, FairMQProgOptions& config) if (control == "interactive")
{ {
device.CatchSignals(); device.InteractiveStateLoop();
std::string id = config.GetValue<std::string>("id"); }
int ioThreads = config.GetValue<int>("io-threads"); else if (control == "static")
{
device.ChangeState(TMQDevice::RUN);
device.WaitForEndOfState(TMQDevice::RUN);
device.fChannels = config.GetFairMQMap(); device.ChangeState(TMQDevice::RESET_TASK);
device.WaitForEndOfState(TMQDevice::RESET_TASK);
device.SetProperty(TMQDevice::Id, id); device.ChangeState(TMQDevice::RESET_DEVICE);
device.SetProperty(TMQDevice::NumIoThreads, ioThreads); device.WaitForEndOfState(TMQDevice::RESET_DEVICE);
LOG(INFO) << "PID: " << getpid(); device.ChangeState(TMQDevice::END);
}
device.SetTransport(config.GetValue<std::string>("transport")); else
{
device.ChangeState(TMQDevice::INIT_DEVICE); LOG(ERROR) << "Requested control mechanism '" << control << "' is not available.";
device.WaitForEndOfState(TMQDevice::INIT_DEVICE); LOG(ERROR) << "Currently available are:"
<< " 'interactive'"
device.ChangeState(TMQDevice::INIT_TASK); << ", 'static'"
device.WaitForEndOfState(TMQDevice::INIT_TASK); << ". Exiting.";
exit(EXIT_FAILURE);
device.ChangeState(TMQDevice::RUN); }
device.WaitForEndOfState(TMQDevice::RUN);
device.ChangeState(TMQDevice::RESET_TASK);
device.WaitForEndOfState(TMQDevice::RESET_TASK);
device.ChangeState(TMQDevice::RESET_DEVICE);
device.WaitForEndOfState(TMQDevice::RESET_DEVICE);
device.ChangeState(TMQDevice::END);
return 0; return 0;
} }