Skip to content
Permalink
Browse files
Stabilizes function benchmarks (#101)
* New LongRange object for managing ranges of longs.
* Only get 1 value.
* Balanced CPU utilization and threads.
  • Loading branch information
pivotal-jbarrett committed Aug 27, 2019
1 parent 439b857 commit e45a12f024886bffeed42cec7c77f3a997d9e8d2
Showing 49 changed files with 538 additions and 371 deletions.
@@ -62,7 +62,6 @@ task benchmark(type: Test) {
testLogging { exceptionFormat = 'full' }

exclude "**/Replicated*QueryBenchmark.class"
exclude "**/ReplicatedFunctionExecution*Benchmark.class"
exclude "**/PartitionedNonIndexedQueryBenchmark.class"
exclude "**/*PutAllBenchmark.class"

@@ -12,44 +12,34 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package benchmark.geode.data;

import java.util.ArrayList;
import java.util.List;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;

public class BenchmarkFunction implements Function {
private long maxKey;
private long minKey;
public class BenchmarkFunction implements Function<Void> {
private final LongRange range;

public BenchmarkFunction(long minKey, long maxKey) {
this.maxKey = maxKey;
this.minKey = minKey;
public BenchmarkFunction(final LongRange range) {
this.range = range;
}

@Override
public void execute(FunctionContext context) {
RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
Region region = regionFunctionContext.getDataSet();
List<Long> results = new ArrayList<>();

for (long i = minKey; i <= maxKey; i++) {
Portfolio portfolio = (Portfolio) region.get(i);
if (portfolio != null) {
results.add(portfolio.getID());
}
}

context.getResultSender().lastResult(results);
public void execute(final FunctionContext<Void> context) {
final RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
final Region<Long, Portfolio> region = regionFunctionContext.getDataSet();
final Long key = range.random();
context.getResultSender().lastResult(region.get(key));
}

@Override
public String getId() {
return "BenchmarkFunction";
return BenchmarkFunction.class.getName();
}

@Override
@@ -14,39 +14,22 @@
*/
package benchmark.geode.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;

public class FunctionWithArguments implements Function {
private long maxKey;
private long minKey;

public FunctionWithArguments() {}

@Override
public void execute(FunctionContext context) {
RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
Region region = regionFunctionContext.getDataSet();
HashMap<String, Long> argumentsMap =
(HashMap<String, Long>) regionFunctionContext.getArguments();
maxKey = argumentsMap.get("maxID");
minKey = argumentsMap.get("minID");
List<Long> results = new ArrayList<>();

for (long i = minKey; i <= maxKey; i++) {
Portfolio portfolio = (Portfolio) region.get(i);
if (portfolio != null) {
results.add(portfolio.getID());
}
}

context.getResultSender().lastResult(results);
public void execute(final FunctionContext context) {
final RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
final Region region = regionFunctionContext.getDataSet();
final Long key = (Long) regionFunctionContext.getArguments();
context.getResultSender().lastResult(region.get(key));
}

@Override
@@ -14,8 +14,6 @@
*/
package benchmark.geode.data;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.geode.cache.Region;
@@ -28,20 +26,14 @@ public class FunctionWithFilter implements Function {
public FunctionWithFilter() {}

@Override
public void execute(FunctionContext context) {
RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
Region region = regionFunctionContext.getDataSet();
Set filterKeys = regionFunctionContext.getFilter();
List<Long> results = new ArrayList<>();

filterKeys.stream().forEach(key -> {
Portfolio portfolio = (Portfolio) region.get(key);
if (portfolio != null) {
results.add(portfolio.getID());
}
});

context.getResultSender().lastResult(results);
public void execute(final FunctionContext context) {
final RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context;
final Region<Long, Portfolio> region = regionFunctionContext.getDataSet();
@SuppressWarnings("unchecked")
final Set<Long> filterKeys = (Set<Long>) regionFunctionContext.getFilter();
final Long key = filterKeys.iterator().next();

context.getResultSender().lastResult(region.get(key));
}

@Override
@@ -15,38 +15,31 @@
package org.apache.geode.benchmark.tasks;

import java.io.Serializable;
import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

import benchmark.geode.data.FunctionWithFilter;
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.execute.Function;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.perftest.jvms.RemoteJVMFactory;

public class ExecuteFilteredFunction extends BenchmarkDriverAdapter implements Serializable {

private final LongRange keyRange;
private final Function function;

private Region region;
long keyRange;
long filterRange;
private Function function;
private static final Logger logger = LoggerFactory.getLogger(RemoteJVMFactory.class);

public ExecuteFilteredFunction(long keyRange, long filterRange) {
public ExecuteFilteredFunction(final LongRange keyRange) {
this.keyRange = keyRange;
this.filterRange = filterRange;
this.function = new FunctionWithFilter();
}

@@ -59,33 +52,15 @@ public void setUp(BenchmarkConfiguration cfg) throws Exception {
}

@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
long minId = ThreadLocalRandom.current().nextLong(0, this.keyRange - filterRange);
long maxId = minId + filterRange;
Set<Long> filterSet = new HashSet<>();
for (long i = minId; i <= maxId; i++) {
filterSet.add(i);
}
ResultCollector resultCollector = FunctionService
public boolean test(Map<Object, Object> ctx) {
final Set<Long> filterSet = Collections.singleton(keyRange.random());
final ResultCollector resultCollector = FunctionService
.onRegion(region)
.withFilter(filterSet)
.execute(function);
List results = (List) resultCollector.getResult();
validateResults(results, minId, maxId);
resultCollector.getResult();
return true;

}

private void validateResults(List results, long minId, long maxId)
throws UnexpectedException {
for (Object result : results) {
ArrayList<Long> IDs = (ArrayList<Long>) result;
for (Long id : IDs) {
if (id < minId || id > maxId) {
throw new UnexpectedException("Invalid ID value received [minID = " + minId + " maxID = "
+ maxId + " ] Portfolio ID received = " + id);
}
}
}
}
}
@@ -15,11 +15,7 @@
package org.apache.geode.benchmark.tasks;

import java.io.Serializable;
import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import benchmark.geode.data.BenchmarkFunction;
import org.yardstickframework.BenchmarkConfiguration;
@@ -28,19 +24,13 @@
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.execute.Function;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;

public class ExecuteFunction extends BenchmarkDriverAdapter implements Serializable {

private Region region;
long keyRange;
long functionIDRange;

public ExecuteFunction(long keyRange, long functionIDRange) {
this.keyRange = keyRange;
this.functionIDRange = functionIDRange;
}
public ExecuteFunction() {}

@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
@@ -50,26 +40,9 @@ public void setUp(BenchmarkConfiguration cfg) throws Exception {
}

@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
long minId = ThreadLocalRandom.current().nextLong(0, this.keyRange - functionIDRange);
long maxId = minId + functionIDRange;
Function function = new BenchmarkFunction(minId, maxId);
FunctionService.registerFunction(function);
ResultCollector resultCollector = FunctionService.onRegion(region).execute(function);
List results = (List) resultCollector.getResult();
validateResults(results, minId, maxId);
public boolean test(final Map<Object, Object> ctx) {
FunctionService.onRegion(region).execute(BenchmarkFunction.class.getName()).getResult();
return true;
}

private void validateResults(List results, long minId, long maxId) throws UnexpectedException {
for (Object result : results) {
ArrayList<Long> IDs = (ArrayList<Long>) result;
for (Long id : IDs) {
if (id < minId || id > maxId) {
throw new UnexpectedException("Invalid ID values received [min ID=" + minId + ",max ID="
+ maxId + "] Portfolio ID received=" + id);
}
}
}
}
}
@@ -15,17 +15,13 @@
package org.apache.geode.benchmark.tasks;

import java.io.Serializable;
import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import benchmark.geode.data.FunctionWithArguments;
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;
@@ -35,15 +31,14 @@

public class ExecuteParameterizedFunction extends BenchmarkDriverAdapter implements Serializable {

private final LongRange keyRange;
private final Function function;

private Region region;
long keyRange;
long functionIDRange;
private Function function;

public ExecuteParameterizedFunction(long keyRange, long functionIDRange) {
public ExecuteParameterizedFunction(final LongRange keyRange) {
this.keyRange = keyRange;
this.functionIDRange = functionIDRange;
this.function = new FunctionWithArguments();
function = new FunctionWithArguments();
}

@Override
@@ -55,32 +50,13 @@ public void setUp(BenchmarkConfiguration cfg) throws Exception {
}

@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
long minId = ThreadLocalRandom.current().nextLong(0, this.keyRange - functionIDRange);
long maxId = minId + functionIDRange;
Map<String, Long> argumentMap = new HashMap<>();
argumentMap.put("maxID", maxId);
argumentMap.put("minID", minId);
public boolean test(Map<Object, Object> ctx) {
ResultCollector resultCollector = FunctionService
.onRegion(region)
.setArguments(argumentMap)
.setArguments(keyRange.random())
.execute(function);
List results = (List) resultCollector.getResult();
validateResults(results, minId, maxId);
resultCollector.getResult();
return true;

}

private void validateResults(List results, long minId, long maxId)
throws UnexpectedException {
for (Object result : results) {
ArrayList<Long> IDs = (ArrayList<Long>) result;
for (Long id : IDs) {
if (id < minId || id > maxId) {
throw new UnexpectedException("Invalid ID value received [minID= " + minId
+ " maxID= " + maxId + " ] Portfolio ID received = " + id);
}
}
}
}
}

0 comments on commit e45a12f

Please sign in to comment.