Fix CIDs 10587, 10813, 10911, 10912, 10402, 10403, 10577, 10578, 10579, 10848, 10861, 10865, 10868, 10910.

Move classes inheriting from device to a subdirectory.
Make sure only protobuf library installed by fairsoft is used.
Cleanup FairMQDevice and fix some initialization list warnings.
Loop to duplicate input files in Sampler.
Add some documentation to FairMQ.
This commit is contained in:
Alexey Rybalchenko
2014-07-21 15:15:40 +02:00
parent fe91e5af96
commit 281fcc459c
19 changed files with 183 additions and 159 deletions

View File

@@ -0,0 +1,176 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQBenchmarkSampler.cpp
*
* @since 2013-04-23
* @author D. Klein, A. Rybalchenko
*/
#include <vector>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQBenchmarkSampler.h"
#include "FairMQLogger.h"
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
: fEventSize(10000)
, fEventRate(1)
, fEventCounter(0)
{
}
FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
{
}
void FairMQBenchmarkSampler::Init()
{
FairMQDevice::Init();
}
void FairMQBenchmarkSampler::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(&FairMQBenchmarkSampler::ResetEventCounter, this));
void* buffer = operator new[](fEventSize);
FairMQMessage* base_msg = fTransportFactory->CreateMessage(buffer, fEventSize);
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
msg->Copy(base_msg);
fPayloadOutputs->at(0)->Send(msg);
--fEventCounter;
while (fEventCounter == 0)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
delete msg;
}
delete base_msg;
try {
rateLogger.interrupt();
resetEventCounter.interrupt();
rateLogger.join();
resetEventCounter.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}
void FairMQBenchmarkSampler::ResetEventCounter()
{
while (true)
{
try
{
fEventCounter = fEventRate / 100;
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
}
catch (boost::thread_interrupted&)
{
break;
}
}
}
void FairMQBenchmarkSampler::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 FairMQBenchmarkSampler::SetProperty(const int key, const string& value, const int slot /*= 0*/)
{
switch (key)
{
default:
FairMQDevice::SetProperty(key, value, slot);
break;
}
}
string FairMQBenchmarkSampler::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
{
switch (key)
{
default:
return FairMQDevice::GetProperty(key, default_, slot);
}
}
void FairMQBenchmarkSampler::SetProperty(const int key, const int value, const int slot /*= 0*/)
{
switch (key)
{
case EventSize:
fEventSize = value;
break;
case EventRate:
fEventRate = value;
break;
default:
FairMQDevice::SetProperty(key, value, slot);
break;
}
}
int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
{
switch (key)
{
case EventSize:
return fEventSize;
case EventRate:
return fEventRate;
default:
return FairMQDevice::GetProperty(key, default_, slot);
}
}

View File

@@ -0,0 +1,53 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQBenchmarkSampler.h
*
* @since 2013-04-23
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQBENCHMARKSAMPLER_H_
#define FAIRMQBENCHMARKSAMPLER_H_
#include <string>
#include "FairMQDevice.h"
/**
* Sampler to generate traffic for benchmarking.
*/
class FairMQBenchmarkSampler : public FairMQDevice
{
public:
enum
{
InputFile = FairMQDevice::Last,
EventRate,
EventSize,
Last
};
FairMQBenchmarkSampler();
virtual ~FairMQBenchmarkSampler();
void Log(int intervalInMs);
void ResetEventCounter();
virtual void SetProperty(const int key, const string& value, const int slot = 0);
virtual string GetProperty(const int key, const string& default_ = "", const int slot = 0);
virtual void SetProperty(const int key, const int value, const int slot = 0);
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
protected:
int fEventSize;
int fEventRate;
int fEventCounter;
virtual void Init();
virtual void Run();
};
#endif /* FAIRMQBENCHMARKSAMPLER_H_ */

View File

@@ -0,0 +1,59 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQBuffer.cxx
*
* @since 2012-10-25
* @author D. Klein, A. Rybalchenko
*/
#include <iostream>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQBuffer.h"
#include "FairMQLogger.h"
FairMQBuffer::FairMQBuffer()
{
}
void FairMQBuffer::Run()
{
LOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
bool received = false;
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
received = fPayloadInputs->at(0)->Receive(msg);
if (received)
{
fPayloadOutputs->at(0)->Send(msg);
received = false;
}
delete msg;
}
try {
rateLogger.interrupt();
rateLogger.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}
FairMQBuffer::~FairMQBuffer()
{
}

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQBuffer.h
*
* @since 2012-10-25
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQBUFFER_H_
#define FAIRMQBUFFER_H_
#include "FairMQDevice.h"
class FairMQBuffer : public FairMQDevice
{
public:
FairMQBuffer();
virtual ~FairMQBuffer();
protected:
virtual void Run();
};
#endif /* FAIRMQBUFFER_H_ */

View File

@@ -0,0 +1,70 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQMerger.cxx
*
* @since 2012-12-06
* @author D. Klein, A. Rybalchenko
*/
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQLogger.h"
#include "FairMQMerger.h"
#include "FairMQPoller.h"
FairMQMerger::FairMQMerger()
{
}
FairMQMerger::~FairMQMerger()
{
}
void FairMQMerger::Run()
{
LOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
FairMQPoller* poller = fTransportFactory->CreatePoller(*fPayloadInputs);
bool received = false;
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
poller->Poll(100);
for (int i = 0; i < fNumInputs; i++)
{
if (poller->CheckInput(i))
{
received = fPayloadInputs->at(i)->Receive(msg);
}
if (received)
{
fPayloadOutputs->at(0)->Send(msg);
received = false;
}
}
delete msg;
}
delete poller;
try {
rateLogger.interrupt();
rateLogger.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQMerger.h
*
* @since 2012-12-06
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQMERGER_H_
#define FAIRMQMERGER_H_
#include "FairMQDevice.h"
class FairMQMerger : public FairMQDevice
{
public:
FairMQMerger();
virtual ~FairMQMerger();
protected:
virtual void Run();
};
#endif /* FAIRMQMERGER_H_ */

View File

@@ -0,0 +1,57 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQProxy.cxx
*
* @since 2013-10-02
* @author A. Rybalchenko
*/
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQLogger.h"
#include "FairMQProxy.h"
FairMQProxy::FairMQProxy()
{
}
FairMQProxy::~FairMQProxy()
{
}
void FairMQProxy::Run()
{
LOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
FairMQMessage* msg = fTransportFactory->CreateMessage();
size_t bytes_received = 0;
while (fState == RUNNING)
{
bytes_received = fPayloadInputs->at(0)->Receive(msg);
if (bytes_received)
{
fPayloadOutputs->at(0)->Send(msg);
bytes_received = 0;
}
}
delete msg;
try {
rateLogger.interrupt();
rateLogger.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQProxy.h
*
* @since 2013-10-02
* @author A. Rybalchenko
*/
#ifndef FAIRMQPROXY_H_
#define FAIRMQPROXY_H_
#include "FairMQDevice.h"
class FairMQProxy : public FairMQDevice
{
public:
FairMQProxy();
virtual ~FairMQProxy();
protected:
virtual void Run();
};
#endif /* FAIRMQPROXY_H_ */

View File

@@ -0,0 +1,52 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQSink.cxx
*
* @since 2013-01-09
* @author D. Klein, A. Rybalchenko
*/
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQSink.h"
#include "FairMQLogger.h"
FairMQSink::FairMQSink()
{
}
void FairMQSink::Run()
{
LOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
size_t bytes_received = 0;
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
bytes_received = fPayloadInputs->at(0)->Receive(msg);
delete msg;
}
try {
rateLogger.interrupt();
rateLogger.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}
FairMQSink::~FairMQSink()
{
}

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQSink.h
*
* @since 2013-01-09
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQSINK_H_
#define FAIRMQSINK_H_
#include "FairMQDevice.h"
class FairMQSink : public FairMQDevice
{
public:
FairMQSink();
virtual ~FairMQSink();
protected:
virtual void Run();
};
#endif /* FAIRMQSINK_H_ */

View File

@@ -0,0 +1,64 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQSplitter.cxx
*
* @since 2012-12-06
* @author D. Klein, A. Rybalchenko
*/
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQLogger.h"
#include "FairMQSplitter.h"
FairMQSplitter::FairMQSplitter()
{
}
FairMQSplitter::~FairMQSplitter()
{
}
void FairMQSplitter::Run()
{
LOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
bool received = false;
int direction = 0;
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
received = fPayloadInputs->at(0)->Receive(msg);
if (received)
{
fPayloadOutputs->at(direction)->Send(msg);
direction++;
if (direction >= fNumOutputs)
{
direction = 0;
}
received = false;
}
delete msg;
}
try {
rateLogger.interrupt();
rateLogger.join();
} catch(boost::thread_resource_error& e) {
LOG(ERROR) << e.what();
}
}

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* 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, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQSplitter.h
*
* @since 2012-12-06
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQSPLITTER_H_
#define FAIRMQSPLITTER_H_
#include "FairMQDevice.h"
class FairMQSplitter : public FairMQDevice
{
public:
FairMQSplitter();
virtual ~FairMQSplitter();
protected:
virtual void Run();
};
#endif /* FAIRMQSPLITTER_H_ */