Java 类com.codahale.metrics.UniformReservoir 实例源码

项目:bamboo    文件:BaseWarcDomainManager.java   
@VisibleForTesting
@SuppressWarnings("unused")
public static void forTestSetMetricsRegistryName(String metricsRegistryName) {
  if (imStarted) {
    throw new IllegalStateException("Unit tests only!!!");
  }
  MetricRegistry metrics = SharedMetricRegistries.getOrCreate(metricsRegistryName);
  bambooReadTimer = new Timer();
  metrics.register("bambooReadTimer", bambooReadTimer);
  bambooParseTimer = new Timer();
  metrics.register("bambooParseTimer", bambooParseTimer);
  warcDocCountHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcDocCountHistogram", warcDocCountHistogram);
  warcSizeHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcSizeHistogram", warcSizeHistogram);
}
项目:lightweight-java-metrics    文件:MetricsFactory.java   
@Override
@SuppressWarnings("unchecked")
public <T> T create(final Class<T> type) {

    if (type.equals(Meter.class)) {
        return (T) new Meter();
    }

    if (type.equals(Counter.class)) {
        return (T) new Counter();
    }

    if (type.equals(Histogram.class)) {
        return (T) new Histogram(new UniformReservoir());
    }

    return null;

}
项目:hbase    文件:TestPerformanceEvaluation.java   
@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);
}
项目:Singularity    文件:SingularityTaskReconciliation.java   
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;
}
项目:microbule    文件:UniformTimingStrategyTest.java   
@Test
public void testCreateTimer() throws ReflectiveOperationException {
    final UniformTimingStrategy strategy = new UniformTimingStrategy();
    final Timer timer = strategy.createTimer(new MapConfig());
    UniformReservoir reservoir = reservoir(timer);
    assertNotNull(reservoir);
    assertEquals("uniform", strategy.name());
}
项目:carbon-metrics    文件:MetricManager.java   
/**
 * 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");

    }
}
项目:bamboo    文件:FilteringCoordinationService.java   
private Histogram yearHistogram(String year) {
  if (!yearSizes.containsKey(year)) {
    synchronized (yearSizes) {
      if (!yearSizes.containsKey(year)) {
        Histogram h = new Histogram(new UniformReservoir());
        metrics.register("size.year." + year, h);
        yearSizes.put(year, h);
      }
    }
  }
  return yearSizes.get(year);
}
项目:bamboo    文件:FilteringCoordinationService.java   
private void lazyLoadByKey(Map map, Object key, String prefix) {
  if (key == null) return;
  if (!map.containsKey(key)) {
    synchronized (map) {
      if (!map.containsKey(key)) {
        Histogram h = new Histogram(new UniformReservoir());
        metrics.register(prefix + key.toString().replaceAll("\\*", "star") + "", h);
        map.put(key, h);
      }
    }
  }
}
项目:jooby    文件:MetricHandlerTest.java   
@Test
public void histograms() throws Exception {
  MetricRegistry registry = new MetricRegistry();
  Histogram h = new Histogram(new UniformReservoir());
  registry.register("h", h);
  h.update(7);
  // result
  Map<String, Object> result = new TreeMap<>();
  result.put("histograms",
      ImmutableMap.of("h", ImmutableMap.builder()
          .put("max", 7D)
          .put("mean", 7D)
          .put("min", 7D)
          .put("p50", 7D)
          .put("p75", 7D)
          .put("p95", 7D)
          .put("p98", 7D)
          .put("p99", 7D)
          .put("p999", 7D)
          .put("values", Lists.newArrayList(7D))
          .build()));

  new MockUnit(Request.class, Response.class)
      .expect(registry(registry))
      .expect(name("name", Optional.empty()))
      .expect(param("type", "*"))
      .expect(param("unit", "seconds", "seconds"))
      .expect(bparam("showSamples", true))
      .expect(send(Status.OK, result))
      .run(unit -> {
        new MetricHandler().handle(unit.get(Request.class), unit.get(Response.class));
      });
}
项目:heftydb    文件:Metrics.java   
private void initMetrics() {
    //Main DB Metrics
    metrics.register(metricName("write"), new Timer(new UniformReservoir()));
    metrics.register(metricName("write.rate"), new Meter());
    metrics.register(metricName("read"), new Timer(new UniformReservoir()));
    metrics.register(metricName("read.rate"), new Meter());
    metrics.register(metricName("scan"), new Timer(new UniformReservoir()));
    metrics.register(metricName("scan.rate"), new Meter());

    //Write
    metrics.register(metricName("write.concurrentMemoryTableSerializers"), new Histogram(new UniformReservoir()));
    metrics.register(metricName("write.memoryTableSerialize"), new Timer(new UniformReservoir()));

    //Read
    metrics.register(metricName("read.tablesConsulted"), new Histogram(new UniformReservoir()));
    metrics.register(metricName("read.bloomFilterFalsePositiveRate"), new CacheHitGauge());
    metrics.register(metricName("read.recordNotFoundRate"), new CacheHitGauge());

    //FileTable
    metrics.register(metricName("table.cacheHitRate"), new CacheHitGauge());

    //Index
    metrics.register(metricName("index.searchLevels"), new Histogram(new UniformReservoir()));
    metrics.register(metricName("index.cacheHitRate"), new CacheHitGauge());

    //Compactor
    metrics.register(metricName("compactor.concurrentTasks"), new Histogram(new UniformReservoir()));
    metrics.register(metricName("compactor.taskExecution"), new Timer(new UniformReservoir()));
}
项目:microbule    文件:UniformTimingStrategy.java   
@Override
public Timer createTimer(Config config) {
    return new Timer(new UniformReservoir(config.integerValue(SIZE_PROP).orElse(DEFAULT_SIZE)));
}
项目:bamboo    文件:FilteringCoordinationService.java   
private void newDomainFilterHistogram(String rules, String metricsName) {
  Histogram h = new Histogram(new UniformReservoir());
  domainSizes.put(new SurtFilter(rules), h);
  metrics.register(metricsName, h);
}
项目:bamboo    文件:BaseWarcDomainManager.java   
protected static synchronized void startMe(FilteringCoordinationService filtering, boolean indexFullText) {
  if (imStarted) {
    throw new IllegalStateException("You started me twice!");
  }
log.info("Bamboo Base URL  : {}", bambooBaseUrl);
log.info("Metrics registry : {}", filtering.getMetricsRegistryName());
log.info("# Filters        : {}", filterPoolLimit);
log.info("# Transformers   : {}", transformPoolLimit);
log.info("# Indexers       : {}", indexPoolLimit);

  // Metrics are fun...
  MetricRegistry metrics = SharedMetricRegistries.getOrCreate(filtering.getMetricsRegistryName());
  bambooReadTimer = new Timer();
  metrics.register("bambooReadTimer", bambooReadTimer);
  bambooParseTimer = new Timer();
  metrics.register("bambooParseTimer", bambooParseTimer);
  Gauge<Long> bambooCacheNull = () -> bambooCacheNullLong;
  metrics.register("bambooCacheNull", bambooCacheNull);
  Gauge<Long> bambooCacheHit = () -> bambooCacheHitLong;
  metrics.register("bambooCacheHit", bambooCacheHit);
  Gauge<Long> bambooCacheMiss = () -> bambooCacheMissLong;
  metrics.register("bambooCacheMiss", bambooCacheMiss);
  warcDocCountHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcDocCountHistogram", warcDocCountHistogram);
  warcSizeHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcSizeHistogram", warcSizeHistogram);
  Timer filterTimer = new Timer();
  metrics.register("filterTimer", filterTimer);
  Timer transformTimer = new Timer();
  metrics.register("transformTimer", transformTimer);
  Timer indexTimer = new Timer();
  metrics.register("indexTimer", indexTimer);

  // Filter workers
  WorkProcessor filterPool = new WorkProcessor(filterPoolLimit);
  for (int i = 0; i < filterPoolLimit; i++) {
    filterPool.process(new FilterWorker(filtering, filterTimer));
  }

  // Transform workers
  WorkProcessor transformPool = new WorkProcessor(transformPoolLimit);
  for (int i = 0; i < transformPoolLimit; i++) {
    transformPool.process(new TransformWorker(transformTimer, indexFullText));
  }

  // Indexing workers
  WorkProcessor indexPool = new WorkProcessor(indexPoolLimit);
  for (int i = 0; i < indexPoolLimit; i++) {
    indexPool.process(new IndexerWorker(indexTimer));
  }

  imStarted = true;
}
项目:hbase    文件:PerformanceEvaluation.java   
void testSetup() throws IOException {
  createConnection();
  onStartup();
  latencyHistogram = YammerHistogramUtils.newHistogram(new UniformReservoir(1024 * 500));
  valueSizeHistogram = YammerHistogramUtils.newHistogram(new UniformReservoir(1024 * 500));
}
项目:qdigest-benchmark    文件:MetricsHistogramFactory.java   
public IQDigest newInstance(long factor)
{
    return new MetricsHistogram(new UniformReservoir());
}
项目:prometheus-client    文件:Summary.java   
/**
 * Create this summary with a uniform reservoir - a reservoir that randomally saves the measurements and is
 * statistically representative of all measurements.
 *
 * @param size the size of the reservoir - the number of measurements that will be saved
 * @see <a href="http://www.cs.umd.edu/~samir/498/vitter.pdf">Random Sampling with a Reservoir</a>
 */
public SummaryBuilder withUniformReservoir(final int size) {
  reservoirSupplier = () -> new UniformReservoir(size);
  return SummaryBuilder.this;
}
项目:strongback-java    文件:ExecutableTimer.java   
/**
 * Create an executable timer that measures the specified number of samples.
 *
 * @param numberOfSamples the maximum number of samples to take; must be positive
 * @param uponCompletion the function that will be called
 */
private ExecutableTimer(int numberOfSamples, Consumer<ExecutableTimer> uponCompletion) {
    histogram = new Histogram(new UniformReservoir(numberOfSamples));
    numSamples = numberOfSamples;
    resultsHandler = uponCompletion;
}