Search in sources :

Example 1 with VisitorStatistics

use of com.yahoo.vdslib.VisitorStatistics in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testMaxTotalHitsEarlyCompletion.

/**
 * Test visitor "prematurely" completing due to max total hits being
 * reached when no other visitors are currently pending.
 */
@Test
public void testMaxTotalHitsEarlyCompletion() {
    VisitorParameters visitorParameters = createVisitorParameters("id.user==1234");
    visitorParameters.setMaxTotalHits(10);
    ReplyModifier replyModifier1 = (reply) -> {
        VisitorStatistics stats = new VisitorStatistics();
        stats.setBucketsVisited(1);
        stats.setDocumentsReturned(9);
        reply.setVisitorStatistics(stats);
        reply.setLastBucket(new BucketId(33, 1234 | (1L << 32)));
    };
    ReplyModifier replyModifier2 = (reply) -> {
        VisitorStatistics stats = new VisitorStatistics();
        stats.setBucketsVisited(1);
        stats.setDocumentsReturned(1);
        reply.setVisitorStatistics(stats);
        reply.setLastBucket(new BucketId(34, 1234 | (1L << 33)));
    };
    doTestEarlyCompletion(visitorParameters, replyModifier1, replyModifier2);
}
Also used : java.util(java.util) CyclicBarrier(java.util.concurrent.CyclicBarrier) com.yahoo.documentapi(com.yahoo.documentapi) com.yahoo.messagebus(com.yahoo.messagebus) DocumentId(com.yahoo.document.DocumentId) ParseException(com.yahoo.document.select.parser.ParseException) com.yahoo.documentapi.messagebus.protocol(com.yahoo.documentapi.messagebus.protocol) Test(org.junit.Test) Callable(java.util.concurrent.Callable) MessageBusVisitorSession(com.yahoo.documentapi.messagebus.MessageBusVisitorSession) Result(com.yahoo.messagebus.Result) Error(com.yahoo.messagebus.Error) RoutingTable(com.yahoo.messagebus.routing.RoutingTable) TimeUnit(java.util.concurrent.TimeUnit) Route(com.yahoo.messagebus.routing.Route) RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Charset(java.nio.charset.Charset) VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType) Assert(org.junit.Assert) RouteSpec(com.yahoo.messagebus.routing.RouteSpec) BucketId(com.yahoo.document.BucketId) Assert.assertEquals(org.junit.Assert.assertEquals) VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) BucketId(com.yahoo.document.BucketId) Test(org.junit.Test)

Example 2 with VisitorStatistics

use of com.yahoo.vdslib.VisitorStatistics in project vespa by vespa-engine.

the class MetricsSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    long timeMs = System.currentTimeMillis();
    /**
     * Backwards compatibility - convert metricsearcher.id to streaming.loadtype
     */
    String metricName = query.properties().getString(metricsearcherId);
    if (metricName != null) {
        query.properties().set(streamingLoadtype, metricName);
    }
    Result result = execution.search(query);
    long latency = System.currentTimeMillis() - timeMs;
    metricName = query.properties().getString(streamingLoadtype);
    if (metricName == null) {
        return result;
    }
    synchronized (this) {
        Stats stats = statMap.get(metricName);
        if (stats == null) {
            stats = new Stats();
            statMap.put(metricName, stats);
        }
        stats.count++;
        stats.latency += latency;
        if (result.hits().getError() != null && !result.hits().getErrorHit().hasOnlyErrorCode(ErrorMessage.NULL_QUERY) && !result.hits().getErrorHit().hasOnlyErrorCode(3)) {
            stats.failed++;
        } else {
            stats.ok++;
        }
        VisitorStatistics visitorstats = null;
        final QueryContext queryContext = query.getContext(false);
        if (queryContext != null) {
            visitorstats = (VisitorStatistics) queryContext.getProperty(STREAMING_STATISTICS);
        }
        if (visitorstats != null) {
            stats.dataStreamed += visitorstats.getBytesVisited();
            stats.documentsStreamed += visitorstats.getDocumentsVisited();
        } else {
            log.fine("No visitor statistics set in query! - don't use metrics searcher without streaming search");
        }
        if ((timeMs - lastMetricLog) > 60000) {
            for (Map.Entry<String, Stats> entry : statMap.entrySet()) {
                stats = entry.getValue();
                Event.value(entry.getKey() + "_latency", stats.count > 0 ? (double) stats.latency / (double) stats.count : 0);
                Event.value(entry.getKey() + "_ok", stats.ok);
                Event.value(entry.getKey() + "_failed", stats.failed);
                Event.value(entry.getKey() + "_bytesstreamed", stats.dataStreamed);
                Event.value(entry.getKey() + "_documentsstreamed", stats.documentsStreamed);
                stats.latency = 0;
                stats.count = 0;
            }
            lastMetricLog = timeMs;
        }
    }
    return result;
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) QueryContext(com.yahoo.search.query.context.QueryContext) TreeMap(java.util.TreeMap) Map(java.util.Map) Result(com.yahoo.search.Result)

Example 3 with VisitorStatistics

use of com.yahoo.vdslib.VisitorStatistics in project vespa by vespa-engine.

the class VisitorControlHandlerTest method has_visited_any_buckets_is_false_if_zero_buckets_visited.

@Test
public void has_visited_any_buckets_is_false_if_zero_buckets_visited() {
    VisitorControlHandler handler = new VisitorControlHandler();
    VisitorStatistics stats = new VisitorStatistics();
    stats.setBucketsVisited(0);
    handler.onVisitorStatistics(stats);
    assertFalse(handler.hasVisitedAnyBuckets());
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) Test(org.junit.Test)

Example 4 with VisitorStatistics

use of com.yahoo.vdslib.VisitorStatistics in project vespa by vespa-engine.

the class VisitorControlHandlerTest method has_visited_any_buckets_is_true_if_more_than_zero_buckets_visited.

@Test
public void has_visited_any_buckets_is_true_if_more_than_zero_buckets_visited() {
    VisitorControlHandler handler = new VisitorControlHandler();
    VisitorStatistics stats = new VisitorStatistics();
    stats.setBucketsVisited(1);
    handler.onVisitorStatistics(stats);
    assertTrue(handler.hasVisitedAnyBuckets());
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) Test(org.junit.Test)

Example 5 with VisitorStatistics

use of com.yahoo.vdslib.VisitorStatistics in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testControlHandlerInvocationNormal.

@Test
public void testControlHandlerInvocationNormal() {
    MockComponents mc = createDefaultMock("id.user=1234");
    assertEquals("reset\nsetSession\n", mc.controlHandler.toString());
    mc.controlHandler.resetMock();
    mc.visitorSession.start();
    mc.executor.expectAndProcessTasks(1);
    replyToCreateVisitor(mc.sender, (reply) -> {
        reply.setLastBucket(ProgressToken.FINISHED_BUCKET);
        VisitorStatistics stats = new VisitorStatistics();
        stats.setBucketsVisited(11);
        stats.setDocumentsReturned(22);
        reply.setVisitorStatistics(stats);
    });
    mc.executor.expectAndProcessTasks(1);
    assertEquals("onProgress : 0 active, 0 pending, 1 finished, 1 total\n" + "onVisitorStatistics : 11 buckets visited, 22 docs returned\n" + "onDone : SUCCESS - ''\n", mc.controlHandler.toString());
    assertTrue(mc.visitorSession.isDone());
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) Test(org.junit.Test)

Aggregations

VisitorStatistics (com.yahoo.vdslib.VisitorStatistics)7 Test (org.junit.Test)6 BucketId (com.yahoo.document.BucketId)3 DocumentId (com.yahoo.document.DocumentId)3 ParseException (com.yahoo.document.select.parser.ParseException)3 com.yahoo.documentapi (com.yahoo.documentapi)3 MessageBusVisitorSession (com.yahoo.documentapi.messagebus.MessageBusVisitorSession)3 LoadType (com.yahoo.documentapi.messagebus.loadtypes.LoadType)3 com.yahoo.documentapi.messagebus.protocol (com.yahoo.documentapi.messagebus.protocol)3 com.yahoo.messagebus (com.yahoo.messagebus)3 Error (com.yahoo.messagebus.Error)3 Result (com.yahoo.messagebus.Result)3 Route (com.yahoo.messagebus.routing.Route)3 RouteSpec (com.yahoo.messagebus.routing.RouteSpec)3 RoutingTable (com.yahoo.messagebus.routing.RoutingTable)3 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)3 Charset (java.nio.charset.Charset)3 java.util (java.util)3 Callable (java.util.concurrent.Callable)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3