Skip to content

Commit

Permalink
add select benchmarks with high limits and offsets
Browse files Browse the repository at this point in the history
also change benchmark namespace
  • Loading branch information
seut committed Mar 26, 2015
1 parent 276a785 commit 44092ab
Show file tree
Hide file tree
Showing 17 changed files with 423 additions and 216 deletions.
4 changes: 2 additions & 2 deletions sql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test {
// force run, see: http://gradle.1045684.n5.nabble.com/how-does-gradle-decide-when-to-run-tests-td3314172.html
outputs.upToDateWhen { false }

exclude('io/crate/module/sql/benchmark/**')
exclude('io/crate/benchmark/**')

// allow to set the number of test forks from the CLI
if (project.hasProperty('testForks')) {
Expand Down Expand Up @@ -67,7 +67,7 @@ task bench(type: Test, dependsOn: [':app:getVersion']) {
systemProperty 'jub.charts.dir', benchmark_dir


include('io/crate/module/sql/benchmark/**')
include('io/crate/benchmark/**')

testLogging {
// show standard out and standard error of the test JVM(s) on the console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,34 @@
* software solely pursuant to the terms of the relevant commercial agreement.
*/

package io.crate.module.sql.benchmark;
package io.crate.benchmark;

import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

public class AddingTableColumnsBenchmark extends BenchmarkBase {

@Rule
public TestRule benchmarkRun = new BenchmarkRule();
public TestRule benchmarkRun = RuleChain.outerRule(new BenchmarkRule()).around(super.ruleChain);

private static boolean tablesCreated = false;

@Before
public void setUp() throws Exception {
if (!tablesCreated) {
if (NODE1 == null) {
NODE1 = cluster.startNode(getNodeSettings(1));
}
if (NODE2 == null) {
NODE2 = cluster.startNode(getNodeSettings(2));
}
@Override
protected String tableName() {
return "table_10";
}

createTable(10, "table_10");
createTable(5000, "table_5k");
@Override
protected void createTable() {
createTable(10, "table_10");
createTable(5000, "table_5k");
}

tablesCreated = true;
}
@Override
public boolean generateData() {
return true;
}

private void createTable(int columnsAmount, String tableName) {
Expand All @@ -71,7 +68,7 @@ private void createTable(int columnsAmount, String tableName) {
" population integer," +
" continent string" +
") clustered into 1 shards with (number_of_replicas=0)", new Object[0], false);

client().admin().cluster().prepareHealth(tableName).setWaitForGreenStatus().execute().actionGet();
}

@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* software solely pursuant to the terms of the relevant commercial agreement.
*/

package io.crate.module.sql.benchmark;
package io.crate.benchmark;

import io.crate.action.sql.SQLAction;
import io.crate.action.sql.SQLRequest;
Expand All @@ -30,8 +30,12 @@
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.IndexMissingException;
Expand All @@ -47,8 +51,12 @@
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static io.crate.test.integration.PathAccessor.bytesFromPath;
import static org.junit.Assert.assertFalse;


@RunWith(JUnit4.class)
Expand Down Expand Up @@ -76,13 +84,23 @@ public class BenchmarkBase {

private Random random = new Random(System.nanoTime());

public final ESLogger logger = Loggers.getLogger(getClass());

@Rule
public TestRule ruleChain = RuleChain.emptyRuleChain();

public SQLResponse execute(String stmt, Object[] args, boolean queryPlannerEnabled) {
return getClient(queryPlannerEnabled).execute(SQLAction.INSTANCE, new SQLRequest(stmt, args)).actionGet();
}

public SQLResponse execute(String stmt) {
return execute(stmt, SQLRequest.EMPTY_ARGS);
}

public SQLResponse execute(String stmt, Object[] args) {
return getClient(true).execute(SQLAction.INSTANCE, new SQLRequest(stmt, args)).actionGet();
}

@Before
public void setUp() throws Exception {
if (NODE1 == null) {
Expand All @@ -93,28 +111,11 @@ public void setUp() throws Exception {
}

if (!indexExists()) {
execute("create table \"" + INDEX_NAME + "\" (" +
" \"areaInSqKm\" float," +
" capital string," +
" continent string," +
" \"continentName\" string," +
" \"countryCode\" string," +
" \"countryName\" string," +
" north float," +
" east float," +
" south float," +
" west float," +
" \"fipsCode\" string," +
" \"currencyCode\" string," +
" languages string," +
" \"isoAlpha3\" string," +
" \"isoNumeric\" string," +
" population integer" +
") clustered into 2 shards with (number_of_replicas=0)", new Object[0], false);
client().admin().cluster().prepareHealth(INDEX_NAME).setWaitForGreenStatus().execute().actionGet();
refresh(client());
if (loadData()) {
doLoadData();
createTable();
if (importData()) {
doImportData();
} else if (generateData()) {
doGenerateData();
}

}
Expand All @@ -130,6 +131,73 @@ public static void tearDownClass() throws IOException {
cluster.afterTest();
}

protected void createTable() {
execute("create table \"" + INDEX_NAME + "\" (" +
" \"areaInSqKm\" float," +
" capital string," +
" continent string," +
" \"continentName\" string," +
" \"countryCode\" string," +
" \"countryName\" string," +
" north float," +
" east float," +
" south float," +
" west float," +
" \"fipsCode\" string," +
" \"currencyCode\" string," +
" languages string," +
" \"isoAlpha3\" string," +
" \"isoNumeric\" string," +
" population integer" +
") clustered into 2 shards with (number_of_replicas=0)", new Object[0], false);
client().admin().cluster().prepareHealth(INDEX_NAME).setWaitForGreenStatus().execute().actionGet();
}

protected void doGenerateData() throws Exception {
final String tableName = tableName();
final int numberOfDocuments = numberOfDocuments();
logger.info("generating {} documents...", numberOfDocuments);
ExecutorService executor = Executors.newFixedThreadPool(4);
for (int i=0; i<4; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
int numDocsToCreate = numberOfDocuments/4;
logger.info("Generating {} Documents in Thread {}", numDocsToCreate, Thread.currentThread().getName());
Client client = getClient(false);
BulkRequest bulkRequest = new BulkRequest();

for (int i=0; i < numDocsToCreate; i+=1000) {
bulkRequest.requests().clear();
try {
byte[] source = generateRowSource();
for (int j=0; j<1000;j++) {
IndexRequest indexRequest = new IndexRequest(tableName, "default", String.valueOf(i+j) + String.valueOf(Thread.currentThread().getId()));
indexRequest.source(source);
bulkRequest.add(indexRequest);
}
BulkResponse response = client.bulk(bulkRequest).actionGet();
assertFalse(response.hasFailures());
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
executor.shutdown();
executor.awaitTermination(2L, TimeUnit.MINUTES);
executor.shutdownNow();
getClient(true).admin().indices().prepareFlush(tableName).setFull(true).execute().actionGet();
getClient(false).admin().indices().prepareFlush(tableName).setFull(true).execute().actionGet();
refresh(client());
logger.info("{} documents generated.", numberOfDocuments);
}

protected byte[] generateRowSource() throws IOException {
return new byte[0];
}

protected Random getRandom() {
return random;
}
Expand All @@ -147,15 +215,31 @@ public boolean nodesStarted() {
}

public boolean indexExists() {
return getClient(false).admin().indices().exists(new IndicesExistsRequest(INDEX_NAME)).actionGet().isExists();
return getClient(false).admin().indices().exists(new IndicesExistsRequest(tableName())).actionGet().isExists();
}

public boolean importData() {
return false;
}

public boolean loadData() {
public boolean generateData() {
return false;
}

public void doLoadData() throws Exception {
loadBulk(DATA, false);
protected int numberOfDocuments() {
return 0;
}

protected String tableName() {
return INDEX_NAME;
}

protected String dataPath() {
return DATA;
}

public void doImportData() throws Exception {
loadBulk(false);
refresh(getClient(true));
refresh(getClient(false));
}
Expand Down Expand Up @@ -187,7 +271,8 @@ public Client getClient(boolean firstNode) {
return firstNode ? cluster.client(NODE1) : cluster.client(NODE2);
}

public void loadBulk(String path, boolean queryPlannerEnabled) throws Exception {
public void loadBulk(boolean queryPlannerEnabled) throws Exception {
String path = dataPath();
byte[] bulkPayload = bytesFromPath(path, this.getClass());
BulkResponse bulk = getClient(queryPlannerEnabled).prepareBulk().add(bulkPayload, 0, bulkPayload.length, false, null, null).execute().actionGet();
for (BulkItemResponse item : bulk.getItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* software solely pursuant to the terms of the relevant commercial agreement.
*/

package io.crate.module.sql.benchmark;
package io.crate.benchmark;


import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
Expand All @@ -37,12 +37,9 @@
import io.crate.metadata.ColumnIdent;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.Client;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
Expand All @@ -69,36 +66,22 @@ public class BulkDeleteBenchmark extends BenchmarkBase{
public static final String SINGLE_INSERT_SQL_STMT = "INSERT INTO users (id, name, age) Values (?, ?, ?)";
public static final String DELETE_SQL_STMT = "DELETE FROM users where id = ?";


@Before
public void setUp() throws Exception {
if (NODE1 == null) {
NODE1 = cluster.startNode(getNodeSettings(1));
}
if (NODE2 == null) {
NODE2 = cluster.startNode(getNodeSettings(2));
}
if(!indexExists()){
execute("create table users (" +
" id string primary key," +
" name string," +
" age integer" +
") clustered into 2 shards with (number_of_replicas=0)", new Object[0], false);
refresh(client());
}

}

@AfterClass
public static void afterClass() {
cluster.client().admin().indices().prepareDelete("users").execute().actionGet();
@Override
protected String tableName() {
return INDEX_NAME;
}

@Override
public boolean indexExists() {
return getClient(false).admin().indices().exists(new IndicesExistsRequest(INDEX_NAME)).actionGet().isExists();
protected void createTable() {
execute("create table users (" +
" id string primary key," +
" name string," +
" age integer" +
") clustered into 2 shards with (number_of_replicas=0)", new Object[0], false);
client().admin().cluster().prepareHealth(INDEX_NAME).setWaitForGreenStatus().execute().actionGet();
}


private HashMap<String, String> createSampleData() {
Object[][] bulkArgs = new Object[ROWS][];
HashMap<String, String> ids = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* software solely pursuant to the terms of the relevant commercial agreement.
*/

package io.crate.module.sql.benchmark;
package io.crate.benchmark;


import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
Expand Down
Loading

0 comments on commit 44092ab

Please sign in to comment.