当前位置: 首页>>代码示例>>Java>>正文


Java Reservoir类代码示例

本文整理汇总了Java中com.codahale.metrics.Reservoir的典型用法代码示例。如果您正苦于以下问题:Java Reservoir类的具体用法?Java Reservoir怎么用?Java Reservoir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Reservoir类属于com.codahale.metrics包,在下文中一共展示了Reservoir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RollingWindowTimerBuilder

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@DataProvider(value = {
    "42     |   DAYS",
    "123    |   SECONDS",
    "999    |   MILLISECONDS",
    "3      |   HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(
    long amount, TimeUnit timeUnit
) {
    // given
    RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);

    // when
    Timer timer = rwtb.newMetric();

    // then
    Histogram histogram = (Histogram) getInternalState(timer, "histogram");
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:24,代码来源:SignalFxEndpointMetricsHandlerTest.java

示例2: RollingWindowHistogramBuilder

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@DataProvider(value = {
    "42     |   DAYS",
    "123    |   SECONDS",
    "999    |   MILLISECONDS",
    "3      |   HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(
    long amount, TimeUnit timeUnit
) {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);

    // when
    Histogram histogram = rwhb.newMetric();

    // then
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:23,代码来源:SignalFxEndpointMetricsHandlerTest.java

示例3: shouldCacheSnapshot

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void shouldCacheSnapshot() {
    Reservoir reservoir = new HdrBuilder().neverResetReservoir().buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    reservoir.update(30);
    reservoir.update(40);
    Snapshot secondSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, secondSnapshot);
    assertEquals(10, secondSnapshot.getMin());
    assertEquals(40, secondSnapshot.getMax());

    reservoir.update(9);
    reservoir.update(60);
    Snapshot thirdSnapshot = reservoir.getSnapshot();
    assertNotSame(secondSnapshot, thirdSnapshot);
    assertEquals(9, thirdSnapshot.getMin());
    assertEquals(60, thirdSnapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:23,代码来源:UniformAccumulatorTest.java

示例4: shouldCacheSnapshot

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void shouldCacheSnapshot() {
    Reservoir reservoir = new HdrBuilder().resetReservoirOnSnapshot().buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    reservoir.update(30);
    reservoir.update(40);
    Snapshot secondSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, secondSnapshot);
    assertEquals(30, secondSnapshot.getMin());
    assertEquals(40, secondSnapshot.getMax());

    reservoir.update(50);
    reservoir.update(60);
    Snapshot thirdSnapshot = reservoir.getSnapshot();
    assertNotSame(secondSnapshot, thirdSnapshot);
    assertEquals(50, thirdSnapshot.getMin());
    assertEquals(60, thirdSnapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:23,代码来源:ResetOnSnapshotAccumulatorTest.java

示例5: testSkipBigValues

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void testSkipBigValues() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.SKIP).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:17,代码来源:OverflowResolverTest.java

示例6: testReduceBigValuesToMax

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void testReduceBigValuesToMax() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.REDUCE_TO_HIGHEST_TRACKABLE).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:17,代码来源:OverflowResolverTest.java

示例7: Summary

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
private Summary(final String name,
                final String help,
                final String[] labelNames,
                final Supplier<Reservoir> reservoirSupplier,
                final Clock clock) {
  super(name, help, labelNames);
  this.reservoirSupplier = reservoirSupplier;
  this.clock = clock;
}
 
开发者ID:outbrain,项目名称:prometheus-client,代码行数:10,代码来源:Summary.java

示例8: getReservoir

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
/**
 * Get reservoir implementation based on the reservoir type
 *
 * @return The {@link Reservoir} implementation
 */
private Reservoir getReservoir() {
    // The Reservoir implementation is selected using a switch statement.
    // The ReservoirType enum is a part of YAML configuration
    // and foreign imports are not supported by Carbon Configuration Maven Plugin.
    // Therefore, the Reservoir class cannot be imported and the Reservoir
    // creation logic cannot be written inside ReservoirType enum.
    switch (reservoirType) {
        case EXPONENTIALLY_DECAYING:
            return new ExponentiallyDecayingReservoir();
        case UNIFORM:
            return new UniformReservoir(reservoirParametersConfig.getSize());
        case SLIDING_WINDOW:
            return new SlidingWindowReservoir(reservoirParametersConfig.getSize());
        case SLIDING_TIME_WINDOW:
            return new SlidingTimeWindowReservoir(reservoirParametersConfig.getWindow(),
                    reservoirParametersConfig.getWindowUnit());
        case HDR_HISTOGRAM:
            Recorder recorder = new Recorder(reservoirParametersConfig.getNumberOfSignificantValueDigits());
            if (reservoirParametersConfig.isResetOnSnapshot()) {
                return new HdrHistogramResetOnSnapshotReservoir(recorder);
            } else {
                return new HdrHistogramReservoir(recorder);
            }
        default:
            throw new RuntimeException("Invalid Reservoir Type");

    }
}
 
开发者ID:wso2,项目名称:carbon-metrics,代码行数:34,代码来源:MetricManager.java

示例9: MinMaxSlidingTimeReservoir

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
/**
 * Build a new reservoir.
 *
 * @param clock Clock to use as a time source
 * @param size Number of buckets to maintain
 * @param step Step between each bucket
 * @param stepUnit Time unit used in 'step'
 * @param delegate Delegate reservoir that min/max is being corrected for.
 */
public MinMaxSlidingTimeReservoir(
    final Clock clock, final int size, final long step, final TimeUnit stepUnit,
    final Reservoir delegate
) {
    this.clock = clock;
    this.size = size;
    this.step = stepUnit.toNanos(step);
    this.delegate = delegate;
}
 
开发者ID:spotify,项目名称:heroic,代码行数:19,代码来源:MinMaxSlidingTimeReservoir.java

示例10: setup

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Before
public void setup() {
    delegate = mock(Reservoir.class);
    reservoir =
        spy(new MinMaxSlidingTimeReservoir(clock, SIZE, STEP, TimeUnit.NANOSECONDS, delegate));
    doReturn(DELEGATE_SNAPSHOT).when(delegate).getSnapshot();
}
 
开发者ID:spotify,项目名称:heroic,代码行数:8,代码来源:MinMaxSlidingTimeReservoirTest.java

示例11: testThatConcurrentThreadsNotHung

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test(timeout = 32000)
public void testThatConcurrentThreadsNotHung() throws InterruptedException {
    Reservoir reservoir = new HdrBuilder()
            .resetReservoirPeriodically(Duration.ofSeconds(1))
            .buildReservoir();

    HistogramUtil.runInParallel(reservoir, TimeUnit.SECONDS.toMillis(30));
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:9,代码来源:ResetPeriodicallyAccumulatorTest.java

示例12: testThatConcurrentThreadsNotHungWithThreeChunks

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test(timeout = 32000)
public void testThatConcurrentThreadsNotHungWithThreeChunks() throws InterruptedException {
    Reservoir reservoir = new HdrBuilder()
            .resetReservoirPeriodicallyByChunks(Duration.ofSeconds(3), 3)
            .buildReservoir();

    HistogramUtil.runInParallel(reservoir, TimeUnit.SECONDS.toMillis(30));
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:9,代码来源:ResetByChunksAccumulatorTest.java

示例13: runInParallel

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
public static void runInParallel(Reservoir reservoir, long durationMillis) throws InterruptedException {
    AtomicReference<Throwable> errorRef = new AtomicReference<>();

    Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
    long start = System.currentTimeMillis();
    final CountDownLatch latch = new CountDownLatch(threads.length);
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(() -> {
            try {
                // update reservoir 100 times and take snapshot on each cycle
                while (errorRef.get() == null && System.currentTimeMillis() - start < durationMillis) {
                    for (int j = 1; j <= 10; j++) {
                        reservoir.update(ThreadLocalRandom.current().nextInt(j));
                    }
                    reservoir.getSnapshot();
                }
            } catch (Exception e){
                e.printStackTrace();
                errorRef.set(e);
            } finally {
                latch.countDown();
            }
        });
        threads[i].start();
    }
    latch.await();
    //latch.await(duration.toMillis() + 4000, TimeUnit.MILLISECONDS);
    if (latch.getCount() > 0) {
        throw new IllegalStateException("" + latch.getCount() + " was not completed");
    }
    if (errorRef.get() != null) {
        throw new RuntimeException(errorRef.get());
    }
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:35,代码来源:HistogramUtil.java

示例14: testSmartSnapshotCalculation

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void testSmartSnapshotCalculation() {
    double[] predefinedPercentiles = {0.5, 0.6, 0.75, 0.9, 0.95, 0.98, 0.99, 0.999};
    Reservoir reservoir = new HdrBuilder().withPredefinedPercentiles(predefinedPercentiles).buildReservoir();
    Snapshot snapshot = snapshotTaker.apply(reservoir);

    Histogram hdrHistogram = createEquivalentHistogram();
    assertEquals(hdrHistogram.getStdDeviation(), snapshot.getStdDev());
    assertEquals(hdrHistogram.getMinValue(), snapshot.getMin());
    assertEquals(hdrHistogram.getMean(), snapshot.getMean());
    assertEquals(hdrHistogram.getValueAtPercentile(50.0), (long) snapshot.getValue(0.42)); // do not defined percentile should be rounded up to first defined
    assertEquals(hdrHistogram.getValueAtPercentile(50.0), (long) snapshot.getMedian());
    assertEquals(hdrHistogram.getMaxValue(), snapshot.getMax());
    assertEquals(hdrHistogram.getValueAtPercentile(60.0), (long) snapshot.getValue(0.6));
    assertEquals(hdrHistogram.getValueAtPercentile(75.0), (long) snapshot.get75thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(90.0), (long) snapshot.getValue(0.8)); // do not defined percentile should be rounded up to first defined
    assertEquals(hdrHistogram.getValueAtPercentile(90.0), (long) snapshot.getValue(0.9));
    assertEquals(hdrHistogram.getValueAtPercentile(95.0), (long) snapshot.getValue(0.94)); // do not defined percentile should be rounded up to first defined
    assertEquals(hdrHistogram.getValueAtPercentile(95.0), (long) snapshot.get95thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(98.0), (long) snapshot.get98thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.0), (long) snapshot.get99thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.9), (long) snapshot.get999thPercentile());
    assertEquals(hdrHistogram.getMaxValue(), (long) snapshot.getValue(0.9999));

    assertEquals(predefinedPercentiles.length, snapshot.size());

    assertTrue(Arrays.equals(
            snapshot.getValues(),
            new long[] {
                    hdrHistogram.getValueAtPercentile(50.0),
                    hdrHistogram.getValueAtPercentile(60.0),
                    hdrHistogram.getValueAtPercentile(75.0),
                    hdrHistogram.getValueAtPercentile(90.0),
                    hdrHistogram.getValueAtPercentile(95.0),
                    hdrHistogram.getValueAtPercentile(98.0),
                    hdrHistogram.getValueAtPercentile(99.0),
                    hdrHistogram.getValueAtPercentile(99.9),
            }
    ));
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:41,代码来源:PercentileCalculationTest.java

示例15: testFullSnapshotCalculation

import com.codahale.metrics.Reservoir; //导入依赖的package包/类
@Test
public void testFullSnapshotCalculation() {
    Reservoir reservoir = new HdrBuilder().withoutSnapshotOptimization().buildReservoir();
    Snapshot snapshot = snapshotTaker.apply(reservoir);

    Histogram hdrHistogram = createEquivalentHistogram();
    assertEquals(hdrHistogram.getStdDeviation(), snapshot.getStdDev());
    assertEquals(hdrHistogram.getMinValue(), snapshot.getMin());
    assertEquals(hdrHistogram.getMean(), snapshot.getMean());
    assertEquals(hdrHistogram.getValueAtPercentile(50.0), (long) snapshot.getMedian());
    assertEquals(hdrHistogram.getMaxValue(), snapshot.getMax());
    assertEquals(hdrHistogram.getValueAtPercentile(60.0), (long) snapshot.getValue(0.6));
    assertEquals(hdrHistogram.getValueAtPercentile(75.0), (long) snapshot.get75thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(80.0), (long) snapshot.getValue(0.8));
    assertEquals(hdrHistogram.getValueAtPercentile(90.0), (long) snapshot.getValue(0.9));
    assertEquals(hdrHistogram.getValueAtPercentile(94.0), (long) snapshot.getValue(0.94));
    assertEquals(hdrHistogram.getValueAtPercentile(95.0), (long) snapshot.get95thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(98.0), (long) snapshot.get98thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.0), (long) snapshot.get99thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.9), (long) snapshot.get999thPercentile());

    assertEquals(hdrHistogram.getTotalCount(), snapshot.size());

    int i = 0;
    long[] values = snapshot.getValues();
    for (HistogramIterationValue value : hdrHistogram.recordedValues()) {
        assertEquals(value.getValueIteratedTo(), values[i++]);
    }
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:30,代码来源:PercentileCalculationTest.java


注:本文中的com.codahale.metrics.Reservoir类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。