Search in sources :

Example 1 with UntypedMetric

use of com.yahoo.metrics.simple.UntypedMetric in project vespa by vespa-engine.

the class SnapshotConverter method convert.

MetricSnapshot convert() {
    for (Map.Entry<Identifier, UntypedMetric> entry : snapshot.entrySet()) {
        Identifier ident = entry.getKey();
        getMap(ident.getLocation()).put(ident.getName(), convert(entry.getValue()));
    }
    Map<MetricDimensions, MetricSet> data = new HashMap<>();
    for (Map.Entry<Point, Map<String, MetricValue>> entry : perPointData.entrySet()) {
        MetricDimensions key = convert(entry.getKey());
        MetricSet newval = new MetricSet(entry.getValue());
        MetricSet old = data.get(key);
        if (old != null) {
            // should not happen, this is bad
            // TODO: consider merging the two MetricSet instances
            log.warning("losing MetricSet when converting for: " + entry.getKey());
        } else {
            data.put(key, newval);
        }
    }
    return new MetricSnapshot(snapshot.getFromMillis(), snapshot.getToMillis(), TimeUnit.MILLISECONDS, data);
}
Also used : Identifier(com.yahoo.metrics.simple.Identifier) Point(com.yahoo.metrics.simple.Point) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric)

Example 2 with UntypedMetric

use of com.yahoo.metrics.simple.UntypedMetric in project vespa by vespa-engine.

the class SnapshotConverter method outputHistograms.

void outputHistograms(PrintStream output) {
    boolean gotHistogram = false;
    for (Map.Entry<Identifier, UntypedMetric> entry : snapshot.entrySet()) {
        if (entry.getValue().getHistogram() == null) {
            continue;
        }
        gotHistogram = true;
        DoubleHistogram histogram = entry.getValue().getHistogram();
        Identifier id = entry.getKey();
        String metricIdentifier = getIdentifierString(id);
        output.println("# start of metric " + metricIdentifier);
        histogram.outputPercentileDistribution(output, 4, 1.0d, true);
        output.println("# end of metric " + metricIdentifier);
    }
    if (!gotHistogram) {
        output.println("# No histograms currently available.");
    }
}
Also used : DoubleHistogram(org.HdrHistogram.DoubleHistogram) Identifier(com.yahoo.metrics.simple.Identifier) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric)

Example 3 with UntypedMetric

use of com.yahoo.metrics.simple.UntypedMetric in project vespa by vespa-engine.

the class RateLimitingSearcherTestCase method testRateLimiting.

@Test
public void testRateLimiting() {
    RateLimitingConfig.Builder rateLimitingConfig = new RateLimitingConfig.Builder();
    rateLimitingConfig.maxAvailableCapacity(4);
    rateLimitingConfig.capacityIncrement(2);
    rateLimitingConfig.recheckForCapacityProbability(1.0);
    ClusterInfoConfig.Builder clusterInfoConfig = new ClusterInfoConfig.Builder();
    clusterInfoConfig.clusterId("testCluster");
    clusterInfoConfig.nodeCount(4);
    ManualClock clock = new ManualClock();
    MetricReceiver.MockReceiver metric = new MetricReceiver.MockReceiver();
    Chain<Searcher> chain = new Chain<Searcher>("test", new RateLimitingSearcher(new RateLimitingConfig(rateLimitingConfig), new ClusterInfoConfig(clusterInfoConfig), metric, clock), new CostSettingSearcher());
    assertEquals("'rate' request are available initially", 2, tryRequests(chain, "id1"));
    assertTrue("However, don't reject if we dryRun", executeWasAllowed(chain, "id1", true));
    // causes 2 new requests to become available
    clock.advance(Duration.ofMillis(1500));
    assertEquals("'rate' new requests became available", 2, tryRequests(chain, "id1"));
    assertEquals("Another id", 2, tryRequests(chain, "id2"));
    clock.advance(Duration.ofMillis(1000000));
    assertEquals("'maxAvailableCapacity' request became available", 4, tryRequests(chain, "id2"));
    assertFalse("If quota is set to 0, all requests are rejected, even initially", executeWasAllowed(chain, "id3", 0));
    clock.advance(Duration.ofMillis(1000000));
    assertTrue("A single query which costs more than capacity is allowed as cost is calculated after allowing it", executeWasAllowed(chain, "id1", 8, 8, false));
    assertFalse("capacity is -4: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertFalse("capacity is -2: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertFalse("capacity is 0: disallowing", executeWasAllowed(chain, "id1"));
    clock.advance(Duration.ofMillis(1000));
    assertTrue(executeWasAllowed(chain, "id1"));
    // check metrics
    Map<Point, UntypedMetric> map = metric.getSnapshot().getMapForMetric("requestsOverQuota");
    assertEquals(requestsToTry - 2 + 1 + requestsToTry - 2 + 3, map.get(metric.point("id", "id1")).getCount());
    assertEquals(requestsToTry - 2 + requestsToTry - 4, map.get(metric.point("id", "id2")).getCount());
}
Also used : Chain(com.yahoo.component.chain.Chain) MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) RateLimitingSearcher(com.yahoo.search.searchers.RateLimitingSearcher) Searcher(com.yahoo.search.Searcher) Point(com.yahoo.metrics.simple.Point) RateLimitingConfig(com.yahoo.search.config.RateLimitingConfig) RateLimitingSearcher(com.yahoo.search.searchers.RateLimitingSearcher) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric) ManualClock(com.yahoo.test.ManualClock) ClusterInfoConfig(com.yahoo.cloud.config.ClusterInfoConfig) Test(org.junit.Test)

Example 4 with UntypedMetric

use of com.yahoo.metrics.simple.UntypedMetric in project vespa by vespa-engine.

the class RateLimitingBenchmark method rejectedRequests.

private int rejectedRequests(int id) {
    Point context = metric.pointBuilder().set("id", toClientId(id)).build();
    UntypedMetric rejectedRequestsMetric = metricSnapshot.getMapForMetric("requestsOverQuota").get(context);
    if (rejectedRequestsMetric == null)
        return 0;
    return (int) rejectedRequestsMetric.getCount();
}
Also used : Point(com.yahoo.metrics.simple.Point) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric)

Aggregations

UntypedMetric (com.yahoo.metrics.simple.UntypedMetric)4 Point (com.yahoo.metrics.simple.Point)3 Identifier (com.yahoo.metrics.simple.Identifier)2 ClusterInfoConfig (com.yahoo.cloud.config.ClusterInfoConfig)1 Chain (com.yahoo.component.chain.Chain)1 MetricReceiver (com.yahoo.metrics.simple.MetricReceiver)1 Searcher (com.yahoo.search.Searcher)1 RateLimitingConfig (com.yahoo.search.config.RateLimitingConfig)1 RateLimitingSearcher (com.yahoo.search.searchers.RateLimitingSearcher)1 ManualClock (com.yahoo.test.ManualClock)1 DoubleHistogram (org.HdrHistogram.DoubleHistogram)1 Test (org.junit.Test)1