private static void testInsertions(
      int tests,
      int perTestCount,
      float testKeyRatio,
      int modificationBatchSize,
      boolean quickEquality)
      throws ExecutionException, InterruptedException {
    int batchesPerTest = perTestCount / modificationBatchSize;
    int testKeyRange = (int) (perTestCount * testKeyRatio);
    long totalCount = (long) perTestCount * tests;
    log(
        "Performing %d tests of %d operations, with %.2f max size/key-range ratio in batches of ~%d ops",
        tests, perTestCount, 1 / testKeyRatio, modificationBatchSize);

    // if we're not doing quick-equality, we can spam with garbage for all the checks we perform, so
    // we'll split the work into smaller chunks
    int chunkSize = quickEquality ? tests : (int) (100000 / Math.pow(perTestCount, 2));
    for (int chunk = 0; chunk < tests; chunk += chunkSize) {
      final List<ListenableFutureTask<List<ListenableFuture<?>>>> outer = new ArrayList<>();
      for (int i = 0; i < chunkSize; i++) {
        int maxRunLength =
            modificationBatchSize == 1
                ? 1
                : ThreadLocalRandom.current().nextInt(1, modificationBatchSize);
        outer.add(
            doOneTestInsertions(
                testKeyRange, maxRunLength, modificationBatchSize, batchesPerTest, quickEquality));
      }

      final List<ListenableFuture<?>> inner = new ArrayList<>();
      long complete = 0;
      int reportInterval = Math.max(1000, (int) (totalCount / 10000));
      long lastReportAt = 0;
      for (ListenableFutureTask<List<ListenableFuture<?>>> f : outer) {
        inner.addAll(f.get());
        complete += perTestCount;
        if (complete - lastReportAt >= reportInterval) {
          long done = (chunk * perTestCount) + complete;
          float ratio = done / (float) totalCount;
          log("Completed %.1f%% (%d of %d operations)", ratio * 100, done, totalCount);
          lastReportAt = complete;
        }
      }
      Futures.allAsList(inner).get();
    }
    Snapshot snap = BTREE_TIMER.getSnapshot();
    log(
        "btree: %.2fns, %.2fns, %.2fns",
        snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile());
    snap = TREE_TIMER.getSnapshot();
    log(
        "java: %.2fns, %.2fns, %.2fns",
        snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile());
    log("Done");
  }
Esempio n. 2
0
 /** @return an abbreviated summary of {@code hist}. */
 public static String getShortHistogramReport(final Histogram hist) {
   Snapshot sn = hist.getSnapshot();
   return "mean="
       + DOUBLE_FORMAT.format(sn.getMean())
       + ", min="
       + DOUBLE_FORMAT.format(sn.getMin())
       + ", max="
       + DOUBLE_FORMAT.format(sn.getMax())
       + ", stdDev="
       + DOUBLE_FORMAT.format(sn.getStdDev())
       + ", 95th="
       + DOUBLE_FORMAT.format(sn.get95thPercentile())
       + ", 99th="
       + DOUBLE_FORMAT.format(sn.get99thPercentile());
 }
Esempio n. 3
0
 @Override
 public String toString() {
   StringWriter sw = new StringWriter();
   Locale locale = Locale.ROOT;
   try (PrintWriter output = new PrintWriter(sw)) {
     final Snapshot snapshot = timer.getSnapshot();
     output.printf(locale, "Benchmark Results%n");
     output.printf(locale, "             count = %d%n", timer.getCount());
     output.printf(locale, "         mean rate = %2.2f calls/%s%n", timer.getMeanRate(), "s");
     output.printf(
         locale,
         "               min = %d %s%n",
         TimeUnit.NANOSECONDS.toMillis(snapshot.getMin()),
         "ms");
     output.printf(
         locale,
         "               max = %d %s%n",
         TimeUnit.NANOSECONDS.toMillis(snapshot.getMax()),
         "ms");
     output.printf(locale, "              mean = %2.2f %s%n", snapshot.getMean() / 1000000, "ms");
     output.printf(
         locale, "            stddev = %2.2f %s%n", snapshot.getStdDev() / 1000000, "ms");
     output.printf(
         locale, "            median = %2.2f %s%n", snapshot.getMedian() / 1000000, "ms");
     output.printf(
         locale, "              75%% <= %2.2f %s%n", snapshot.get75thPercentile() / 1000000, "ms");
     output.printf(
         locale, "              95%% <= %2.2f %s%n", snapshot.get95thPercentile() / 1000000, "ms");
     output.printf(
         locale,
         "            99.9%% <= %2.2f %s%n",
         snapshot.get999thPercentile() / 1000000,
         "ms");
   }
   return sw.toString();
 }
Esempio n. 4
0
  private void adjustMetrics(
      Map<String, Map<Integer, MetricSnapshot>> metrics,
      Map<String, Integer> metaCounters,
      Map<String, Map<Integer, Histogram>> histograms,
      Map<String, Map<Integer, Timer>> timers) {
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
      String meta = metricEntry.getKey();
      MetricType metricType = MetricUtils.metricType(meta);
      MetaType metaType = MetricUtils.metaType(meta);
      Map<Integer, MetricSnapshot> winData = metricEntry.getValue();

      if (metricType == MetricType.HISTOGRAM) {
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
          MetricSnapshot snapshot = dataEntry.getValue();
          Integer cnt = metaCounters.get(meta);
          Histogram histogram = histograms.get(meta).get(dataEntry.getKey());
          if (cnt != null && cnt > 1) {

            Snapshot snapshot1 = histogram.getSnapshot();
            snapshot.set_mean(snapshot1.getMean());
            snapshot.set_p50(snapshot1.getMedian());
            snapshot.set_p75(snapshot1.get75thPercentile());
            snapshot.set_p95(snapshot1.get95thPercentile());
            snapshot.set_p98(snapshot1.get98thPercentile());
            snapshot.set_p99(snapshot1.get99thPercentile());
            snapshot.set_p999(snapshot1.get999thPercentile());
            snapshot.set_stddev(snapshot1.getStdDev());
            snapshot.set_min(snapshot1.getMin());
            snapshot.set_max(snapshot1.getMax());

            if (metaType == MetaType.TOPOLOGY) {
              snapshot.set_points(Arrays.asList(ArrayUtils.toObject(snapshot1.getValues())));
            }
          }
          if (metaType != MetaType.TOPOLOGY) {
            snapshot.set_points(new ArrayList<Long>(0));
          }
        }

      } else if (metricType == MetricType.TIMER) {
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
          MetricSnapshot snapshot = dataEntry.getValue();
          Integer cnt = metaCounters.get(meta);
          if (cnt != null && cnt > 1) {
            Timer timer = timers.get(meta).get(dataEntry.getKey());
            Snapshot snapshot1 = timer.getSnapshot();
            snapshot.set_p50(snapshot1.getMedian());
            snapshot.set_p75(snapshot1.get75thPercentile());
            snapshot.set_p95(snapshot1.get95thPercentile());
            snapshot.set_p98(snapshot1.get98thPercentile());
            snapshot.set_p99(snapshot1.get99thPercentile());
            snapshot.set_p999(snapshot1.get999thPercentile());
            snapshot.set_stddev(snapshot1.getStdDev());
            snapshot.set_min(snapshot1.getMin());
            snapshot.set_max(snapshot1.getMax());
          }
          snapshot.set_points(new ArrayList<Long>(0));
        }
      }
    }
  }
 public int size() {
   return s.size();
 }
 public long[] getValues() {
   return s.getValues();
 }
 public double getValue(double quantile) {
   return s.getValue(quantile);
 }
 public double getStdDev() {
   return s.getStdDev();
 }
 public long getMin() {
   return s.getMin();
 }
Esempio n. 10
0
 public double getMedian() {
   return s.getMedian();
 }
Esempio n. 11
0
 public long getMax() {
   return s.getMax();
 }
Esempio n. 12
0
 public double get99thPercentile() {
   return s.get99thPercentile();
 }
  private void collectTimerReports(
      List<DBObject> docs, SortedMap<String, Timer> timers, Date timestamp) {
    if (timers.isEmpty()) return;
    for (Map.Entry<String, Timer> entry : timers.entrySet()) {
      final BasicDBObject report = getBasicDBObject(timestamp, entry.getKey(), "timer");
      final Timer v = entry.getValue();
      final Snapshot s = v.getSnapshot();
      // meter part
      report.put("count", v.getCount());
      report.put("rate-unit", getRateUnit());
      report.put("1-minute-rate", convertRate(v.getOneMinuteRate()));
      report.put("5-minute-rate", convertRate(v.getFiveMinuteRate()));
      report.put("15-minute-rate", convertRate(v.getFifteenMinuteRate()));
      report.put("mean-rate", convertRate(v.getMeanRate()));

      // histogram part
      report.put("duration-unit", getDurationUnit());
      report.put("75-percentile", convertDuration(s.get75thPercentile()));
      report.put("95-percentile", convertDuration(s.get95thPercentile()));
      report.put("98-percentile", convertDuration(s.get98thPercentile()));
      report.put("99-percentile", convertDuration(s.get99thPercentile()));
      report.put("999-percentile", convertDuration(s.get999thPercentile()));
      report.put("max", convertDuration(s.getMax()));
      report.put("min", convertDuration(s.getMin()));
      report.put("mean", convertDuration(s.getMean()));
      report.put("median", convertDuration(s.getMedian()));
      report.put("stddev", convertDuration(s.getStdDev()));
      docs.add(report);
    }
  }
  private void collectHistogramReports(
      List<DBObject> docs, SortedMap<String, Histogram> histograms, Date timestamp) {
    if (histograms.isEmpty()) return;

    for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
      final BasicDBObject report = getBasicDBObject(timestamp, entry.getKey(), "histogram");
      final Histogram histogram = entry.getValue();

      final Snapshot s = histogram.getSnapshot();
      report.put("count", s.size());
      report.put("75th_percentile", s.get75thPercentile());
      report.put("95th_percentile", s.get95thPercentile());
      report.put("98th_percentile", s.get98thPercentile());
      report.put("99th_percentile", s.get99thPercentile());
      report.put("999th_percentile", s.get999thPercentile());
      report.put("max", s.getMax());
      report.put("min", s.getMin());
      report.put("mean", s.getMean());
      report.put("median", s.getMedian());
      report.put("std_dev", s.getStdDev());
      docs.add(report);
    }
  }
  public void addSampling(String name, Sampling sampling, boolean convert) {
    final Snapshot snapshot = sampling.getSnapshot();
    maybeAdd(MEDIAN, name, convertDuration(snapshot.getMedian(), convert));
    maybeAdd(PCT_75, name, convertDuration(snapshot.get75thPercentile(), convert));
    maybeAdd(PCT_95, name, convertDuration(snapshot.get95thPercentile(), convert));
    maybeAdd(PCT_98, name, convertDuration(snapshot.get98thPercentile(), convert));
    maybeAdd(PCT_99, name, convertDuration(snapshot.get99thPercentile(), convert));
    maybeAdd(PCT_999, name, convertDuration(snapshot.get999thPercentile(), convert));

    if (!omitComplexGauges) {
      final double sum = snapshot.size() * snapshot.getMean();
      final long count = (long) snapshot.size();
      if (count > 0) {
        SourceInformation info = SourceInformation.from(sourceRegex, name);
        MultiSampleGaugeMeasurement measurement;
        try {
          measurement =
              MultiSampleGaugeMeasurement.builder(addPrefix(info.name))
                  .setSource(info.source)
                  .setCount(count)
                  .setSum(convertDuration(sum, convert))
                  .setMax(convertDuration(snapshot.getMax(), convert))
                  .setMin(convertDuration(snapshot.getMin(), convert))
                  .build();
        } catch (IllegalArgumentException e) {
          log.warn("Could not create gauge", e);
          return;
        }
        addMeasurement(measurement);
      }
    }
  }