Search in sources :

Example 31 with Snapshot

use of com.codahale.metrics.Snapshot in project controller by opendaylight.

the class TransactionRateLimiterTest method testAcquireGetRateLimitFromOtherDataStores.

@Test
public void testAcquireGetRateLimitFromOtherDataStores() {
    for (int i = 1; i < 11; i++) {
        // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
        // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
        doReturn(0.0D).when(commitSnapshot).getValue(i * 0.1);
    }
    Timer operationalCommitTimer = mock(Timer.class);
    Timer.Context operationalCommitTimerContext = mock(Timer.Context.class);
    Snapshot operationalCommitSnapshot = mock(Snapshot.class);
    doReturn(operationalCommitTimer).when(actorContext).getOperationTimer("operational", "commit");
    doReturn(operationalCommitTimerContext).when(operationalCommitTimer).time();
    doReturn(operationalCommitSnapshot).when(operationalCommitTimer).getSnapshot();
    for (int i = 1; i < 11; i++) {
        // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
        // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
        doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(operationalCommitSnapshot).getValue(i * 0.1);
    }
    DatastoreContext.getGlobalDatastoreNames().add("config");
    DatastoreContext.getGlobalDatastoreNames().add("operational");
    TransactionRateLimiter rateLimiter = new TransactionRateLimiter(actorContext);
    rateLimiter.acquire();
    assertThat(rateLimiter.getTxCreationLimit(), approximately(292));
    assertEquals(147, rateLimiter.getPollOnCount());
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Timer(com.codahale.metrics.Timer) Test(org.junit.Test)

Example 32 with Snapshot

use of com.codahale.metrics.Snapshot in project controller by opendaylight.

the class TransactionRateLimiter method calculateNewRateLimit.

private static double calculateNewRateLimit(Timer commitTimer, long commitTimeoutInSeconds) {
    if (commitTimer == null) {
        // This can happen in unit tests.
        return 0;
    }
    Snapshot timerSnapshot = commitTimer.getSnapshot();
    double newRateLimit = 0;
    long commitTimeoutInNanos = TimeUnit.SECONDS.toNanos(commitTimeoutInSeconds);
    // Compute the rate limit for that percentile and sum it up
    for (int i = 1; i <= 10; i++) {
        // Get the amount of time transactions take in the i*10th percentile
        double percentileTimeInNanos = timerSnapshot.getValue(i * 0.1D);
        if (percentileTimeInNanos > 0) {
            // Figure out the rate limit for the i*10th percentile in nanos
            double percentileRateLimit = commitTimeoutInNanos / percentileTimeInNanos;
            // Add the percentileRateLimit to the total rate limit
            newRateLimit += percentileRateLimit;
        }
    }
    // Compute the rate limit per second
    return newRateLimit / (commitTimeoutInSeconds * 10);
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 33 with Snapshot

use of com.codahale.metrics.Snapshot in project bookkeeper by apache.

the class CodahaleOpStatsLogger method toOpStatsData.

/**
 * This function should go away soon (hopefully).
 */
public synchronized OpStatsData toOpStatsData() {
    long numFailed = fail.getCount();
    long numSuccess = success.getCount();
    Snapshot s = success.getSnapshot();
    double avgLatencyMillis = s.getMean();
    double[] defaultPercentiles = { 10, 50, 90, 99, 99.9, 99.99 };
    long[] latenciesMillis = new long[defaultPercentiles.length];
    Arrays.fill(latenciesMillis, Long.MAX_VALUE);
    for (int i = 0; i < defaultPercentiles.length; i++) {
        latenciesMillis[i] = (long) s.getValue(defaultPercentiles[i] / 100);
    }
    return new OpStatsData(numSuccess, numFailed, avgLatencyMillis, latenciesMillis);
}
Also used : Snapshot(com.codahale.metrics.Snapshot) OpStatsData(org.apache.bookkeeper.stats.OpStatsData)

Example 34 with Snapshot

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

the class SingularityTaskReconciliation method checkReconciliation.

private void checkReconciliation(final long reconciliationStart, final Collection<SingularityTaskId> remainingTaskIds, final int numTimes, final Histogram histogram) {
    final List<SingularityTaskStatusHolder> taskStatusHolders = taskManager.getLastActiveTaskStatusesFor(remainingTaskIds);
    final List<MesosTaskStatusObject> taskStatuses = Lists.newArrayListWithCapacity(taskStatusHolders.size());
    for (SingularityTaskStatusHolder taskStatusHolder : taskStatusHolders) {
        if (taskStatusHolder.getServerId().equals(serverId) && taskStatusHolder.getServerTimestamp() > reconciliationStart) {
            histogram.update(taskStatusHolder.getServerTimestamp() - reconciliationStart);
            continue;
        }
        if (taskStatusHolder.getTaskStatus().isPresent()) {
            LOG.debug("Re-requesting task status for {}", taskStatusHolder.getTaskId());
            taskStatuses.add(taskStatusHolder.getTaskStatus().get());
        } else {
            TaskStatus.Builder fakeTaskStatusBuilder = TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue(taskStatusHolder.getTaskId().getId())).setState(TaskState.TASK_STARTING);
            if (taskStatusHolder.getSlaveId().isPresent()) {
                fakeTaskStatusBuilder.setAgentId(AgentID.newBuilder().setValue(taskStatusHolder.getSlaveId().get()));
            }
            LOG.info("Task {} didn't have a TaskStatus yet, submitting fake status", taskStatusHolder.getTaskId());
            taskStatuses.add(mesosProtosUtils.taskStatusFromProtos(fakeTaskStatusBuilder.build()));
        }
    }
    if (taskStatuses.isEmpty()) {
        LOG.info("Task reconciliation ended after {} checks and {}", numTimes, JavaUtils.duration(reconciliationStart));
        final Snapshot snapshot = histogram.getSnapshot();
        stateManager.saveTaskReconciliationStatistics(new SingularityTaskReconciliationStatistics(reconciliationStart, System.currentTimeMillis() - reconciliationStart, numTimes, histogram.getCount(), snapshot.getMax(), snapshot.getMean(), snapshot.getMin(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(), snapshot.get98thPercentile(), snapshot.get99thPercentile(), snapshot.get999thPercentile(), snapshot.getStdDev()));
        isRunningReconciliation.set(false);
        return;
    }
    LOG.info("Requesting reconciliation of {} taskStatuses, task reconciliation has been running for {}", taskStatuses.size(), JavaUtils.duration(reconciliationStart));
    schedulerClient.reconcile(taskStatuses.stream().map((t) -> Task.newBuilder().setTaskId(MesosProtosUtils.toTaskId(t.getTaskId())).setAgentId(MesosProtosUtils.toAgentId(t.getAgentId())).build()).collect(Collectors.toList()));
    scheduleReconciliationCheck(reconciliationStart, remainingTaskIds, numTimes, histogram);
}
Also used : MesosTaskStatusObject(com.hubspot.mesos.protos.MesosTaskStatusObject) Snapshot(com.codahale.metrics.Snapshot) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) TaskStatus(org.apache.mesos.v1.Protos.TaskStatus) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics)

Example 35 with Snapshot

use of com.codahale.metrics.Snapshot in project incubator-gobblin by apache.

the class OutputStreamReporter method printHistogram.

private void printHistogram(Histogram histogram) {
    this.outputBufferPrintStream.printf(locale, "             count = %d%n", histogram.getCount());
    Snapshot snapshot = histogram.getSnapshot();
    this.outputBufferPrintStream.printf(locale, "               min = %d%n", snapshot.getMin());
    this.outputBufferPrintStream.printf(locale, "               max = %d%n", snapshot.getMax());
    this.outputBufferPrintStream.printf(locale, "              mean = %2.2f%n", snapshot.getMean());
    this.outputBufferPrintStream.printf(locale, "            stddev = %2.2f%n", snapshot.getStdDev());
    this.outputBufferPrintStream.printf(locale, "            median = %2.2f%n", snapshot.getMedian());
    this.outputBufferPrintStream.printf(locale, "              75%% <= %2.2f%n", snapshot.get75thPercentile());
    this.outputBufferPrintStream.printf(locale, "              95%% <= %2.2f%n", snapshot.get95thPercentile());
    this.outputBufferPrintStream.printf(locale, "              98%% <= %2.2f%n", snapshot.get98thPercentile());
    this.outputBufferPrintStream.printf(locale, "              99%% <= %2.2f%n", snapshot.get99thPercentile());
    this.outputBufferPrintStream.printf(locale, "            99.9%% <= %2.2f%n", snapshot.get999thPercentile());
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)57 Test (org.junit.Test)13 Histogram (com.codahale.metrics.Histogram)11 Timer (com.codahale.metrics.Timer)11 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 Counter (com.codahale.metrics.Counter)2 Gauge (com.codahale.metrics.Gauge)2 Meter (com.codahale.metrics.Meter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InOrder (org.mockito.InOrder)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 UniformReservoir (com.codahale.metrics.UniformReservoir)1 ResultSet (com.datastax.driver.core.ResultSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1