mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Add example/test for built-in devices
This commit is contained in:
committed by
Dennis Klein
parent
ffab4ac78c
commit
d4a4ea14d2
@@ -18,7 +18,8 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
|
||||
: fSameMessage(true)
|
||||
: fMultipart(false)
|
||||
, fNumParts(1)
|
||||
, fMsgSize(10000)
|
||||
, fMsgRate(0)
|
||||
, fNumIterations(0)
|
||||
@@ -33,8 +34,9 @@ FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
|
||||
|
||||
void FairMQBenchmarkSampler::InitTask()
|
||||
{
|
||||
fSameMessage = fConfig->GetValue<bool>("same-msg");
|
||||
fMsgSize = fConfig->GetValue<int>("msg-size");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fNumParts = fConfig->GetValue<size_t>("num-parts");
|
||||
fMsgSize = fConfig->GetValue<size_t>("msg-size");
|
||||
fMsgRate = fConfig->GetValue<float>("msg-rate");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
@@ -54,12 +56,16 @@ void FairMQBenchmarkSampler::Run()
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
if (fSameMessage)
|
||||
if (fMultipart)
|
||||
{
|
||||
FairMQMessagePtr msg(dataOutChannel.NewMessage());
|
||||
msg->Copy(*baseMsg);
|
||||
FairMQParts parts;
|
||||
|
||||
if (dataOutChannel.Send(msg) >= 0)
|
||||
for (size_t i = 0; i < fNumParts; ++i)
|
||||
{
|
||||
parts.AddPart(dataOutChannel.NewMessage(fMsgSize));
|
||||
}
|
||||
|
||||
if (dataOutChannel.Send(parts) >= 0)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
|
@@ -26,8 +26,9 @@ class FairMQBenchmarkSampler : public FairMQDevice
|
||||
virtual ~FairMQBenchmarkSampler();
|
||||
|
||||
protected:
|
||||
bool fSameMessage;
|
||||
int fMsgSize;
|
||||
bool fMultipart;
|
||||
size_t fNumParts;
|
||||
size_t fMsgSize;
|
||||
std::atomic<int> fMsgCounter;
|
||||
float fMsgRate;
|
||||
uint64_t fNumIterations;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQMerger::FairMQMerger()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fInChannelName("data-in")
|
||||
, fOutChannelName("data-out")
|
||||
{
|
||||
@@ -30,6 +30,8 @@ void FairMQMerger::RegisterChannelEndpoints()
|
||||
{
|
||||
RegisterChannelEndpoint(fInChannelName, 1, 10000);
|
||||
RegisterChannelEndpoint(fOutChannelName, 1, 1);
|
||||
|
||||
PrintRegisteredChannels();
|
||||
}
|
||||
|
||||
FairMQMerger::~FairMQMerger()
|
||||
@@ -38,7 +40,7 @@ FairMQMerger::~FairMQMerger()
|
||||
|
||||
void FairMQMerger::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ class FairMQMerger : public FairMQDevice
|
||||
virtual ~FairMQMerger();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQMultiplier::FairMQMultiplier()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fNumOutputs(0)
|
||||
, fInChannelName()
|
||||
, fOutChannelNames()
|
||||
@@ -27,7 +27,7 @@ FairMQMultiplier::~FairMQMultiplier()
|
||||
|
||||
void FairMQMultiplier::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelNames = fConfig->GetValue<vector<string>>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size();
|
||||
|
@@ -20,7 +20,7 @@ class FairMQMultiplier : public FairMQDevice
|
||||
virtual ~FairMQMultiplier();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
int fNumOutputs;
|
||||
std::string fInChannelName;
|
||||
std::vector<std::string> fOutChannelNames;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQProxy::FairMQProxy()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fInChannelName()
|
||||
, fOutChannelName()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ FairMQProxy::~FairMQProxy()
|
||||
|
||||
void FairMQProxy::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ class FairMQProxy : public FairMQDevice
|
||||
virtual ~FairMQProxy();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
|
@@ -27,7 +27,8 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
{
|
||||
public:
|
||||
FairMQSink()
|
||||
: fMaxIterations(0)
|
||||
: fMultipart(false)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
, fInChannelName()
|
||||
{}
|
||||
@@ -36,12 +37,14 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
{}
|
||||
|
||||
protected:
|
||||
bool fMultipart;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
std::string fInChannelName;
|
||||
|
||||
virtual void InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
fInChannelName = fConfig->GetValue<std::string>("in-channel");
|
||||
}
|
||||
@@ -56,18 +59,39 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
||||
|
||||
if (dataInChannel.Receive(msg) >= 0)
|
||||
if (fMultipart)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
FairMQParts parts;
|
||||
|
||||
if (dataInChannel.Receive(parts) >= 0)
|
||||
{
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
break;
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(info) << "Configured maximum number of iterations reached.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
||||
|
||||
if (dataInChannel.Receive(msg) >= 0)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(info) << "Configured maximum number of iterations reached.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQSplitter::FairMQSplitter()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fNumOutputs(0)
|
||||
, fDirection(0)
|
||||
, fInChannelName()
|
||||
@@ -34,7 +34,7 @@ FairMQSplitter::~FairMQSplitter()
|
||||
|
||||
void FairMQSplitter::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelName).size();
|
||||
|
@@ -26,7 +26,7 @@ class FairMQSplitter : public FairMQDevice
|
||||
virtual ~FairMQSplitter();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
int fNumOutputs;
|
||||
int fDirection;
|
||||
std::string fInChannelName;
|
||||
|
@@ -16,7 +16,9 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("out-channel", bpo::value<std::string>()->default_value("data"), "Name of the output channel")
|
||||
("same-msg", bpo::value<bool>()->default_value(false), "Re-send the same message, or recreate for each iteration")
|
||||
("msg-size", bpo::value<int>()->default_value(1000000), "Message size in bytes")
|
||||
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads")
|
||||
("num-parts", bpo::value<size_t>()->default_value(1), "Number of parts to send. 1 will send single messages, not parts")
|
||||
("msg-size", bpo::value<size_t>()->default_value(1000000), "Message size in bytes")
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
|
||||
("msg-rate", bpo::value<float>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::vector<std::string>>()->multitoken(), "Names of the output channels")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -15,7 +15,8 @@ void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data"), "Name of the input channel")
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)");
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
|
||||
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -5,7 +5,6 @@ export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
|
||||
maxIterations="0"
|
||||
msgSize="1000000"
|
||||
transport="zeromq"
|
||||
sameMsg="true"
|
||||
affinity="false"
|
||||
affinitySamp=""
|
||||
affinitySink=""
|
||||
@@ -24,11 +23,7 @@ if [[ $3 =~ ^[a-z]+$ ]]; then
|
||||
fi
|
||||
|
||||
if [[ $4 =~ ^[a-z]+$ ]]; then
|
||||
sameMsg=$4
|
||||
fi
|
||||
|
||||
if [[ $5 =~ ^[a-z]+$ ]]; then
|
||||
affinity=$5
|
||||
affinity=$4
|
||||
fi
|
||||
|
||||
|
||||
@@ -45,12 +40,6 @@ fi
|
||||
|
||||
echo "transport: $transport"
|
||||
|
||||
if [ $sameMsg = "true" ]; then
|
||||
echo "resend same message: yes, using Copy() method to resend the same message"
|
||||
else
|
||||
echo "resend same message: no, allocating each message separately"
|
||||
fi
|
||||
|
||||
if [ $affinity = "true" ]; then
|
||||
affinitySamp="taskset -c 0"
|
||||
affinitySink="taskset -c 1"
|
||||
@@ -60,7 +49,7 @@ else
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Usage: startBenchmark [message size=1000000] [number of iterations=0] [transport=zeromq/nanomsg/shmem] [resend same message=true] [affinity=false]"
|
||||
echo "Usage: startBenchmark [message size=1000000] [number of iterations=0] [transport=zeromq/nanomsg/shmem] [affinity=false]"
|
||||
|
||||
SAMPLER="fairmq-bsampler"
|
||||
SAMPLER+=" --id bsampler1"
|
||||
@@ -69,7 +58,7 @@ SAMPLER+=" --id bsampler1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --severity debug"
|
||||
SAMPLER+=" --msg-size $msgSize"
|
||||
SAMPLER+=" --same-msg $sameMsg"
|
||||
SAMPLER+=" --num-parts 1"
|
||||
# SAMPLER+=" --msg-rate 1000"
|
||||
SAMPLER+=" --max-iterations $maxIterations"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:5555"
|
||||
@@ -84,6 +73,7 @@ SINK+=" --id sink1"
|
||||
#SINK+=" --control static"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --severity debug"
|
||||
SINK+=" --multipart false"
|
||||
SINK+=" --max-iterations $maxIterations"
|
||||
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:5555"
|
||||
xterm -geometry 90x50+550+0 -hold -e $affinitySink @CMAKE_CURRENT_BINARY_DIR@/$SINK &
|
||||
|
Reference in New Issue
Block a user