Skip to content
Permalink
Browse files
GEODE-6332: Add function execution benchmarks (#51)
  • Loading branch information
nabarunnag committed Feb 8, 2019
1 parent feab250 commit 8d181bbb3c4264c22a6b6aac43c97585cc10c618
Show file tree
Hide file tree
Showing 20 changed files with 1,053 additions and 1 deletion.
@@ -0,0 +1,59 @@
/*
* 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 benchmark.geode.data;

import java.util.ArrayList;
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 BenchmarkFunction implements Function {
private long maxKey;
private long minKey;

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

@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);
}

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

@Override
public boolean isHA() {
return false;
}
}
@@ -0,0 +1,61 @@
/*
* 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 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);
}

@Override
public String getId() {
return "FunctionWithArguments";
}

@Override
public boolean isHA() {
return true;
}
}
@@ -0,0 +1,56 @@
/*
* 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 benchmark.geode.data;

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

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 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);
}

@Override
public String getId() {
return "FunctionWithFilter";
}

@Override
public boolean isHA() {
return true;
}
}
@@ -36,6 +36,8 @@ public static Properties serverProperties() {
properties.setProperty(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, "0");
properties.setProperty(ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION, "false");
properties.setProperty(ConfigurationProperties.USE_CLUSTER_CONFIGURATION, "false");
properties.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"benchmark.geode.data.**");
return properties;
}

@@ -0,0 +1,91 @@
/*
* 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.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
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.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 Region region;
long keyRange;
long filterRange;
private Function function;
private static final Logger logger = LoggerFactory.getLogger(RemoteJVMFactory.class);

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

@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
super.setUp(cfg);
ClientCache cache = ClientCacheFactory.getAnyInstance();
region = cache.getRegion("region");
FunctionService.registerFunction(function);
}

@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
.onRegion(region)
.withFilter(filterSet)
.execute(function);
List results = (List) resultCollector.getResult();
validateResults(results, minId, maxId);
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,0 +1,75 @@
/*
* 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.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;
import org.yardstickframework.BenchmarkDriverAdapter;

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;
}

@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
super.setUp(cfg);
ClientCache cache = ClientCacheFactory.getAnyInstance();
region = cache.getRegion("region");
}

@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);
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);
}
}
}
}
}

0 comments on commit 8d181bb

Please sign in to comment.