Search in sources :

Example 1 with SlidingWindowReservoir

use of com.codahale.metrics.SlidingWindowReservoir in project hadoop by apache.

the class SLSCapacityScheduler method registerSchedulerMetrics.

private void registerSchedulerMetrics() {
    samplerLock.lock();
    try {
        // counters for scheduler operations
        schedulerAllocateCounter = metrics.counter("counter.scheduler.operation.allocate");
        schedulerHandleCounter = metrics.counter("counter.scheduler.operation.handle");
        schedulerHandleCounterMap = new HashMap<SchedulerEventType, Counter>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Counter counter = metrics.counter("counter.scheduler.operation.handle." + e);
            schedulerHandleCounterMap.put(e, counter);
        }
        // timers for scheduler operations
        int timeWindowSize = conf.getInt(SLSConfiguration.METRICS_TIMER_WINDOW_SIZE, SLSConfiguration.METRICS_TIMER_WINDOW_SIZE_DEFAULT);
        schedulerAllocateTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimerMap = new HashMap<SchedulerEventType, Timer>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Timer timer = new Timer(new SlidingWindowReservoir(timeWindowSize));
            schedulerHandleTimerMap.put(e, timer);
        }
        // histogram for scheduler operations (Samplers)
        schedulerHistogramList = new ArrayList<Histogram>();
        histogramTimerMap = new HashMap<Histogram, Timer>();
        Histogram schedulerAllocateHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.allocate.timecost", schedulerAllocateHistogram);
        schedulerHistogramList.add(schedulerAllocateHistogram);
        histogramTimerMap.put(schedulerAllocateHistogram, schedulerAllocateTimer);
        Histogram schedulerHandleHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.handle.timecost", schedulerHandleHistogram);
        schedulerHistogramList.add(schedulerHandleHistogram);
        histogramTimerMap.put(schedulerHandleHistogram, schedulerHandleTimer);
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Histogram histogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
            metrics.register("sampler.scheduler.operation.handle." + e + ".timecost", histogram);
            schedulerHistogramList.add(histogram);
            histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e));
        }
    } finally {
        samplerLock.unlock();
    }
}
Also used : SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) SchedulerEventType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType)

Example 2 with SlidingWindowReservoir

use of com.codahale.metrics.SlidingWindowReservoir in project hadoop by apache.

the class ResourceSchedulerWrapper method registerSchedulerMetrics.

private void registerSchedulerMetrics() {
    samplerLock.lock();
    try {
        // counters for scheduler operations
        schedulerAllocateCounter = metrics.counter("counter.scheduler.operation.allocate");
        schedulerHandleCounter = metrics.counter("counter.scheduler.operation.handle");
        schedulerHandleCounterMap = new HashMap<SchedulerEventType, Counter>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Counter counter = metrics.counter("counter.scheduler.operation.handle." + e);
            schedulerHandleCounterMap.put(e, counter);
        }
        // timers for scheduler operations
        int timeWindowSize = conf.getInt(SLSConfiguration.METRICS_TIMER_WINDOW_SIZE, SLSConfiguration.METRICS_TIMER_WINDOW_SIZE_DEFAULT);
        schedulerAllocateTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimerMap = new HashMap<SchedulerEventType, Timer>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Timer timer = new Timer(new SlidingWindowReservoir(timeWindowSize));
            schedulerHandleTimerMap.put(e, timer);
        }
        // histogram for scheduler operations (Samplers)
        schedulerHistogramList = new ArrayList<Histogram>();
        histogramTimerMap = new HashMap<Histogram, Timer>();
        Histogram schedulerAllocateHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.allocate.timecost", schedulerAllocateHistogram);
        schedulerHistogramList.add(schedulerAllocateHistogram);
        histogramTimerMap.put(schedulerAllocateHistogram, schedulerAllocateTimer);
        Histogram schedulerHandleHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.handle.timecost", schedulerHandleHistogram);
        schedulerHistogramList.add(schedulerHandleHistogram);
        histogramTimerMap.put(schedulerHandleHistogram, schedulerHandleTimer);
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Histogram histogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
            metrics.register("sampler.scheduler.operation.handle." + e + ".timecost", histogram);
            schedulerHistogramList.add(histogram);
            histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e));
        }
    } finally {
        samplerLock.unlock();
    }
}
Also used : SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) SchedulerEventType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType)

Example 3 with SlidingWindowReservoir

use of com.codahale.metrics.SlidingWindowReservoir 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 4 with SlidingWindowReservoir

use of com.codahale.metrics.SlidingWindowReservoir in project flink by apache.

the class DropwizardFlinkHistogramWrapperTest method testDropwizardHistogramWrapperReporting.

/**
 * Tests that the DropwizardHistogramWrapper reports correct dropwizard snapshots to the
 * ScheduledReporter.
 */
@Test
void testDropwizardHistogramWrapperReporting() throws Exception {
    int size = 10;
    String histogramMetricName = "histogram";
    final TestingReporter testingReporter = new TestingReporter();
    testingReporter.open(new MetricConfig());
    DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
    final MetricGroup metricGroup = TestMetricGroup.newBuilder().build();
    testingReporter.notifyOfAddedMetric(histogramWrapper, histogramMetricName, metricGroup);
    // check that the metric has been registered
    assertThat(testingReporter.getMetrics()).hasSize(1);
    for (int i = 0; i < size; i++) {
        histogramWrapper.update(i);
    }
    testingReporter.report();
    String fullMetricName = metricGroup.getMetricIdentifier(histogramMetricName);
    Snapshot snapshot = testingReporter.getNextHistogramSnapshot(fullMetricName);
    assertThat(snapshot.getMin()).isEqualTo(0);
    assertThat(snapshot.getMedian()).isCloseTo((size - 1) / 2.0, offset(0.001));
    assertThat(snapshot.getMax()).isEqualTo(size - 1);
    assertThat(snapshot.size()).isEqualTo(size);
    testingReporter.notifyOfRemovedMetric(histogramWrapper, histogramMetricName, metricGroup);
    // check that the metric has been de-registered
    assertThat(testingReporter.getMetrics()).hasSize(0);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Snapshot(com.codahale.metrics.Snapshot) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.Test) AbstractHistogramTest(org.apache.flink.metrics.AbstractHistogramTest)

Aggregations

SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)4 Counter (com.codahale.metrics.Counter)2 Histogram (com.codahale.metrics.Histogram)2 Timer (com.codahale.metrics.Timer)2 SchedulerEventType (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType)2 Clock (com.codahale.metrics.Clock)1 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)1 Reservoir (com.codahale.metrics.Reservoir)1 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)1 Snapshot (com.codahale.metrics.Snapshot)1 UniformReservoir (com.codahale.metrics.UniformReservoir)1 AbstractHistogramTest (org.apache.flink.metrics.AbstractHistogramTest)1 MetricConfig (org.apache.flink.metrics.MetricConfig)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 TestMetricGroup (org.apache.flink.metrics.util.TestMetricGroup)1 PluginInfoInitialized (org.apache.solr.util.plugin.PluginInfoInitialized)1 Test (org.junit.jupiter.api.Test)1