Search in sources :

Example 1 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult in project elasticsearch by elastic.

the class QueryProfilerTests method testBasic.

public void testBasic() throws IOException {
    QueryProfiler profiler = new QueryProfiler();
    searcher.setProfiler(profiler);
    Query query = new TermQuery(new Term("foo", "bar"));
    searcher.search(query, 1);
    List<ProfileResult> results = profiler.getTree();
    assertEquals(1, results.size());
    Map<String, Long> breakdown = results.get(0).getTimeBreakdown();
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString() + "_count").longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString() + "_count").longValue(), equalTo(0L));
    long rewriteTime = profiler.getRewriteTime();
    assertThat(rewriteTime, greaterThan(0L));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) TermQuery(org.apache.lucene.search.TermQuery) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Term(org.apache.lucene.index.Term)

Example 2 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult in project elasticsearch by elastic.

the class QueryProfilerTests method testApproximations.

public void testApproximations() throws IOException {
    QueryProfiler profiler = new QueryProfiler();
    Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader));
    // disable query caching since we want to test approximations, which won't
    // be exposed on a cached entry
    ContextIndexSearcher searcher = new ContextIndexSearcher(engineSearcher, null, MAYBE_CACHE_POLICY);
    searcher.setProfiler(profiler);
    Query query = new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random());
    searcher.count(query);
    List<ProfileResult> results = profiler.getTree();
    assertEquals(1, results.size());
    Map<String, Long> breakdown = results.get(0).getTimeBreakdown();
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString()).longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString() + "_count").longValue(), greaterThan(0L));
    assertThat(breakdown.get(QueryTimingType.ADVANCE.toString() + "_count").longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.SCORE.toString() + "_count").longValue(), equalTo(0L));
    assertThat(breakdown.get(QueryTimingType.MATCH.toString() + "_count").longValue(), greaterThan(0L));
    long rewriteTime = profiler.getRewriteTime();
    assertThat(rewriteTime, greaterThan(0L));
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) TermQuery(org.apache.lucene.search.TermQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) Term(org.apache.lucene.index.Term) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Engine(org.elasticsearch.index.engine.Engine)

Example 3 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult in project elasticsearch by elastic.

the class AggregationProfileShardResultTests method testToXContent.

public void testToXContent() throws IOException {
    List<ProfileResult> profileResults = new ArrayList<>();
    Map<String, Long> timings = new HashMap<>();
    timings.put("timing1", 2000L);
    timings.put("timing2", 4000L);
    ProfileResult profileResult = new ProfileResult("someType", "someDescription", timings, Collections.emptyList());
    profileResults.add(profileResult);
    AggregationProfileShardResult aggProfileResults = new AggregationProfileShardResult(profileResults);
    BytesReference xContent = toXContent(aggProfileResults, XContentType.JSON, false);
    assertEquals("{\"aggregations\":[" + "{\"type\":\"someType\"," + "\"description\":\"someDescription\"," + "\"time_in_nanos\":6000," + "\"breakdown\":{\"timing1\":2000,\"timing2\":4000}" + "}" + "]}", xContent.utf8ToString());
    xContent = toXContent(aggProfileResults, XContentType.JSON, true);
    assertEquals("{\"aggregations\":[" + "{\"type\":\"someType\"," + "\"description\":\"someDescription\"," + "\"time\":\"6micros\"," + "\"time_in_nanos\":6000," + "\"breakdown\":{\"timing1\":2000,\"timing2\":4000}" + "}" + "]}", xContent.utf8ToString());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) ProfileResult(org.elasticsearch.search.profile.ProfileResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 4 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testSimpleProfile.

public void testSimpleProfile() {
    SearchResponse response = client().prepareSearch("idx").setProfile(true).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L)).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(getNumShards("idx").numPrimaries));
    for (ProfileShardResult profileShardResult : profileResults.values()) {
        assertThat(profileShardResult, notNullValue());
        AggregationProfileShardResult aggProfileResults = profileShardResult.getAggregationProfileResults();
        assertThat(aggProfileResults, notNullValue());
        List<ProfileResult> aggProfileResultsList = aggProfileResults.getProfileResults();
        assertThat(aggProfileResultsList, notNullValue());
        assertThat(aggProfileResultsList.size(), equalTo(1));
        ProfileResult histoAggResult = aggProfileResultsList.get(0);
        assertThat(histoAggResult, notNullValue());
        assertThat(histoAggResult.getQueryName(), equalTo("org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator"));
        assertThat(histoAggResult.getLuceneDescription(), equalTo("histo"));
        assertThat(histoAggResult.getProfiledChildren().size(), equalTo(0));
        assertThat(histoAggResult.getTime(), greaterThan(0L));
        Map<String, Long> breakdown = histoAggResult.getTimeBreakdown();
        assertThat(breakdown, notNullValue());
        assertThat(breakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
    }
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) ProfileResult(org.elasticsearch.search.profile.ProfileResult) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 5 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testMultiLevelProfileBreadthFirst.

public void testMultiLevelProfileBreadthFirst() {
    SearchResponse response = client().prepareSearch("idx").setProfile(true).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L).subAggregation(terms("terms").collectMode(SubAggCollectionMode.BREADTH_FIRST).field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)))).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(getNumShards("idx").numPrimaries));
    for (ProfileShardResult profileShardResult : profileResults.values()) {
        assertThat(profileShardResult, notNullValue());
        AggregationProfileShardResult aggProfileResults = profileShardResult.getAggregationProfileResults();
        assertThat(aggProfileResults, notNullValue());
        List<ProfileResult> aggProfileResultsList = aggProfileResults.getProfileResults();
        assertThat(aggProfileResultsList, notNullValue());
        assertThat(aggProfileResultsList.size(), equalTo(1));
        ProfileResult histoAggResult = aggProfileResultsList.get(0);
        assertThat(histoAggResult, notNullValue());
        assertThat(histoAggResult.getQueryName(), equalTo("org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator"));
        assertThat(histoAggResult.getLuceneDescription(), equalTo("histo"));
        assertThat(histoAggResult.getTime(), greaterThan(0L));
        Map<String, Long> histoBreakdown = histoAggResult.getTimeBreakdown();
        assertThat(histoBreakdown, notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(histoAggResult.getProfiledChildren().size(), equalTo(1));
        ProfileResult termsAggResult = histoAggResult.getProfiledChildren().get(0);
        assertThat(termsAggResult, notNullValue());
        assertThat(termsAggResult.getQueryName(), equalTo(GlobalOrdinalsStringTermsAggregator.WithHash.class.getName()));
        assertThat(termsAggResult.getLuceneDescription(), equalTo("terms"));
        assertThat(termsAggResult.getTime(), greaterThan(0L));
        Map<String, Long> termsBreakdown = termsAggResult.getTimeBreakdown();
        assertThat(termsBreakdown, notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(termsAggResult.getProfiledChildren().size(), equalTo(1));
        ProfileResult avgAggResult = termsAggResult.getProfiledChildren().get(0);
        assertThat(avgAggResult, notNullValue());
        assertThat(avgAggResult.getQueryName(), equalTo(AvgAggregator.class.getName()));
        assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
        assertThat(avgAggResult.getTime(), greaterThan(0L));
        Map<String, Long> avgBreakdown = termsAggResult.getTimeBreakdown();
        assertThat(avgBreakdown, notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
    }
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) ProfileResult(org.elasticsearch.search.profile.ProfileResult) GlobalOrdinalsStringTermsAggregator(org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Aggregations

ProfileResult (org.elasticsearch.search.profile.ProfileResult)22 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ProfileShardResult (org.elasticsearch.search.profile.ProfileShardResult)14 Map (java.util.Map)9 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)9 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)9 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)9 RandomQueryGenerator.randomQueryBuilder (org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder)9 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)9 AggregationProfileShardResult (org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)5 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 Term (org.apache.lucene.index.Term)4 Query (org.apache.lucene.search.Query)4 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4 GlobalOrdinalsStringTermsAggregator (org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)1