FairMQ/fairmq/devices/FairMQBenchmarkSampler.cxx
Alexey Rybalchenko 732373faa2 Update multi-part features (nanomsg) and various fixes
- Implement nanomsg multipart with MessagePack.
 - Use the MessagePack from FairSoft and handle not found case.
 - Update splitter, merger and proxy devices to handle multi-part.
 - Let FairMQParts.At() return pointer reference (can be used for moving).
 - Add missing const specifier in the message interface.
 - Add transmit kernel size setting to channels (ZMQ_SNDBUF).
 - Remove FairMQBuffer device.
 - Remove old multi-part methods from Tutorial3 example (to be replaced with Parts API).
 - Make callback mandatory for newMsg(data, size, callback).
 - Add missing <vector> include in FairMQSocket.
2016-03-24 13:36:47 +01:00

140 lines
3.6 KiB
C++

/********************************************************************************
* 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 <boost/timer/timer.hpp>
#include "FairMQBenchmarkSampler.h"
#include "FairMQLogger.h"
using namespace std;
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
: fMsgSize(10000)
, fNumMsgs(0)
{
}
FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
{
}
void FairMQBenchmarkSampler::Run()
{
int numSentMsgs = 0;
unique_ptr<FairMQMessage> baseMsg(fTransportFactory->CreateMessage(fMsgSize));
// store the channel reference to avoid traversing the map on every loop iteration
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
LOG(INFO) << "Starting the benchmark with message size of " << fMsgSize << " and number of messages " << fNumMsgs << ".";
boost::timer::auto_cpu_timer timer;
while (CheckCurrentState(RUNNING))
{
unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
msg->Copy(baseMsg);
if (dataOutChannel.Send(msg) >= 0)
{
if (fNumMsgs > 0)
{
numSentMsgs++;
if (numSentMsgs >= fNumMsgs)
{
break;
}
}
}
}
LOG(INFO) << "Sent " << numSentMsgs << " messages, leaving RUNNING state.";
LOG(INFO) << "Sending time: ";
}
void FairMQBenchmarkSampler::SetProperty(const int key, const string& value)
{
switch (key)
{
default:
FairMQDevice::SetProperty(key, value);
break;
}
}
string FairMQBenchmarkSampler::GetProperty(const int key, const string& default_ /*= ""*/)
{
switch (key)
{
default:
return FairMQDevice::GetProperty(key, default_);
}
}
void FairMQBenchmarkSampler::SetProperty(const int key, const int value)
{
switch (key)
{
case MsgSize:
fMsgSize = value;
break;
case NumMsgs:
fNumMsgs = value;
break;
default:
FairMQDevice::SetProperty(key, value);
break;
}
}
int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*/)
{
switch (key)
{
case MsgSize:
return fMsgSize;
case NumMsgs:
return fNumMsgs;
default:
return FairMQDevice::GetProperty(key, default_);
}
}
string FairMQBenchmarkSampler::GetPropertyDescription(const int key)
{
switch (key)
{
case MsgSize:
return "MsgSize: Size of the transfered message buffer.";
case NumMsgs:
return "NumMsgs: Number of messages to send.";
default:
return FairMQDevice::GetPropertyDescription(key);
}
}
void FairMQBenchmarkSampler::ListProperties()
{
LOG(INFO) << "Properties of FairMQBenchmarkSampler:";
for (int p = FairMQConfigurable::Last; p < FairMQBenchmarkSampler::Last; ++p)
{
LOG(INFO) << " " << GetPropertyDescription(p);
}
LOG(INFO) << "---------------------------";
}