Skip to content

Commit

Permalink
Poll gauge values less frequently (#447)
Browse files Browse the repository at this point in the history
Servo gauges were sampled by default once a minute, and the default
spectator polling frequency is 5s. That could cause a noticeable
increase in CPU usage attributed to monitoring. This change makes
spectator sample the values every 59s.
  • Loading branch information
dmuino committed May 17, 2018
1 parent a4bb89c commit c616eb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -76,7 +76,7 @@ subprojects {
dependencies {
compile 'org.slf4j:slf4j-api'
compile 'com.google.guava:guava'
compile 'com.netflix.spectator:spectator-api:0.66.0'
compile 'com.netflix.spectator:spectator-api:0.67.0'
testCompile 'org.testng:testng:6.1.1'
testRuntime 'org.slf4j:slf4j-log4j12'
testRuntime 'log4j:log4j:1.2.17'
Expand Down
Expand Up @@ -18,6 +18,7 @@
import com.netflix.servo.monitor.CompositeMonitor;
import com.netflix.servo.monitor.Monitor;
import com.netflix.servo.monitor.MonitorConfig;
import com.netflix.servo.monitor.Pollers;
import com.netflix.servo.monitor.SpectatorMonitor;
import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.DistributionSummary;
Expand All @@ -32,6 +33,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -113,9 +115,11 @@ public static ScheduledExecutorService gaugePool() {

/** Create builder for a polled gauge based on the config. */
public static PolledMeter.Builder polledGauge(MonitorConfig config) {
long delayMillis = Math.max(Pollers.getPollingIntervals().get(0) - 1000, 5000);
return PolledMeter.using(registry)
.withId(createId(config))
.scheduleOn(GAUGE_POOL);
.withDelay(Duration.ofMillis(delayMillis))
.scheduleOn(gaugePool());
}

/** Register a custom monitor. */
Expand Down

0 comments on commit c616eb9

Please sign in to comment.