Several FairMQ fixes and improvements:

- FairMQ: add possibility to poll on multiple channels.
- FairMQ: include command channel when polling on blocking calls (for unblocking without termination).
- FairMQ: move signal handler inside of FairMQDevice class (call FairMQDevice::CatchSignals() in the main function).
- FairMQ: add 'bool CheckCurrentState(statename)' (instead of 'GetCurrentState() == statename' that cannot be thread safe).
- FairMQDevice: add 'InteractiveStateLoop()' method that can be used to change states from the command line.
- FairMQDevice: add automatic transition to IDLE state if Run() exits without an external event.
- FairMQDevice: implement device reset.
- FairMQDevice: use unordered_map for device channels.
- FairMQChannel: improve address validation for channels.
- FairMQChannel: add ExpectsAnotherPart() method to check if another msg part is expected (old approach still works).
- FairMQ: remove invalid transition from the run files.
- FairMQFileSink: disable ROOT termination signal handler.
- Tutorial3: spawn xterm windows from start scripts without overlapping for better visibility.
- FairMQ Examples: update protobuf test and move its files to a common directory.
- FairMQStateMachine: improve feedback on invalid transitions (more readable).
This commit is contained in:
Alexey Rybalchenko
2015-07-03 22:57:36 +02:00
committed by Mohammad Al-Turany
parent d1bba61939
commit 1302e77a16
65 changed files with 1250 additions and 2234 deletions

View File

@@ -40,12 +40,15 @@ void FairMQBenchmarkSampler::Run()
void* buffer = operator new[](fEventSize);
FairMQMessage* baseMsg = fTransportFactory->CreateMessage(buffer, fEventSize);
while (GetCurrentState() == RUNNING)
// store the channel reference to avoid traversing the map on every loop iteration
const FairMQChannel& dataChannel = fChannels.at("data-out").at(0);
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
msg->Copy(baseMsg);
fChannels["data-out"].at(0).Send(msg);
dataChannel.Send(msg);
--fEventCounter;
@@ -69,7 +72,7 @@ void FairMQBenchmarkSampler::Run()
void FairMQBenchmarkSampler::ResetEventCounter()
{
while (GetCurrentState() == RUNNING)
while (CheckCurrentState(RUNNING))
{
try
{

View File

@@ -26,13 +26,17 @@ FairMQBuffer::FairMQBuffer()
void FairMQBuffer::Run()
{
while (GetCurrentState() == RUNNING)
// store the channel references to avoid traversing the map on every loop iteration
const FairMQChannel& dataInChannel = fChannels.at("data-in").at(0);
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
if (fChannels["data-in"].at(0).Receive(msg) > 0)
if (dataInChannel.Receive(msg) > 0)
{
fChannels["data-out"].at(0).Send(msg);
dataOutChannel.Send(msg);
}
delete msg;

View File

@@ -29,21 +29,38 @@ FairMQMerger::~FairMQMerger()
void FairMQMerger::Run()
{
FairMQPoller* poller = fTransportFactory->CreatePoller(fChannels["data-in"]);
FairMQPoller* poller = fTransportFactory->CreatePoller(fChannels.at("data-in"));
while (GetCurrentState() == RUNNING)
// store the channel references to avoid traversing the map on every loop iteration
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
FairMQChannel* dataInChannels[fChannels.at("data-in").size()];
for (int i = 0; i < fChannels.at("data-in").size(); ++i)
{
dataInChannels[i] = &(fChannels.at("data-in").at(i));
}
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
poller->Poll(100);
for (int i = 0; i < fChannels["data-in"].size(); ++i)
for (int i = 0; i < fChannels.at("data-in").size(); ++i)
{
if (poller->CheckInput(i))
{
if (fChannels["data-in"].at(i).Receive(msg))
if (dataInChannels[i]->Receive(msg) > 0)
{
fChannels["data-out"].at(0).Send(msg);
if (dataOutChannel.Send(msg) < 0)
{
LOG(DEBUG) << "Blocking send interrupted by a command";
break;
}
}
else
{
LOG(DEBUG) << "Blocking receive interrupted by a command";
break;
}
}
}

View File

@@ -30,11 +30,15 @@ void FairMQProxy::Run()
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
while (GetCurrentState() == RUNNING)
// store the channel references to avoid traversing the map on every loop iteration
const FairMQChannel& dataInChannel = fChannels.at("data-in").at(0);
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
while (CheckCurrentState(RUNNING))
{
if (fChannels["data-in"].at(0).Receive(msg) > 0)
if (dataInChannel.Receive(msg) > 0)
{
fChannels["data-out"].at(0).Send(msg);
dataOutChannel.Send(msg);
}
}

View File

@@ -24,11 +24,14 @@ FairMQSink::FairMQSink()
void FairMQSink::Run()
{
while (GetCurrentState() == RUNNING)
// store the channel reference to avoid traversing the map on every loop iteration
const FairMQChannel& dataChannel = fChannels.at("data-in").at(0);
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
fChannels["data-in"].at(0).Receive(msg);
dataChannel.Receive(msg);
delete msg;
}

View File

@@ -29,16 +29,25 @@ FairMQSplitter::~FairMQSplitter()
void FairMQSplitter::Run()
{
int direction = 0;
int numOutputs = fChannels.at("data-out").size();
while (GetCurrentState() == RUNNING)
// store the channel references to avoid traversing the map on every loop iteration
const FairMQChannel& dataInChannel = fChannels.at("data-in").at(0);
FairMQChannel* dataOutChannels[fChannels.at("data-out").size()];
for (int i = 0; i < numOutputs; ++i)
{
dataOutChannels[i] = &(fChannels.at("data-out").at(i));
}
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
if (fChannels["data-in"].at(0).Receive(msg) > 0)
if (dataInChannel.Receive(msg) > 0)
{
fChannels["data-out"].at(direction).Send(msg);
direction++;
if (direction >= fChannels["data-out"].size())
dataOutChannels[direction]->Send(msg);
++direction;
if (direction >= numOutputs)
{
direction = 0;
}

View File

@@ -89,4 +89,3 @@ class GenericFileSink : public FairMQDevice, public InputPolicy, public OutputPo
};
#endif /* GENERICFILESINK_H */

View File

@@ -44,10 +44,10 @@ void GenericFileSink<InputPolicy, OutputPolicy>::Run()
{
int receivedMsg = 0;
while (GetCurrentState() == RUNNING)
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
if (fChannels["data-in"].at(0).Receive(msg) > 0)
if (fChannels.at("data-in").at(0).Receive(msg) > 0)
{
OutputPolicy::AddToFile(InputPolicy::DeSerializeMsg(msg));
receivedMsg++;

View File

@@ -92,10 +92,7 @@ class GenericProcessor : public FairMQDevice, public InputPolicy, public OutputP
// bool ReceivePart();
bool ReceivePart()
{
int64_t more = 0;
size_t more_size = sizeof(more);
fChannels["data-in"].at(0).fSocket->GetOption("rcv-more", &more, &more_size);
if (more)
if (fChannels["data-in"].at(0).ExpectsAnotherPart())
{
InputPolicy::CloseMessage();
// fProcessorTask->GetPayload()->CloseMessage();
@@ -123,7 +120,7 @@ class GenericProcessor : public FairMQDevice, public InputPolicy, public OutputP
int receivedMsgs = 0;
int sentMsgs = 0;
while (GetCurrentState() == RUNNING)
while (CheckCurrentState(RUNNING))
{
FairMQMessage* msg = fTransportFactory->CreateMessage();

View File

@@ -51,8 +51,9 @@ void base_GenericSampler<T,U,K,L>::Run()
boost::timer::auto_cpu_timer timer;
LOG(INFO) << "Number of events to process: " << fNumEvents;
do {
do
{
for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++)
{
for(auto& p : fChannels[fOutChanName])
@@ -75,7 +76,7 @@ void base_GenericSampler<T,U,K,L>::Run()
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
// }
if (GetCurrentState() != RUNNING)
if (!CheckCurrentState(RUNNING))
break;
}
// if more than one socket, remove the last incrementation
@@ -83,7 +84,7 @@ void base_GenericSampler<T,U,K,L>::Run()
fCurrentIdx--;
}
}
while ( GetCurrentState() == RUNNING && fContinuous );
while (CheckCurrentState(RUNNING) && fContinuous);
boost::timer::cpu_times const elapsed_time(timer.elapsed());
LOG(INFO) << "Sent everything in:\n" << boost::timer::format(elapsed_time, 2);