Skip to content

Commit

Permalink
Set pause detector before initializing TimeWindowLatencyHistogram buf…
Browse files Browse the repository at this point in the history
…fer (fixes micrometer-metrics#350)
  • Loading branch information
jkschneider committed Jan 17, 2018
1 parent 661e540 commit 92d9ddf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class TimeWindowHistogram extends TimeWindowHistogramBase<DoubleRecorder,
public TimeWindowHistogram(Clock clock, HistogramConfig histogramConfig) {
super(clock, histogramConfig, DoubleRecorder.class);
intervalHistogram = new DoubleHistogram(NUM_SIGNIFICANT_VALUE_DIGITS);
initRingBuffer();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class TimeWindowHistogramBase<T, U> {
private final HistogramConfig histogramConfig;

private final T[] ringBuffer;
private final U accumulatedHistogram;
private U accumulatedHistogram;
private volatile boolean accumulatedHistogramStale;

private final long durationBetweenRotatesMillis;
Expand All @@ -64,8 +64,8 @@ abstract class TimeWindowHistogramBase<T, U> {
rejectHistogramConfig("histogramBufferLength (" + ageBuckets + ") must be greater than 0.");
}

ringBuffer = newRingBuffer(bucketType, ageBuckets, histogramConfig);
accumulatedHistogram = newAccumulatedHistogram(ringBuffer);
//noinspection unchecked
ringBuffer = (T[]) Array.newInstance(bucketType, ageBuckets);

durationBetweenRotatesMillis = histogramConfig.getHistogramExpiry().toMillis() / ageBuckets;
if (durationBetweenRotatesMillis <= 0) {
Expand All @@ -75,7 +75,6 @@ abstract class TimeWindowHistogramBase<T, U> {

currentBucket = 0;
lastRotateTimestampMillis = clock.wallTime();

}

private static HistogramConfig validateHistogramConfig(HistogramConfig histogramConfig) {
Expand Down Expand Up @@ -107,13 +106,11 @@ private static HistogramConfig validateHistogramConfig(HistogramConfig histogram
return histogramConfig;
}

private T[] newRingBuffer(Class<T> bucketType, int ageBuckets, HistogramConfig histogramConfig) {
@SuppressWarnings("unchecked")
final T[] ringBuffer = (T[]) Array.newInstance(bucketType, ageBuckets);
for (int i = 0; i < ageBuckets; i++) {
void initRingBuffer() {
for (int i = 0; i < ringBuffer.length; i++) {
ringBuffer[i] = newBucket(histogramConfig);
}
return ringBuffer;
accumulatedHistogram = newAccumulatedHistogram(ringBuffer);
}

private static void rejectHistogramConfig(String msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static java.util.Objects.requireNonNull;

/**
* @author Jon Schneider
* @author Trustin Heuiseung Lee
Expand All @@ -54,7 +56,7 @@ public TimeWindowLatencyHistogram(Clock clock, HistogramConfig histogramConfig,
io.micrometer.core.instrument.histogram.pause.PauseDetector pauseDetector) {
super(clock, histogramConfig, LatencyStats.class);

this.pauseDetector = pauseDetectorCache.computeIfAbsent(pauseDetector, detector -> {
this.pauseDetector = requireNonNull(pauseDetectorCache.computeIfAbsent(pauseDetector, detector -> {
if (detector instanceof ClockDriftPauseDetector) {
ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;
return new SimplePauseDetector(clockDriftPauseDetector.getSleepInterval().toNanos(),
Expand All @@ -63,11 +65,15 @@ public TimeWindowLatencyHistogram(Clock clock, HistogramConfig histogramConfig,
return new NoopPauseDetector();
}
return new NoopPauseDetector();
});
}));

initRingBuffer();
}

@Override
LatencyStats newBucket(HistogramConfig histogramConfig) {
requireNonNull(pauseDetector);

return new LatencyStats.Builder()
.pauseDetector(pauseDetector)
.lowestTrackableLatency(histogramConfig.getMinimumExpectedValue())
Expand Down
2 changes: 2 additions & 0 deletions scripts/cpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
htop -p $(ps ax | grep '[m]icrometer-core' | awk '{print $1}')

0 comments on commit 92d9ddf

Please sign in to comment.