Fix HistogramAggregationSearchBenchmark.

This commit is contained in:
Adrien Grand 2014-01-17 22:29:27 +01:00
parent 8f659bccb1
commit 6159343c61
1 changed files with 22 additions and 23 deletions

View File

@ -16,6 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.elasticsearch.benchmark.search.aggregations; package org.elasticsearch.benchmark.search.aggregations;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
@ -32,6 +33,7 @@ import org.elasticsearch.node.Node;
import org.elasticsearch.search.facet.FacetBuilder; import org.elasticsearch.search.facet.FacetBuilder;
import java.util.Date; import java.util.Date;
import java.util.Random;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
@ -58,8 +60,8 @@ public class HistogramAggregationSearchBenchmark {
Settings settings = settingsBuilder() Settings settings = settingsBuilder()
.put("refresh_interval", "-1") .put("refresh_interval", "-1")
.put("gateway.type", "local") .put("gateway.type", "local")
.put(SETTING_NUMBER_OF_SHARDS, 2) .put(SETTING_NUMBER_OF_SHARDS, 1)
.put(SETTING_NUMBER_OF_REPLICAS, 1) .put(SETTING_NUMBER_OF_REPLICAS, 0)
.build(); .build();
String clusterName = HistogramAggregationSearchBenchmark.class.getSimpleName(); String clusterName = HistogramAggregationSearchBenchmark.class.getSimpleName();
@ -76,16 +78,14 @@ public class HistogramAggregationSearchBenchmark {
lValues[i] = i; lValues[i] = i;
} }
Thread.sleep(10000); Random r = new Random();
try { try {
client.admin().indices().prepareCreate("test") client.admin().indices().prepareCreate("test")
.setSettings(settingsBuilder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)) .setSettings(settingsBuilder().put(settings))
.addMapping("test", jsonBuilder() .addMapping("type1", jsonBuilder()
.startObject() .startObject()
.startObject("test") .startObject("type1")
.startObject("properties") .startObject("properties")
.startObject("name")
.startObject("fields")
.startObject("l_value") .startObject("l_value")
.field("type", "long") .field("type", "long")
.endObject() .endObject()
@ -100,8 +100,6 @@ public class HistogramAggregationSearchBenchmark {
.endObject() .endObject()
.endObject() .endObject()
.endObject() .endObject()
.endObject()
.endObject()
.endObject()) .endObject())
.execute().actionGet(); .execute().actionGet();
@ -115,7 +113,7 @@ public class HistogramAggregationSearchBenchmark {
BulkRequestBuilder request = client.prepareBulk(); BulkRequestBuilder request = client.prepareBulk();
for (int j = 0; j < BATCH; j++) { for (int j = 0; j < BATCH; j++) {
counter++; counter++;
final long value = lValues[counter % lValues.length]; final long value = lValues[r.nextInt(lValues.length)];
XContentBuilder source = jsonBuilder().startObject() XContentBuilder source = jsonBuilder().startObject()
.field("id", Integer.valueOf(counter)) .field("id", Integer.valueOf(counter))
.field("l_value", value) .field("l_value", value)
@ -136,6 +134,7 @@ public class HistogramAggregationSearchBenchmark {
stopWatch.start(); stopWatch.start();
} }
} }
client.admin().indices().prepareFlush("test").execute().actionGet();
System.out.println("--> Indexing took " + stopWatch.totalTime() + ", TPS " + (((double) (COUNT)) / stopWatch.totalTime().secondsFrac())); System.out.println("--> Indexing took " + stopWatch.totalTime() + ", TPS " + (((double) (COUNT)) / stopWatch.totalTime().secondsFrac()));
} catch (Exception e) { } catch (Exception e) {
System.out.println("--> Index already exists, ignoring indexing phase, waiting for green"); System.out.println("--> Index already exists, ignoring indexing phase, waiting for green");
@ -144,7 +143,6 @@ public class HistogramAggregationSearchBenchmark {
System.err.println("--> Timed out waiting for cluster health"); System.err.println("--> Timed out waiting for cluster health");
} }
} }
client.admin().indices().prepareRefresh().execute().actionGet();
if (client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() != COUNT) { if (client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() != COUNT) {
throw new Error(); throw new Error();
} }
@ -190,6 +188,7 @@ public class HistogramAggregationSearchBenchmark {
} }
System.out.println("--> Histogram Facet (" + field + ") " + (totalQueryTime / QUERY_COUNT) + "ms"); System.out.println("--> Histogram Facet (" + field + ") " + (totalQueryTime / QUERY_COUNT) + "ms");
totalQueryTime = 0;
for (int j = 0; j < QUERY_COUNT; j++) { for (int j = 0; j < QUERY_COUNT; j++) {
SearchResponse searchResponse = client.prepareSearch() SearchResponse searchResponse = client.prepareSearch()
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())