Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added benchmarks for aggregate functions. #115

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.benchmark.tasks;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yardstickframework.BenchmarkConfiguration;
import org.yardstickframework.BenchmarkDriverAdapter;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.query.Query;
import org.apache.geode.cache.query.SelectResults;
import org.apache.geode.perftest.jvms.RemoteJVMFactory;

public class AggregateOQLQuery extends BenchmarkDriverAdapter implements Serializable {

public static class QueryTypes {
public static final String SUM = "SUM(";
public static final String SUM_DISTINCT = "SUM(DISTINCT ";
public static final String AVG = "AVG(";
public static final String AVG_DISTINCT = "AVG(DISTINCT ";
public static final String COUNT = "COUNT(";
public static final String COUNT_DISTINCT = "COUNT(DISTINCT ";
public static final String MAX = "MAX(";
public static final String MIN = "MIN(";
}

private static final Logger logger = LoggerFactory.getLogger(RemoteJVMFactory.class);
private Region<Object, Object> region;
private LongRange keyRange;
private long queryRange;
private String type;
ClientCache cache;
private Query query;

public AggregateOQLQuery(LongRange keyRange, long queryRange, String type) {
this.keyRange = keyRange;
this.queryRange = queryRange;
this.type = type;
}

@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
super.setUp(cfg);
cache = ClientCacheFactory.getAnyInstance();
region = cache.getRegion("region");
query = cache.getQueryService()
.newQuery("SELECT " + type + "r.ID) FROM /region r WHERE r.ID >= $1 AND r.ID <= $2");
}

@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
long minId =
ThreadLocalRandom.current().nextLong(keyRange.getMin(), keyRange.getMax() - queryRange);
long maxId = minId + queryRange;

SelectResults results = executeQuery(minId, maxId);
verifyResults(results, minId, maxId);

return true;
}

private void verifyResults(SelectResults results, long minId, long maxId) throws Exception {
switch (type) {
case QueryTypes.SUM:
case QueryTypes.SUM_DISTINCT:
long sum = (int) results.asList().get(0);
long expectedSum = (maxId + minId) * (maxId - minId + 1) / 2;
if (sum != expectedSum) {
throw new Exception(
"Incorrect query result. Expected sum was " + expectedSum + ", actual sum was " + sum
+ ". min =" + minId + " max =" + maxId + " range =" + queryRange);
}
break;
case QueryTypes.AVG:
case QueryTypes.AVG_DISTINCT:
long avg = (int) results.asList().get(0);
long expectedAvg = (maxId + minId) * (maxId - minId + 1) / ((queryRange + 1) * 2);
if (avg != expectedAvg) {
throw new Exception(
"Incorrect query result. Expected average was " + expectedAvg
+ ", actual average was "
+ avg + ". min =" + minId + " max =" + maxId + " range =" + queryRange);
}
break;
case QueryTypes.COUNT:
case QueryTypes.COUNT_DISTINCT:
long count = (int) results.asList().get(0);
if (count != queryRange + 1) {
throw new Exception(
"Incorrect query result. Expected count was " + queryRange + ", actual count was "
+ count + ". min =" + minId + " max =" + maxId + " range =" + queryRange);
}
break;
case QueryTypes.MAX:
long max = (long) results.asList().get(0);
if (max != maxId) {
throw new Exception(
"Incorrect query result. Expected max was " + maxId + ", actual max was " + max
+ ". min =" + minId + " max =" + maxId + " range =" + queryRange);
}
break;
case QueryTypes.MIN:
long min = (long) results.asList().get(0);
if (min != minId) {
throw new Exception(
"Incorrect query result. Expected min was " + minId + ", actual min was " + min
+ ". min =" + minId + " max =" + maxId + " range =" + queryRange);
}
break;
default:
throw new Exception("Unsupported aggregate query type: " + type);
}
}

private SelectResults executeQuery(long minId, long maxId) throws Exception {
return (SelectResults) query.execute(minId, maxId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.benchmark.tests;

import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreatePartitionedRegion;
import org.apache.geode.benchmark.tasks.PrePopulateRegion;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;

abstract class AbstractPartitionedQueryBenchmark implements PerformanceTest {
private LongRange keyRange = new LongRange(0, 500000);
private long queryRange = 100;

public final void setKeyRange(LongRange keyRange) {
this.keyRange = keyRange;
}

public final LongRange getKeyRange() {
return keyRange;
}

public long getQueryRange() {
return queryRange;
}

public void setQueryRange(long queryRange) {
this.queryRange = queryRange;
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
config.threads(Runtime.getRuntime().availableProcessors() * 8);
ClientServerTopology.configure(config);
config.before(new CreatePartitionedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegion(keyRange), CLIENT);
return config;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.benchmark.tests;

import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreateReplicatedRegion;
import org.apache.geode.benchmark.tasks.PrePopulateRegion;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;

abstract class AbstractReplicatedQueryBenchmark implements PerformanceTest {
private LongRange keyRange = new LongRange(0, 500000);
private long queryRange = 100;

public final void setKeyRange(LongRange keyRange) {
this.keyRange = keyRange;
}

public final LongRange getKeyRange() {
return keyRange;
}

public long getQueryRange() {
return queryRange;
}

public void setQueryRange(long queryRange) {
this.queryRange = queryRange;
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
config.threads(Runtime.getRuntime().availableProcessors() * 8);
ClientServerTopology.configure(config);
config.before(new CreateReplicatedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegion(keyRange), CLIENT);
return config;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.benchmark.tests;

import static org.apache.geode.benchmark.tasks.AggregateOQLQuery.QueryTypes.AVG;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.tasks.AggregateOQLQuery;
import org.apache.geode.benchmark.tasks.CreateIndexOnID;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

public class PartitionedIndexedAggregateQueryAvgBenchmark
extends AbstractPartitionedQueryBenchmark {

public PartitionedIndexedAggregateQueryAvgBenchmark() {}

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

@Override
public TestConfig configure() {
TestConfig config = super.configure();
config.threads(Runtime.getRuntime().availableProcessors() * 1);
config.before(new CreateIndexOnID(), SERVER);
config.workload(new AggregateOQLQuery(getKeyRange(), 1000, AVG), CLIENT);
return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.benchmark.tests;

import static org.apache.geode.benchmark.tasks.AggregateOQLQuery.QueryTypes.AVG_DISTINCT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.tasks.AggregateOQLQuery;
import org.apache.geode.benchmark.tasks.CreateIndexOnID;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

public class PartitionedIndexedAggregateQueryAvgDistinctBenchmark
extends AbstractPartitionedQueryBenchmark {

public PartitionedIndexedAggregateQueryAvgDistinctBenchmark() {}

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

@Override
public TestConfig configure() {
TestConfig config = super.configure();
config.threads(Runtime.getRuntime().availableProcessors() * 1);
config.before(new CreateIndexOnID(), SERVER);
config.workload(new AggregateOQLQuery(getKeyRange(), getQueryRange(), AVG_DISTINCT), CLIENT);
return config;
}
}
Loading