Search in sources :

Example 1 with UniformReservoir

use of com.codahale.metrics.UniformReservoir in project lucene-solr by apache.

the class MetricSuppliers method getReservoir.

private static final Reservoir getReservoir(SolrResourceLoader loader, PluginInfo info) {
    if (info == null) {
        return new ExponentiallyDecayingReservoir();
    }
    Clock clk = getClock(info, CLOCK);
    String clazz = ExponentiallyDecayingReservoir.class.getName();
    int size = -1;
    double alpha = -1;
    long window = -1;
    if (info.initArgs != null) {
        if (info.initArgs.get(RESERVOIR) != null) {
            String val = String.valueOf(info.initArgs.get(RESERVOIR)).trim();
            if (!val.isEmpty()) {
                clazz = val;
            }
        }
        Number n = (Number) info.initArgs.get(RESERVOIR_SIZE);
        if (n != null) {
            size = n.intValue();
        }
        n = (Number) info.initArgs.get(RESERVOIR_EDR_ALPHA);
        if (n != null) {
            alpha = n.doubleValue();
        }
        n = (Number) info.initArgs.get(RESERVOIR_WINDOW);
        if (n != null) {
            window = n.longValue();
        }
    }
    if (size <= 0) {
        size = DEFAULT_SIZE;
    }
    if (alpha <= 0) {
        alpha = DEFAULT_ALPHA;
    }
    // special case for core implementations
    if (clazz.equals(EDR_CLAZZ)) {
        return new ExponentiallyDecayingReservoir(size, alpha, clk);
    } else if (clazz.equals(UNI_CLAZZ)) {
        return new UniformReservoir(size);
    } else if (clazz.equals(STW_CLAZZ)) {
        if (window <= 0) {
            // 5 minutes, comparable to EDR
            window = DEFAULT_WINDOW;
        }
        return new SlidingTimeWindowReservoir(window, TimeUnit.SECONDS);
    } else if (clazz.equals(SW_CLAZZ)) {
        return new SlidingWindowReservoir(size);
    } else {
        // custom reservoir
        Reservoir reservoir;
        try {
            reservoir = loader.newInstance(clazz, Reservoir.class);
            if (reservoir instanceof PluginInfoInitialized) {
                ((PluginInfoInitialized) reservoir).init(info);
            } else {
                SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
            }
            return reservoir;
        } catch (Exception e) {
            log.warn("Error initializing custom Reservoir implementation (will use default): " + info, e);
            return new ExponentiallyDecayingReservoir(size, alpha, clk);
        }
    }
}
Also used : Reservoir(com.codahale.metrics.Reservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Clock(com.codahale.metrics.Clock) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) PluginInfoInitialized(org.apache.solr.util.plugin.PluginInfoInitialized)

Example 2 with UniformReservoir

use of com.codahale.metrics.UniformReservoir in project spring-boot by spring-projects.

the class DropwizardMetricServicesTests method setCustomReservoirTimer.

@Test
public void setCustomReservoirTimer() {
    given(this.reservoirFactory.getReservoir(anyString())).willReturn(new UniformReservoir());
    this.writer.submit("timer.foo", 200);
    this.writer.submit("timer.foo", 300);
    assertThat(this.registry.timer("timer.foo").getCount()).isEqualTo(2);
    Timer timer = (Timer) this.registry.getMetrics().get("timer.foo");
    Histogram histogram = (Histogram) ReflectionTestUtils.getField(timer, "histogram");
    assertThat(ReflectionTestUtils.getField(histogram, "reservoir").getClass().equals(UniformReservoir.class)).isTrue();
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) UniformReservoir(com.codahale.metrics.UniformReservoir) Test(org.junit.Test)

Example 3 with UniformReservoir

use of com.codahale.metrics.UniformReservoir in project Singularity by HubSpot.

the class SingularityTaskReconciliation method startReconciliation.

public ReconciliationState startReconciliation() {
    final long taskReconciliationStartedAt = System.currentTimeMillis();
    if (!isRunningReconciliation.compareAndSet(false, true)) {
        LOG.info("Reconciliation is already running, NOT starting a new reconciliation process");
        return ReconciliationState.ALREADY_RUNNING;
    }
    if (!schedulerClient.isRunning()) {
        LOG.trace("Not running reconciliation - no active scheduler present");
        isRunningReconciliation.set(false);
        return ReconciliationState.NO_DRIVER;
    }
    final List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIds();
    LOG.info("Starting a reconciliation cycle - {} current active tasks", activeTaskIds.size());
    schedulerClient.reconcile(Collections.emptyList());
    scheduleReconciliationCheck(taskReconciliationStartedAt, activeTaskIds, 0, new Histogram(new UniformReservoir()));
    return ReconciliationState.STARTED;
}
Also used : Histogram(com.codahale.metrics.Histogram) UniformReservoir(com.codahale.metrics.UniformReservoir) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 4 with UniformReservoir

use of com.codahale.metrics.UniformReservoir in project hbase by apache.

the class TestPerformanceEvaluation method testZipfian.

@Test
public void testZipfian() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    TestOptions opts = new PerformanceEvaluation.TestOptions();
    opts.setValueZipf(true);
    final int valueSize = 1024;
    opts.setValueSize(valueSize);
    RandomReadTest rrt = new RandomReadTest(null, opts, null);
    Constructor<?> ctor = Histogram.class.getDeclaredConstructor(com.codahale.metrics.Reservoir.class);
    ctor.setAccessible(true);
    Histogram histogram = (Histogram) ctor.newInstance(new UniformReservoir(1024 * 500));
    for (int i = 0; i < 100; i++) {
        histogram.update(rrt.getValueLength(null));
    }
    Snapshot snapshot = histogram.getSnapshot();
    double stddev = snapshot.getStdDev();
    assertTrue(stddev != 0 && stddev != 1.0);
    assertTrue(snapshot.getStdDev() != 0);
    double median = snapshot.getMedian();
    assertTrue(median != 0 && median != 1 && median != valueSize);
}
Also used : RandomReadTest(org.apache.hadoop.hbase.PerformanceEvaluation.RandomReadTest) Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) TestOptions(org.apache.hadoop.hbase.PerformanceEvaluation.TestOptions) UniformReservoir(com.codahale.metrics.UniformReservoir) RandomReadTest(org.apache.hadoop.hbase.PerformanceEvaluation.RandomReadTest) Test(org.junit.Test)

Example 5 with UniformReservoir

use of com.codahale.metrics.UniformReservoir in project spring-boot by spring-projects.

the class DropwizardMetricServicesTests method setCustomReservoirHistogram.

@Test
public void setCustomReservoirHistogram() {
    given(this.reservoirFactory.getReservoir(anyString())).willReturn(new UniformReservoir());
    this.writer.submit("histogram.foo", 2.1);
    this.writer.submit("histogram.foo", 2.3);
    assertThat(this.registry.histogram("histogram.foo").getCount()).isEqualTo(2);
    assertThat(ReflectionTestUtils.getField(this.registry.getMetrics().get("histogram.foo"), "reservoir").getClass().equals(UniformReservoir.class)).isTrue();
}
Also used : UniformReservoir(com.codahale.metrics.UniformReservoir) Test(org.junit.Test)

Aggregations

UniformReservoir (com.codahale.metrics.UniformReservoir)10 Test (org.junit.Test)6 Histogram (com.codahale.metrics.Histogram)5 Timer (com.codahale.metrics.Timer)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Reservoir (com.codahale.metrics.Reservoir)2 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)2 Clock (com.codahale.metrics.Clock)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 Snapshot (com.codahale.metrics.Snapshot)1 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 RandomReadTest (org.apache.hadoop.hbase.PerformanceEvaluation.RandomReadTest)1 TestOptions (org.apache.hadoop.hbase.PerformanceEvaluation.TestOptions)1 NodeConfig (org.apache.solr.core.NodeConfig)1 PluginInfoInitialized (org.apache.solr.util.plugin.PluginInfoInitialized)1 ConfigValidationException (org.graylog2.plugin.validate.ConfigValidationException)1 Test (org.junit.jupiter.api.Test)1