mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
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:
committed by
Mohammad Al-Turany
parent
d1bba61939
commit
1302e77a16
@@ -1,8 +1,8 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "FairMQBinSampler.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQBinSampler::FairMQBinSampler()
|
||||
: fEventSize(10000)
|
||||
, fEventRate(1)
|
||||
@@ -33,25 +35,18 @@ FairMQBinSampler::~FairMQBinSampler()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQBinSampler::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQBinSampler::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
// boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
boost::thread resetEventCounter(boost::bind(&FairMQBinSampler::ResetEventCounter, this));
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
LOG(DEBUG) << "Message size: " << fEventSize * sizeof(Content) << " bytes.";
|
||||
|
||||
while (fState == RUNNING)
|
||||
{
|
||||
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
Content* payload = new Content[fEventSize];
|
||||
|
||||
for (int i = 0; i < fEventSize; ++i)
|
||||
@@ -67,7 +62,7 @@ void FairMQBinSampler::Run()
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage(fEventSize * sizeof(Content));
|
||||
memcpy(msg->GetData(), payload, fEventSize * sizeof(Content));
|
||||
|
||||
fPayloadOutputs->at(0)->Send(msg);
|
||||
dataOutChannel.Send(msg);
|
||||
|
||||
--fEventCounter;
|
||||
|
||||
@@ -80,16 +75,13 @@ void FairMQBinSampler::Run()
|
||||
delete msg;
|
||||
}
|
||||
|
||||
rateLogger.interrupt();
|
||||
resetEventCounter.interrupt();
|
||||
|
||||
rateLogger.join();
|
||||
resetEventCounter.join();
|
||||
}
|
||||
|
||||
void FairMQBinSampler::ResetEventCounter()
|
||||
{
|
||||
while (true)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -103,61 +95,26 @@ void FairMQBinSampler::ResetEventCounter()
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBinSampler::Log(int intervalInMs)
|
||||
{
|
||||
timestamp_t t0;
|
||||
timestamp_t t1;
|
||||
unsigned long bytes = fPayloadOutputs->at(0)->GetBytesTx();
|
||||
unsigned long messages = fPayloadOutputs->at(0)->GetMessagesTx();
|
||||
unsigned long bytesNew = 0;
|
||||
unsigned long messagesNew = 0;
|
||||
double megabytesPerSecond = 0;
|
||||
double messagesPerSecond = 0;
|
||||
|
||||
t0 = get_timestamp();
|
||||
|
||||
while (true)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(intervalInMs));
|
||||
|
||||
t1 = get_timestamp();
|
||||
|
||||
bytesNew = fPayloadOutputs->at(0)->GetBytesTx();
|
||||
messagesNew = fPayloadOutputs->at(0)->GetMessagesTx();
|
||||
|
||||
timestamp_t timeSinceLastLog_ms = (t1 - t0) / 1000.0L;
|
||||
|
||||
megabytesPerSecond = ((double)(bytesNew - bytes) / (1024. * 1024.)) / (double)timeSinceLastLog_ms * 1000.;
|
||||
messagesPerSecond = (double)(messagesNew - messages) / (double)timeSinceLastLog_ms * 1000.;
|
||||
|
||||
LOG(DEBUG) << "send " << messagesPerSecond << " msg/s, " << megabytesPerSecond << " MB/s";
|
||||
|
||||
bytes = bytesNew;
|
||||
messages = messagesNew;
|
||||
t0 = t1;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBinSampler::SetProperty(const int key, const string& value, const int slot /*= 0*/)
|
||||
void FairMQBinSampler::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQBinSampler::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
|
||||
string FairMQBinSampler::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBinSampler::SetProperty(const int key, const int value, const int slot /*= 0*/)
|
||||
void FairMQBinSampler::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@@ -168,12 +125,12 @@ void FairMQBinSampler::SetProperty(const int key, const int value, const int slo
|
||||
fEventRate = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQBinSampler::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
|
||||
int FairMQBinSampler::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@@ -182,6 +139,6 @@ int FairMQBinSampler::GetProperty(const int key, const int default_ /*= 0*/, con
|
||||
case EventRate:
|
||||
return fEventRate;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user