public void recordFailure(Exception exception) { recentFailures.add(1); lastResponseTime.set(new DateTime()); lastFailureException.set(exception); Throwable cause = exception; while (cause.getClass() == RuntimeException.class && cause.getCause() != null) { cause = cause.getCause(); } synchronized (this) { DecayCounter counter = failureCountByType.get(cause.getClass()); if (counter == null) { counter = new DecayCounter(ExponentialDecay.oneMinute()); failureCountByType.put(cause.getClass(), counter); } counter.add(1); } }
public TimeStat(Ticker ticker, TimeUnit unit) { this.ticker = ticker; oneMinute = new TimeDistribution(ExponentialDecay.oneMinute(), unit); fiveMinutes = new TimeDistribution(ExponentialDecay.fiveMinutes(), unit); fifteenMinutes = new TimeDistribution(ExponentialDecay.fifteenMinutes(), unit); allTime = new TimeDistribution(unit); }
@Test public void testDecayedCounts() throws Exception { TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, 60), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); // should have no compressions with so few values and the allowed error assertEquals(digest.getConfidenceFactor(), 0.0); ticker.increment(60, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); assertEquals(digest.getCount(), 15.0); }
public TimeStat(Ticker ticker, TimeUnit unit) { this.ticker = ticker; oneMinute = new TimeDistribution(ExponentialDecay.oneMinute(), unit); fiveMinutes = new TimeDistribution(ExponentialDecay.fiveMinutes(), unit); fifteenMinutes = new TimeDistribution(ExponentialDecay.fifteenMinutes(), unit); allTime = new TimeDistribution(unit); }
@Test public void testDecayedCountsWithClockIncrementSmallerThanRescaleThreshold() throws Exception { int targetAgeInSeconds = (int) (QuantileDigest.RESCALE_THRESHOLD_SECONDS - 1); TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, targetAgeInSeconds), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); ticker.increment(targetAgeInSeconds, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); assertEquals(digest.getCount(), 15.0); }
public void recordFailure(Exception exception) { recentFailures.add(1); lastResponseTime.set(new DateTime()); lastFailureException.set(exception); Throwable cause = exception; while (cause.getClass() == RuntimeException.class && cause.getCause() != null) { cause = cause.getCause(); } synchronized (this) { DecayCounter counter = failureCountByType.get(cause.getClass()); if (counter == null) { counter = new DecayCounter(ExponentialDecay.oneMinute()); failureCountByType.put(cause.getClass(), counter); } counter.add(1); } }
public DistributionStat() { oneMinute = new Distribution(ExponentialDecay.oneMinute()); fiveMinutes = new Distribution(ExponentialDecay.fiveMinutes()); fifteenMinutes = new Distribution(ExponentialDecay.fifteenMinutes()); allTime = new Distribution(); }
@Test public void testDecayedCounts() throws Exception { TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, 60), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); // should have no compressions with so few values and the allowed error assertEquals(digest.getConfidenceFactor(), 0.0); ticker.increment(60, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); assertEquals(digest.getCount(), 15.0); }
public void recordFailure(Exception exception) { recentFailures.add(1); lastResponseTime.set(new DateTime()); Throwable cause = exception; while (cause.getClass() == RuntimeException.class && cause.getCause() != null) { cause = cause.getCause(); } synchronized (this) { DecayCounter counter = failureCountByType.get(cause.getClass()); if (counter == null) { counter = new DecayCounter(ExponentialDecay.oneMinute()); failureCountByType.put(cause.getClass(), counter); } counter.add(1); } }
public DistributionStat() { oneMinute = new Distribution(ExponentialDecay.oneMinute()); fiveMinutes = new Distribution(ExponentialDecay.fiveMinutes()); fifteenMinutes = new Distribution(ExponentialDecay.fifteenMinutes()); allTime = new Distribution(); }
@Test public void testDecayedCountsWithClockIncrementSmallerThanRescaleThreshold() throws Exception { int targetAgeInSeconds = (int) (QuantileDigest.RESCALE_THRESHOLD_SECONDS - 1); TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, targetAgeInSeconds), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); ticker.increment(targetAgeInSeconds, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); assertEquals(digest.getCount(), 15.0); }
public void recordFailure(Exception exception) { recentFailures.add(1); lastResponseTime.set(new DateTime()); lastFailureException.set(exception); Throwable cause = exception; while (cause.getClass() == RuntimeException.class && cause.getCause() != null) { cause = cause.getCause(); } synchronized (this) { DecayCounter counter = failureCountByType.get(cause.getClass()); if (counter == null) { counter = new DecayCounter(ExponentialDecay.oneMinute()); failureCountByType.put(cause.getClass(), counter); } counter.add(1); } }
@Test public void testDecayedQuantiles() throws Exception { TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, 60), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); // should have no compressions with so few values and the allowed error assertEquals(digest.getConfidenceFactor(), 0.0); ticker.increment(60, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); // Considering that the first 10 values now have a weight of 0.5 per the alpha factor, they only contributed a count // of 5 to rank computations. Therefore, the 50th percentile is equivalent to a weighted rank of (5 + 10) / 2 = 7.5, // which corresponds to value 12 assertEquals(digest.getQuantile(0.5), 12); }
@Test public void testCountDecays() { TestingTicker ticker = new TestingTicker(); DecayCounter counter = new DecayCounter(ExponentialDecay.oneMinute(), ticker); counter.add(1); ticker.increment(1, TimeUnit.MINUTES); assertTrue(Math.abs(counter.getCount() - 1 / Math.E) < 1e-9); }
@Test public void testDecayedQuantiles() throws Exception { TestingTicker ticker = new TestingTicker(); QuantileDigest digest = new QuantileDigest(1, ExponentialDecay.computeAlpha(0.5, 60), ticker); addAll(digest, asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); // should have no compressions with so few values and the allowed error assertEquals(digest.getConfidenceFactor(), 0.0); ticker.increment(60, TimeUnit.SECONDS); addAll(digest, asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); // Considering that the first 10 values now have a weight of 0.5 per the alpha factor, they only contributed a count // of 5 to rank computations. Therefore, the 50th percentile is equivalent to a weighted rank of (5 + 10) / 2 = 7.5, // which corresponds to value 12 assertEquals(digest.getQuantile(0.5), 12); }
@Test public void testCountDecays() { TestingTicker ticker = new TestingTicker(); DecayCounter counter = new DecayCounter(ExponentialDecay.oneMinute(), ticker); counter.add(1); ticker.increment(1, TimeUnit.MINUTES); assertTrue(Math.abs(counter.getCount() - 1 / Math.E) < 1e-9); }
@Test public void testRescaleWithDecayKeepsCompactTree() throws Exception { TestingTicker ticker = new TestingTicker(); int targetAgeInSeconds = (int) (QuantileDigest.RESCALE_THRESHOLD_SECONDS); QuantileDigest digest = new QuantileDigest(0.01, ExponentialDecay.computeAlpha(QuantileDigest.ZERO_WEIGHT_THRESHOLD / 2, targetAgeInSeconds), ticker); for (int i = 0; i < 10; ++i) { digest.add(i); digest.validate(); // bump the clock to make all previous values decay to ~0 ticker.increment(targetAgeInSeconds, TimeUnit.SECONDS); } assertEquals(digest.getNodeCount(), 1); }
@Test public void testAddAfterRescale() { TestingTicker ticker = new TestingTicker(); DecayCounter counter = new DecayCounter(ExponentialDecay.oneMinute(), ticker); counter.add(1); ticker.increment(1, TimeUnit.MINUTES); counter.add(2); double expected = 2 + 1 / Math.E; assertTrue(Math.abs(counter.getCount() - expected) < 1e-9); } }
@Test public void testRescaleWithDecayKeepsCompactTree() throws Exception { TestingTicker ticker = new TestingTicker(); int targetAgeInSeconds = (int) (QuantileDigest.RESCALE_THRESHOLD_SECONDS); QuantileDigest digest = new QuantileDigest(0.01, ExponentialDecay.computeAlpha(QuantileDigest.ZERO_WEIGHT_THRESHOLD / 2, targetAgeInSeconds), ticker); for (int i = 0; i < 10; ++i) { digest.add(i); digest.validate(); // bump the clock to make all previous values decay to ~0 ticker.increment(targetAgeInSeconds, TimeUnit.SECONDS); } assertEquals(digest.getNodeCount(), 1); }
@Test public void testAddAfterRescale() { TestingTicker ticker = new TestingTicker(); DecayCounter counter = new DecayCounter(ExponentialDecay.oneMinute(), ticker); counter.add(1); ticker.increment(1, TimeUnit.MINUTES); counter.add(2); double expected = 2 + 1 / Math.E; assertTrue(Math.abs(counter.getCount() - expected) < 1e-9); } }