Skip to content

Commit

Permalink
Use new RateLimiter for ConditionalRun
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx authored and dennisklein committed Aug 27, 2018
1 parent 6545dae commit 2498837
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
2 changes: 0 additions & 2 deletions examples/1-1/Sampler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ bool Sampler::ConditionalRun()
return false;
}

this_thread::sleep_for(chrono::seconds(1));

return true;
}

Expand Down
1 change: 1 addition & 0 deletions examples/1-1/fairmq-start-ex-1-1.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down
1 change: 1 addition & 0 deletions examples/1-1/test-ex-1-1.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 5 additions & 12 deletions fairmq/FairMQDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Ver
, fMultitransportProceed(false)
, fVersion(version)
, fRate(0.)
, fLastTime(0)
, fRawCmdLineArgs()
{
}
Expand Down Expand Up @@ -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<TimeScale::rep>(chrono::duration_cast<TimeScale>(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<TimeScale>(Clock::now() - reftime).count();
}
}

Run();
Expand Down
1 change: 0 additions & 1 deletion fairmq/FairMQDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> fRawCmdLineArgs;
};

Expand Down

0 comments on commit 2498837

Please sign in to comment.