Package com.yammer.metrics.stats

Examples of com.yammer.metrics.stats.Snapshot


    for (int i = 0; i < data.length; i++) {
      data[i] = (long) (r.nextGaussian() * 10000.0);
      h.update(data[i]);
    }

    final Snapshot s = h.getSnapshot();
    Arrays.sort(data);

    // as long as the histogram chooses an item with index N+/-slop, accept it
    final int slop = 20;

    // make sure the median, 75th percentile and 95th percentile are good
    final int medianIndex = data.length / 2;
    final long minAcceptableMedian = data[safeIndex(medianIndex - slop,
        data.length)];
    final long maxAcceptableMedian = data[safeIndex(medianIndex + slop,
        data.length)];
    Assert.assertTrue(s.getMedian() >= minAcceptableMedian
        && s.getMedian() <= maxAcceptableMedian);

    final int seventyFifthIndex = (int) (data.length * 0.75);
    final long minAcceptableseventyFifth = data[safeIndex(seventyFifthIndex
        - slop, data.length)];
    final long maxAcceptableseventyFifth = data[safeIndex(seventyFifthIndex
        + slop, data.length)];
    Assert.assertTrue(s.get75thPercentile() >= minAcceptableseventyFifth
        && s.get75thPercentile() <= maxAcceptableseventyFifth);

    final int ninetyFifthIndex = (int) (data.length * 0.95);
    final long minAcceptableninetyFifth = data[safeIndex(ninetyFifthIndex
        - slop, data.length)];
    final long maxAcceptableninetyFifth = data[safeIndex(ninetyFifthIndex
        + slop, data.length)];
    Assert.assertTrue(s.get95thPercentile() >= minAcceptableninetyFifth
        && s.get95thPercentile() <= maxAcceptableninetyFifth);

  }
View Full Code Here


        output = out;
    }

    public void run()
    {
        Snapshot latency;
        long oldLatency;
        int epoch, total, oldTotal, keyCount, oldKeyCount;

        // creating keyspace and column families
        if (client.getOperation() == Stress.Operations.INSERT || client.getOperation() == Stress.Operations.COUNTER_ADD)
            client.createKeySpaces();

        int threadCount = client.getThreads();
        Consumer[] consumers = new Consumer[threadCount];

        output.println("total,interval_op_rate,interval_key_rate,latency,95th,99.9th,elapsed_time");

        int itemsPerThread = client.getKeysPerThread();
        int modulo = client.getNumKeys() % threadCount;
        RateLimiter rateLimiter = RateLimiter.create(client.getMaxOpsPerSecond());

        // creating required type of the threads for the test
        for (int i = 0; i < threadCount; i++) {
            if (i == threadCount - 1)
                itemsPerThread += modulo; // last one is going to handle N + modulo items

            consumers[i] = new Consumer(itemsPerThread, rateLimiter);
        }

        Producer producer = new Producer();
        producer.start();

        // starting worker threads
        for (int i = 0; i < threadCount; i++)
            consumers[i].start();

        // initialization of the values
        boolean terminate = false;
        epoch = total = keyCount = 0;

        int interval = client.getProgressInterval();
        int epochIntervals = client.getProgressInterval() * 10;
        long testStartTime = System.nanoTime();
       
        StressStatistics stats = new StressStatistics(client, output);

        while (!terminate)
        {
            if (stop)
            {
                producer.stopProducer();

                for (Consumer consumer : consumers)
                    consumer.stopConsume();

                break;
            }

            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);

            int alive = 0;
            for (Thread thread : consumers)
                if (thread.isAlive()) alive++;

            if (alive == 0)
                terminate = true;

            epoch++;

            if (terminate || epoch > epochIntervals)
            {
                epoch = 0;

                oldTotal = total;
                oldKeyCount = keyCount;

                total = client.operations.get();
                keyCount = client.keys.get();
                latency = client.latency.getSnapshot();

                int opDelta = total - oldTotal;
                int keyDelta = keyCount - oldKeyCount;

                long currentTimeInSeconds = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - testStartTime);

                output.println(String.format("%d,%d,%d,%.1f,%.1f,%.1f,%d",
                                             total,
                                             opDelta / interval,
                                             keyDelta / interval,
                                             latency.getMedian(), latency.get95thPercentile(), latency.get999thPercentile(),
                                             currentTimeInSeconds));

                if (client.outputStatistics()) {
                    stats.addIntervalStats(total,
                                           opDelta / interval,
View Full Code Here

                    lastReportAt = complete;
                }
            }
            Futures.allAsList(inner).get();
        }
        Snapshot snap = BTREE_TIMER.getSnapshot();
        System.out.println(String.format("btree   : %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile()));
        snap = TREE_TIMER.getSnapshot();
        System.out.println(String.format("snaptree: %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile()));
        System.out.println("Done");
    }
View Full Code Here

          valueSize.count() + " measures");
      reportHistogram(this.valueSize);
    }

    private void reportHistogram(final Histogram h) throws IOException {
      Snapshot sn = h.getSnapshot();
      status.setStatus(testName + " Min      = " + h.min());
      status.setStatus(testName + " Avg      = " + h.mean());
      status.setStatus(testName + " StdDev   = " + h.stdDev());
      status.setStatus(testName + " 50th     = " + sn.getMedian());
      status.setStatus(testName + " 75th     = " + sn.get75thPercentile());
      status.setStatus(testName + " 95th     = " + sn.get95thPercentile());
      status.setStatus(testName + " 99th     = " + sn.get99thPercentile());
      status.setStatus(testName + " 99.9th   = " + sn.get999thPercentile());
      status.setStatus(testName + " 99.99th  = " + sn.getValue(0.9999));
      status.setStatus(testName + " 99.999th = " + sn.getValue(0.99999));
      status.setStatus(testName + " Max      = " + h.max());
    }
View Full Code Here

      histogram.update(rrt.getValueLength(null));
    }
    double stddev = histogram.stdDev();
    assertTrue(stddev != 0 && stddev != 1.0);
    assertTrue(histogram.stdDev() != 0);
    Snapshot snapshot = histogram.getSnapshot();
    double median = snapshot.getMedian();
    assertTrue(median != 0 && median != 1 && median != valueSize);
  }
View Full Code Here

      return new AgeSnapshot(this.age);
    }

    @Override
    public String toString() {
      Snapshot snapshot = this.age.getSnapshot();
      return "count=" + count + ", dataBlockCount=" + this.dataBlockCount + ", size=" + size +
          ", dataSize=" + getDataSize() +
          ", mean age=" + this.age.mean() + ", stddev age=" + this.age.stdDev() +
          ", min age=" + this.age.min() + ", max age=" + this.age.max() +
          ", 95th percentile age=" + snapshot.get95thPercentile() +
          ", 99th percentile age=" + snapshot.get99thPercentile();
    }
View Full Code Here

        histogram.getName() + "Mean",
        StringUtils.limitDecimalTo2(histogram.getMean()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "Count",
        StringUtils.limitDecimalTo2(histogram.getCount()));
    final Snapshot s = histogram.getSnapshot();
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "Median", StringUtils.limitDecimalTo2(s.getMedian()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "75th", StringUtils.limitDecimalTo2(s.get75thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "95th", StringUtils.limitDecimalTo2(s.get95thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "99th", StringUtils.limitDecimalTo2(s.get99thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "999th", StringUtils.limitDecimalTo2(s.get999thPercentile()));
    return sb;
  }
View Full Code Here

  public void testMetricsMBeanBaseHistogram()
      throws ReflectionException, AttributeNotFoundException, MBeanException {
    MetricsRegistry mr = new MetricsRegistry();
    MetricsHistogram histo = mock(MetricsHistogram.class);
    Snapshot snap = mock(Snapshot.class);

    //Set up the mocks
    String histoName = "MockHisto";
    when(histo.getName()).thenReturn(histoName);
    when(histo.getCount()).thenReturn(20l);
    when(histo.getMin()).thenReturn(1l);
    when(histo.getMax()).thenReturn(999l);
    when(histo.getMean()).thenReturn(500.2);
    when(histo.getStdDev()).thenReturn(1.2);
    when(histo.getSnapshot()).thenReturn(snap);

    when(snap.getMedian()).thenReturn(490.0);
    when(snap.get75thPercentile()).thenReturn(550.0);
    when(snap.get95thPercentile()).thenReturn(900.0);
    when(snap.get99thPercentile()).thenReturn(990.0);

    mr.add("myTestHisto", histo);

    MetricsMBeanBase mBeanBase = new MetricsMBeanBase(mr, "test");
View Full Code Here

        histogram.getName() + "Mean",
        StringUtils.limitDecimalTo2(histogram.getMean()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "Count",
        StringUtils.limitDecimalTo2(histogram.getCount()));
    final Snapshot s = histogram.getSnapshot();
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "Median",
        StringUtils.limitDecimalTo2(s.getMedian()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "75th",
        StringUtils.limitDecimalTo2(s.get75thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "95th",
        StringUtils.limitDecimalTo2(s.get95thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "99th",
        StringUtils.limitDecimalTo2(s.get99thPercentile()));
    sb = Strings.appendKeyValue(sb,
        histogram.getName() + "999th",
        StringUtils.limitDecimalTo2(s.get999thPercentile()));
    return sb;
  }
View Full Code Here

    @Override
    public void processHistogram(MetricName name, Histogram histogram, Date context) throws Exception {
        List<Dimension> dimensions = createDimensions(name, histogram);
        String sanitizedName = sanitizeName(name);
        Snapshot snapshot = histogram.getSnapshot();
        for (double percentile : percentilesToSend) {
            if (percentile == .5) {
                sendValue(context, sanitizedName + ".median", snapshot.getMedian(), StandardUnit.None, dimensions);
            } else {
                sendValue(context, sanitizedName + "_percentile_" + percentile, snapshot.getValue(percentile), StandardUnit.None, dimensions);
            }
        }
        if (sendHistoLifetime) {
            sendValue(context, sanitizedName + ".min", histogram.min(), StandardUnit.None, dimensions);
            sendValue(context, sanitizedName + ".max", histogram.max(), StandardUnit.None, dimensions);
View Full Code Here

TOP

Related Classes of com.yammer.metrics.stats.Snapshot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.