mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Use new RateLimiter in BenchmarkSampler
This commit is contained in:
parent
e95096eb37
commit
6545daeda7
|
@ -1,8 +1,8 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
/**
|
/**
|
||||||
|
@ -14,23 +14,22 @@
|
||||||
|
|
||||||
#include "FairMQBenchmarkSampler.h"
|
#include "FairMQBenchmarkSampler.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <fairmq/Tools.h>
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include "../FairMQLogger.h"
|
#include "../FairMQLogger.h"
|
||||||
#include "../options/FairMQProgOptions.h"
|
#include "../options/FairMQProgOptions.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
|
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
|
||||||
: fSameMessage(true)
|
: fSameMessage(true)
|
||||||
, fMsgSize(10000)
|
, fMsgSize(10000)
|
||||||
, fMsgCounter(0)
|
, fMsgRate(0)
|
||||||
, fMsgRate(1)
|
|
||||||
, fNumIterations(0)
|
, fNumIterations(0)
|
||||||
, fMaxIterations(0)
|
, fMaxIterations(0)
|
||||||
, fOutChannelName()
|
, fOutChannelName()
|
||||||
, fResetMsgCounter()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,16 +41,11 @@ void FairMQBenchmarkSampler::InitTask()
|
||||||
{
|
{
|
||||||
fSameMessage = fConfig->GetValue<bool>("same-msg");
|
fSameMessage = fConfig->GetValue<bool>("same-msg");
|
||||||
fMsgSize = fConfig->GetValue<int>("msg-size");
|
fMsgSize = fConfig->GetValue<int>("msg-size");
|
||||||
fMsgRate = fConfig->GetValue<int>("msg-rate");
|
fMsgRate = fConfig->GetValue<float>("msg-rate");
|
||||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQBenchmarkSampler::PreRun()
|
|
||||||
{
|
|
||||||
fResetMsgCounter = std::thread(&FairMQBenchmarkSampler::ResetMsgCounter, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQBenchmarkSampler::Run()
|
void FairMQBenchmarkSampler::Run()
|
||||||
{
|
{
|
||||||
// store the channel reference to avoid traversing the map on every loop iteration
|
// store the channel reference to avoid traversing the map on every loop iteration
|
||||||
|
@ -62,6 +56,8 @@ void FairMQBenchmarkSampler::Run()
|
||||||
LOG(info) << "Starting the benchmark with message size of " << fMsgSize << " and " << fMaxIterations << " iterations.";
|
LOG(info) << "Starting the benchmark with message size of " << fMsgSize << " and " << fMaxIterations << " iterations.";
|
||||||
auto tStart = chrono::high_resolution_clock::now();
|
auto tStart = chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
fair::mq::tools::RateLimiter rateLimiter(fMsgRate);
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
while (CheckCurrentState(RUNNING))
|
||||||
{
|
{
|
||||||
if (fSameMessage)
|
if (fSameMessage)
|
||||||
|
@ -98,31 +94,14 @@ void FairMQBenchmarkSampler::Run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
--fMsgCounter;
|
|
||||||
|
|
||||||
while (fMsgCounter == 0)
|
if (fMsgRate > 0)
|
||||||
{
|
{
|
||||||
this_thread::sleep_for(chrono::milliseconds(1));
|
rateLimiter.maybe_sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tEnd = chrono::high_resolution_clock::now();
|
auto tEnd = chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
LOG(info) << "Done " << fNumIterations << " iterations in " << chrono::duration<double, milli>(tEnd - tStart).count() << "ms.";
|
LOG(info) << "Done " << fNumIterations << " iterations in " << chrono::duration<double, milli>(tEnd - tStart).count() << "ms.";
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQBenchmarkSampler::PostRun()
|
|
||||||
{
|
|
||||||
fResetMsgCounter.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQBenchmarkSampler::ResetMsgCounter()
|
|
||||||
{
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
fMsgCounter = fMsgRate / 100;
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(10));
|
|
||||||
}
|
|
||||||
fMsgCounter = -1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,20 +31,14 @@ class FairMQBenchmarkSampler : public FairMQDevice
|
||||||
FairMQBenchmarkSampler();
|
FairMQBenchmarkSampler();
|
||||||
virtual ~FairMQBenchmarkSampler();
|
virtual ~FairMQBenchmarkSampler();
|
||||||
|
|
||||||
void PreRun() override;
|
|
||||||
void PostRun() override;
|
|
||||||
|
|
||||||
void ResetMsgCounter();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool fSameMessage;
|
bool fSameMessage;
|
||||||
int fMsgSize;
|
int fMsgSize;
|
||||||
std::atomic<int> fMsgCounter;
|
std::atomic<int> fMsgCounter;
|
||||||
int fMsgRate;
|
float fMsgRate;
|
||||||
uint64_t fNumIterations;
|
uint64_t fNumIterations;
|
||||||
uint64_t fMaxIterations;
|
uint64_t fMaxIterations;
|
||||||
std::string fOutChannelName;
|
std::string fOutChannelName;
|
||||||
std::thread fResetMsgCounter;
|
|
||||||
|
|
||||||
virtual void InitTask() override;
|
virtual void InitTask() override;
|
||||||
virtual void Run() override;
|
virtual void Run() override;
|
||||||
|
|
|
@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||||
("same-msg", bpo::value<bool>()->default_value(false), "Re-send the same message, or recreate for each iteration")
|
("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")
|
("msg-size", bpo::value<int>()->default_value(1000000), "Message size in bytes")
|
||||||
("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)")
|
||||||
("msg-rate", bpo::value<int>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
("msg-rate", bpo::value<float>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user