builtin devices: Reorganize

This commit is contained in:
Dennis Klein
2021-03-24 12:53:20 +01:00
committed by Dennis Klein
parent 66a4df0667
commit fc49687879
15 changed files with 132 additions and 125 deletions

View File

@@ -1,32 +1,35 @@
/********************************************************************************
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIRMQBENCHMARKSAMPLER_H_
#define FAIRMQBENCHMARKSAMPLER_H_
#ifndef FAIR_MQ_BENCHMARKSAMPLER_H
#define FAIR_MQ_BENCHMARKSAMPLER_H
#include "FairMQLogger.h"
#include "FairMQDevice.h"
#include "fairmq/tools/RateLimit.h"
#include <fairmq/Device.h>
#include <fairmq/tools/RateLimit.h>
#include <chrono>
#include <cstddef> // size_t
#include <cstdint> // uint64_t
#include <cstring> // memset
#include <fairlogger/Logger.h>
#include <string>
namespace fair::mq
{
/**
* Sampler to generate traffic for benchmarking.
*/
class FairMQBenchmarkSampler : public FairMQDevice
class BenchmarkSampler : public Device
{
public:
FairMQBenchmarkSampler()
BenchmarkSampler()
: fMultipart(false)
, fMemSet(false)
, fNumParts(1)
@@ -117,4 +120,6 @@ class FairMQBenchmarkSampler : public FairMQDevice
std::string fOutChannelName;
};
#endif /* FAIRMQBENCHMARKSAMPLER_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_BENCHMARKSAMPLER_H */

View File

@@ -1,36 +1,32 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (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_
#ifndef FAIR_MQ_MERGER_H
#define FAIR_MQ_MERGER_H
#include "FairMQDevice.h"
#include "FairMQPoller.h"
#include "FairMQLogger.h"
#include <FairMQPoller.h>
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <string>
#include <vector>
class FairMQMerger : public FairMQDevice
namespace fair::mq
{
class Merger : public Device
{
public:
FairMQMerger()
Merger()
: fMultipart(true)
, fInChannelName("data-in")
, fOutChannelName("data-out")
{}
~FairMQMerger() {}
protected:
bool fMultipart;
@@ -112,4 +108,6 @@ class FairMQMerger : public FairMQDevice
}
};
#endif /* FAIRMQMERGER_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_MERGER_H */

View File

@@ -1,29 +1,31 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIRMQMULTIPLIER_H_
#define FAIRMQMULTIPLIER_H_
#ifndef FAIR_MQ_MULTIPLIER_H
#define FAIR_MQ_MULTIPLIER_H
#include "FairMQDevice.h"
#include <fairmq/Device.h>
#include <string>
#include <vector>
class FairMQMultiplier : public FairMQDevice
namespace fair::mq
{
class Multiplier : public Device
{
public:
FairMQMultiplier()
Multiplier()
: fMultipart(true)
, fNumOutputs(0)
, fInChannelName()
, fOutChannelNames()
{}
~FairMQMultiplier() {}
protected:
bool fMultipart;
@@ -39,9 +41,9 @@ class FairMQMultiplier : public FairMQDevice
fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size();
if (fMultipart) {
OnData(fInChannelName, &FairMQMultiplier::HandleMultipartData);
OnData(fInChannelName, &Multiplier::HandleMultipartData);
} else {
OnData(fInChannelName, &FairMQMultiplier::HandleSingleData);
OnData(fInChannelName, &Multiplier::HandleSingleData);
}
}
@@ -107,4 +109,6 @@ class FairMQMultiplier : public FairMQDevice
}
};
#endif /* FAIRMQMULTIPLIER_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_MULTIPLIER_H */

View File

@@ -1,33 +1,29 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQProxy.h
*
* @since 2013-10-02
* @author A. Rybalchenko
*/
#ifndef FAIRMQPROXY_H_
#define FAIRMQPROXY_H_
#ifndef FAIR_MQ_PROXY_H
#define FAIR_MQ_PROXY_H
#include "FairMQDevice.h"
#include <fairmq/Device.h>
#include <string>
class FairMQProxy : public FairMQDevice
namespace fair::mq
{
class Proxy : public Device
{
public:
FairMQProxy()
Proxy()
: fMultipart(true)
, fInChannelName()
, fOutChannelName()
{}
~FairMQProxy() {}
protected:
bool fMultipart;
@@ -73,4 +69,6 @@ class FairMQProxy : public FairMQDevice
}
};
#endif /* FAIRMQPROXY_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_PROXY_H */

View File

@@ -2,9 +2,9 @@
With FairMQ several generic devices are provided:
- **FairMQBenchmarkSampler**: generates random data of configurable size and at configurable rate and sends it out on an output channel.
- **FairMQSink**: receives messages on the input channel and simply discards them.
- **FairMQMerger**: receives data from multiple input channels and forwards it to a single output channel.
- **FairMQSplitter**: receives messages on a single input channels and round-robins them among multiple output channels (which can have different socket types).
- **FairMQMultiplier**: receives data from a single input channel and multiplies (copies) it to two or more output channels.
- **FairMQProxy**: connects input channel to output channel, where both can have different socket types and multiple peers.
- **BenchmarkSampler**: generates random data of configurable size and at configurable rate and sends it out on an output channel.
- **Sink**: receives messages on the input channel and simply discards them.
- **Merger**: receives data from multiple input channels and forwards it to a single output channel.
- **Splitter**: receives messages on a single input channels and round-robins them among multiple output channels (which can have different socket types).
- **Multiplier**: receives data from a single input channel and multiplies (copies) it to two or more output channels.
- **Proxy**: connects input channel to output channel, where both can have different socket types and multiple peers.

View File

@@ -1,33 +1,31 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (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_
#ifndef FAIR_MQ_SINK_H
#define FAIR_MQ_SINK_H
#include "FairMQDevice.h"
#include "FairMQLogger.h"
#include <FairMQPoller.h>
#include <fairmq/Device.h>
#include <fairmq/tools/Strings.h>
#include <chrono>
#include <string>
#include <fairlogger/Logger.h>
#include <fstream>
#include <string>
#include <stdexcept>
class FairMQSink : public FairMQDevice
namespace fair::mq
{
class Sink : public Device
{
public:
FairMQSink()
Sink()
: fMultipart(false)
, fMaxIterations(0)
, fNumIterations(0)
@@ -37,8 +35,6 @@ class FairMQSink : public FairMQDevice
, fOutFilename()
{}
~FairMQSink() {}
protected:
bool fMultipart;
uint64_t fMaxIterations;
@@ -145,4 +141,6 @@ class FairMQSink : public FairMQDevice
}
};
#endif /* FAIRMQSINK_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_SINK_H */

View File

@@ -1,35 +1,31 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (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_
#ifndef FAIR_MQ_SPLITTER_H
#define FAIR_MQ_SPLITTER_H
#include "FairMQDevice.h"
#include <fairmq/Device.h>
#include <string>
class FairMQSplitter : public FairMQDevice
namespace fair::mq
{
class Splitter : public Device
{
public:
FairMQSplitter()
Splitter()
: fMultipart(true)
, fNumOutputs(0)
, fDirection(0)
, fInChannelName()
, fOutChannelName()
{}
~FairMQSplitter() {}
protected:
bool fMultipart;
@@ -47,9 +43,9 @@ class FairMQSplitter : public FairMQDevice
fDirection = 0;
if (fMultipart) {
OnData(fInChannelName, &FairMQSplitter::HandleData<FairMQParts>);
OnData(fInChannelName, &Splitter::HandleData<FairMQParts>);
} else {
OnData(fInChannelName, &FairMQSplitter::HandleData<FairMQMessagePtr>);
OnData(fInChannelName, &Splitter::HandleData<FairMQMessagePtr>);
}
}
@@ -66,4 +62,6 @@ class FairMQSplitter : public FairMQDevice
}
};
#endif /* FAIRMQSPLITTER_H_ */
} // namespace fair::mq
#endif /* FAIR_MQ_SPLITTER_H */

View File

@@ -0,0 +1,30 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/BenchmarkSampler.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& options)
{
options.add_options()
("out-channel", bpo::value<std::string>()->default_value("data"), "Name of the output channel")
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads")
("memset", bpo::value<bool>()->default_value(false), "Memset allocated buffers to 0")
("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")
("msg-alignment", bpo::value<size_t>()->default_value(0), "Message alignment")
("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");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /* config */)
{
return std::make_unique<fair::mq::BenchmarkSampler>();
}

View File

@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/Merger.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
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<bool>()->default_value(true), "Handle multipart payloads");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /*config*/)
{
return std::make_unique<fair::mq::Merger>();
}

View File

@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/Multiplier.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
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<bool>()->default_value(true), "Handle multipart payloads");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /*config*/)
{
return std::make_unique<fair::mq::Multiplier>();
}

View File

@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/Proxy.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
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<bool>()->default_value(true), "Handle multipart payloads");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /*config*/)
{
return std::make_unique<fair::mq::Proxy>();
}

View File

@@ -0,0 +1,27 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/Sink.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& options)
{
options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data"), "Name of the input channel")
("out-filename", bpo::value<std::string>()->default_value(""), "Write incoming message buffers to the specified file")
("max-file-size", bpo::value<uint64_t>()->default_value(2000000000), "Maximum file size for the file output (0 - unlimited)")
("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");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /*config*/)
{
return std::make_unique<fair::mq::Sink>();
}

View File

@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/devices/Splitter.h>
#include <fairmq/runDevice.h>
namespace bpo = boost::program_options;
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<bool>()->default_value(true), "Handle multipart payloads");
}
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& /*config*/)
{
return std::make_unique<fair::mq::Splitter>();
}

View File

@@ -0,0 +1,95 @@
#!/bin/bash
export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
maxIterations="0"
msgSize="1000000"
transport="zeromq"
affinity="false"
multipart="false"
numParts="1"
affinitySamp=""
affinitySink=""
if [[ $1 =~ ^[0-9]+$ ]]; then
msgSize=$1
fi
if [[ $2 =~ ^[0-9]+$ ]]; then
maxIterations=$2
fi
if [[ $3 =~ ^[a-z]+$ ]]; then
transport=$3
fi
if [[ $4 =~ ^[a-z]+$ ]]; then
affinity=$4
fi
if [[ $5 =~ ^[a-z]+$ ]]; then
multipart=$5
fi
if [[ $6 =~ ^[0-9]+$ ]]; then
numParts=$6
fi
echo "Starting benchmark with following settings:"
echo ""
echo "message size: $msgSize bytes"
if [ $maxIterations = 0 ]; then
echo "number of iterations: unlimited"
else
echo "number of iterations: $maxIterations"
fi
echo "transport: $transport"
if [ $affinity = "true" ]; then
affinitySamp="taskset -c 0"
affinitySink="taskset -c 1"
echo "affinity: assigning sampler to core 0, sink to core 1"
else
echo ""
fi
echo ""
echo "Usage: startBenchmark [message size=1000000] [number of iterations=0] [transport=zeromq/shmem] [affinity=false]"
SAMPLER="fairmq-bsampler"
SAMPLER+=" --id bsampler1"
#SAMPLER+=" --io-threads 2"
#SAMPLER+=" --control static"
SAMPLER+=" --transport $transport"
SAMPLER+=" --severity debug"
SAMPLER+=" --msg-size $msgSize"
SAMPLER+=" --multipart $multipart"
SAMPLER+=" --num-parts $numParts"
SAMPLER+=" --shm-throw-bad-alloc false"
# SAMPLER+=" --msg-rate 1000"
SAMPLER+=" --max-iterations $maxIterations"
SAMPLER+=" --channel-config name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555"
xterm -geometry 90x50+0+0 -hold -e $affinitySamp @CMAKE_CURRENT_BINARY_DIR@/$SAMPLER &
echo ""
echo "started: xterm -geometry 90x50+0+0 -hold -e $affinitySamp @CMAKE_CURRENT_BINARY_DIR@/$SAMPLER"
echo "pid: $!"
SINK="fairmq-sink"
SINK+=" --id sink1"
#SINK+=" --io-threads 2"
#SINK+=" --control static"
SINK+=" --transport $transport"
SINK+=" --severity debug"
SINK+=" --multipart $multipart"
SINK+=" --max-iterations $maxIterations"
SINK+=" --channel-config name=data,type=pair,method=connect,address=tcp://127.0.0.1:5555"
xterm -geometry 90x50+550+0 -hold -e $affinitySink @CMAKE_CURRENT_BINARY_DIR@/$SINK &
echo ""
echo "started: xterm -geometry 90x50+550+0 -hold -e $affinitySink @CMAKE_CURRENT_BINARY_DIR@/$SINK"
echo "pid: $!"
echo ""