mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Adding rate control for ConditionalRun function
Devices implementing the conditional run method are typically source devices and a rate control can be desireable. New option '--rate' with a float number argument in Hz can be used to configure rate control. By default it is switched off.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
7429f7a326
commit
9b2b1cf9f1
@@ -14,6 +14,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
|
||||
@@ -61,6 +62,9 @@ FairMQDevice::FairMQDevice()
|
||||
, fMultitransportProceed(false)
|
||||
, fExternalConfig(false)
|
||||
, fVersion({0, 0, 0})
|
||||
, fRate(0.)
|
||||
, fLastTime(0)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
@@ -511,6 +515,18 @@ void FairMQDevice::RunWrapper()
|
||||
{
|
||||
while (CheckCurrentState(RUNNING) && ConditionalRun())
|
||||
{
|
||||
using TimeScale = std::chrono::microseconds;
|
||||
static const auto reftime = std::chrono::system_clock::now();
|
||||
if (fRate > 0.001) {
|
||||
auto timeSinceRef = std::chrono::duration_cast<TimeScale>(std::chrono::system_clock::now() - reftime);
|
||||
auto timespan = timeSinceRef.count() - fLastTime;
|
||||
TimeScale::rep period = (float)TimeScale::period::den / fRate;
|
||||
if (timespan < period) {
|
||||
TimeScale sleepfor(period - timespan);
|
||||
std::this_thread::sleep_for(sleepfor);
|
||||
}
|
||||
fLastTime = std::chrono::duration_cast<TimeScale>(std::chrono::system_clock::now() - reftime).count();
|
||||
}
|
||||
}
|
||||
|
||||
Run();
|
||||
@@ -893,6 +909,7 @@ void FairMQDevice::SetConfig(FairMQProgOptions& config)
|
||||
fNetworkInterface = config.GetValue<string>("network-interface");
|
||||
fNumIoThreads = config.GetValue<int>("io-threads");
|
||||
fInitializationTimeoutInS = config.GetValue<int>("initialization-timeout");
|
||||
std::stringstream(fConfig->GetValue<string>("rate")) >> fRate;
|
||||
}
|
||||
|
||||
void FairMQDevice::LogSocketRates()
|
||||
|
Reference in New Issue
Block a user