Skip to content

Commit

Permalink
Sleep after over-long iteartion
Browse files Browse the repository at this point in the history
Too short iteration interval is problematic for rate calculation on slow moving
counters: small time delta pushes calculated rate way above the average rate
for the couner.

This PR revises logic introduced in #323 and limits minimum interval between
iterations to a half of the configured check period to minimize negative effect
on the rate calculations.
  • Loading branch information
vickenty committed May 18, 2021
1 parent 7470c85 commit 37a6fd5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,15 @@ void start() {
try {
long loopPeriod = appConfig.getCheckPeriod();
long sleepPeriod = loopPeriod - duration;
if (sleepPeriod <= 0) {
if (sleepPeriod < loopPeriod / 2) {
log.debug(
"The collection cycle took longer that the configured check period,"
+ " the next cycle will start immediatly");
+ " the next cycle will be delayed");
sleepPeriod = loopPeriod / 2;
} else {
log.debug("Sleeping for " + sleepPeriod + " ms.");
Thread.sleep(sleepPeriod);
}
Thread.sleep(sleepPeriod);
} catch (InterruptedException e) {
log.warn(e.getMessage(), e);
}
Expand Down

0 comments on commit 37a6fd5

Please sign in to comment.