Adding support for running jmh benchmarks to gradle and adding a CompactRangeIndexBenchmark.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/45513045 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/45513045 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/45513045 Branch: refs/heads/feature/GEODE-1985 Commit: 45513045c14751688129d5635963c157f5886832 Parents: d6afb70 Author: Dan Smith <[email protected]> Authored: Wed Oct 19 10:16:31 2016 -0700 Committer: Dan Smith <[email protected]> Committed: Mon Oct 24 11:12:48 2016 -0700 ---------------------------------------------------------------------- build.gradle | 2 + .../index/CompactRangeIndexBenchmark.java | 105 +++++++++++++++++++ gradle/jmh.gradle | 6 ++ 3 files changed, 113 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/45513045/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index a734e05..0472064 100755 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ buildscript { classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1' classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1' classpath "com.diffplug.gradle.spotless:spotless:2.2.0" + classpath "me.champeau.gradle:jmh-gradle-plugin:0.3.1" } } @@ -81,6 +82,7 @@ apply from: "${scriptDir}/code-analysis.gradle" apply from: "${scriptDir}/sonar.gradle" apply from: "${scriptDir}/ide.gradle" apply from: "${scriptDir}/rat.gradle" +apply from: "${scriptDir}/jmh.gradle" subprojects { // Make sure clean task for rootProject runs last http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/45513045/geode-core/src/jmh/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexBenchmark.java ---------------------------------------------------------------------- diff --git a/geode-core/src/jmh/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexBenchmark.java b/geode-core/src/jmh/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexBenchmark.java new file mode 100644 index 0000000..545353d --- /dev/null +++ b/geode-core/src/jmh/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexBenchmark.java @@ -0,0 +1,105 @@ +/* + * 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.cache.query.internal.index; + +import static org.junit.Assert.assertEquals; + +import java.util.List; +import java.util.stream.IntStream; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; +import org.apache.geode.cache.query.FunctionDomainException; +import org.apache.geode.cache.query.IndexExistsException; +import org.apache.geode.cache.query.IndexNameConflictException; +import org.apache.geode.cache.query.NameResolutionException; +import org.apache.geode.cache.query.Query; +import org.apache.geode.cache.query.QueryInvocationTargetException; +import org.apache.geode.cache.query.RegionNotFoundException; +import org.apache.geode.cache.query.SelectResults; +import org.apache.geode.cache.query.TypeMismatchException; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +@Fork(3) +public class CompactRangeIndexBenchmark { + + @State(Scope.Benchmark) + public static class CacheState { + private Region region; + private Query query; + + public CacheState() {} + + @Setup + public void setup() { + Cache cache = new CacheFactory().set("mcast-port", "0").set("locators", "").create(); + + region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("region"); + try { + AbstractIndex index = + (AbstractIndex) cache.getQueryService().createIndex("Status", "id", "/region"); + + IntStream.range(0, 10000).forEach(i -> region.put(i, new Value(i))); + query = cache.getQueryService().newQuery("select * from /region where id > 0"); + + // Do the query once to make sure it's actually returning results + // And using the index + SelectResults results = query(); + assertEquals(9999, results.size()); + assertEquals(1, index.getStatistics().getTotalUses()); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + public SelectResults query() throws NameResolutionException, TypeMismatchException, + QueryInvocationTargetException, FunctionDomainException { + return (SelectResults) query.execute(); + } + } + + @Benchmark + @Warmup(iterations = 20) + @Measurement(iterations = 20) + public Object indexedQuery(CacheState state) throws NameResolutionException, + TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { + return state.query(); + } + + + + public static class Value { + protected final int id; + public final String status; + + public Value(int id) { + this.id = id; + this.status = id % 2 == 0 ? "active" : "inactive"; + } + + public int getId() { + return id; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/45513045/gradle/jmh.gradle ---------------------------------------------------------------------- diff --git a/gradle/jmh.gradle b/gradle/jmh.gradle new file mode 100644 index 0000000..abf3562 --- /dev/null +++ b/gradle/jmh.gradle @@ -0,0 +1,6 @@ +subprojects { + apply plugin: "me.champeau.gradle.jmh" + jmh { + duplicateClassesStrategy = 'warn' + } +}
