diff --git a/examples/1-1/Sampler.cxx b/examples/1-1/Sampler.cxx index 4367f447..03a406db 100644 --- a/examples/1-1/Sampler.cxx +++ b/examples/1-1/Sampler.cxx @@ -64,8 +64,6 @@ bool Sampler::ConditionalRun() return false; } - this_thread::sleep_for(chrono::seconds(1)); - return true; } diff --git a/examples/1-1/fairmq-start-ex-1-1.sh.in b/examples/1-1/fairmq-start-ex-1-1.sh.in index 537e5702..1b637bfd 100755 --- a/examples/1-1/fairmq-start-ex-1-1.sh.in +++ b/examples/1-1/fairmq-start-ex-1-1.sh.in @@ -4,6 +4,7 @@ export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@ SAMPLER="fairmq-ex-1-1-sampler" SAMPLER+=" --id sampler1" +SAMPLER+=" --rate 1" SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0" xterm -geometry 80x23+0+0 -hold -e @EX_BIN_DIR@/$SAMPLER & diff --git a/examples/1-1/test-ex-1-1.sh.in b/examples/1-1/test-ex-1-1.sh.in index 83b08048..f398c659 100755 --- a/examples/1-1/test-ex-1-1.sh.in +++ b/examples/1-1/test-ex-1-1.sh.in @@ -13,6 +13,7 @@ trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SI SAMPLER="fairmq-ex-1-1-sampler" SAMPLER+=" --id sampler1" +SAMPLER+=" --rate 1" SAMPLER+=" --transport $transport" SAMPLER+=" --verbosity veryhigh" SAMPLER+=" --control static --color false" diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index b4ff16d8..2f1436f9 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -71,7 +71,6 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Ver , fMultitransportProceed(false) , fVersion(version) , fRate(0.) - , fLastTime(0) , fRawCmdLineArgs() { } @@ -516,20 +515,14 @@ void FairMQDevice::RunWrapper() } else { - using Clock = chrono::steady_clock; - using TimeScale = chrono::microseconds; - const TimeScale::rep period = TimeScale::period::den / fRate; - const auto reftime = Clock::now(); + fair::mq::tools::RateLimiter rateLimiter(fRate); + while (CheckCurrentState(RUNNING) && ConditionalRun()) { - if (fRate > 0.001) { - auto timespan = static_cast(chrono::duration_cast(Clock::now() - reftime).count() - fLastTime); - if (timespan < period) { - TimeScale sleepfor(period - timespan); - this_thread::sleep_for(sleepfor); + if (fRate > 0.001) + { + rateLimiter.maybe_sleep(); } - fLastTime = chrono::duration_cast(Clock::now() - reftime).count(); - } } Run(); diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index e5ca0b2e..6d1ccc0c 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -550,7 +550,6 @@ class FairMQDevice : public FairMQStateMachine const fair::mq::tools::Version fVersion; float fRate; ///< Rate limiting for ConditionalRun - size_t fLastTime; ///< Rate limiting for ConditionalRun std::vector fRawCmdLineArgs; };