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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations