Added cache GET benchmark.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e2be94e6 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e2be94e6 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e2be94e6 Branch: refs/heads/ignite-1786 Commit: e2be94e62aecddeb7bf3409450a5a95a314ba186 Parents: afd3bc1 Author: vozerov-gridgain <[email protected]> Authored: Thu Feb 4 15:31:18 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Feb 4 15:31:18 2016 +0300 ---------------------------------------------------------------------- .../jmh/cache/JmhCacheAbstractBenchmark.java | 3 + .../benchmarks/jmh/cache/JmhCacheBenchmark.java | 145 +++++++++++++++++++ .../jmh/cache/JmhCachePutBenchmark.java | 124 ---------------- .../jmh/runner/JmhIdeBenchmarkRunner.java | 20 ++- 4 files changed, 160 insertions(+), 132 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e2be94e6/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java index e8829bb..709ab77 100644 --- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java +++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java @@ -58,6 +58,9 @@ public class JmhCacheAbstractBenchmark extends JmhAbstractBenchmark { /** Default amount of nodes. */ protected static final int DFLT_DATA_NODES = 1; + /** Items count. */ + protected static final int CNT = 100000; + /** IP finder shared across nodes. */ private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); http://git-wip-us.apache.org/repos/asf/ignite/blob/e2be94e6/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheBenchmark.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheBenchmark.java new file mode 100644 index 0000000..f55d16c --- /dev/null +++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheBenchmark.java @@ -0,0 +1,145 @@ +/* + * 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.ignite.internal.benchmarks.jmh.cache; + +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner; +import org.apache.ignite.internal.benchmarks.model.IntValue; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.profile.GCProfiler; + +import java.util.concurrent.ThreadLocalRandom; + +/** + * Put benchmark. + */ +@SuppressWarnings("unchecked") +public class JmhCacheBenchmark extends JmhCacheAbstractBenchmark { + /** + * Set up routine. + * + * @throws Exception If failed. + */ + + public void setup() throws Exception { + super.setup(); + + IgniteDataStreamer<Integer, IntValue> dataLdr = node.dataStreamer(cache.getName()); + + for (int i = 0; i < CNT; i++) + dataLdr.addData(i, new IntValue(i)); + + dataLdr.close(); + + System.out.println("Cache populated."); + } + + /** + * Test PUT operation. + * + * @throws Exception If failed. + */ + @Benchmark + public void put() throws Exception { + int key = ThreadLocalRandom.current().nextInt(CNT); + + cache.put(key, new IntValue(key)); + } + + /** + * Test PUT operation. + * + * @throws Exception If failed. + */ + @Benchmark + public Object get() throws Exception { + int key = ThreadLocalRandom.current().nextInt(CNT); + + return cache.get(key); + } + + /** + * Run benchmarks. + * + * @param args Arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + run("put", CacheAtomicityMode.ATOMIC); + run("get", CacheAtomicityMode.ATOMIC); + run("put", CacheAtomicityMode.TRANSACTIONAL); + run("get", CacheAtomicityMode.TRANSACTIONAL); + } + + /** + * Run benchmarks for atomic cache. + * + * @param benchmark Benchmark name. + * @param atomicityMode Atomicity mode. + * @throws Exception If failed. + */ + private static void run(String benchmark, CacheAtomicityMode atomicityMode) throws Exception { + run(benchmark, 4, true, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); + run(benchmark, 4, true, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); + run(benchmark, 4, false, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); + run(benchmark, 4, false, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); + } + + /** + * Run benchmark. + * + * @param benchmark Benchmark to run. + * @param threads Amount of threads. + * @param client Client mode flag. + * @param atomicityMode Atomicity mode. + * @param writeSyncMode Write synchronization mode. + * @throws Exception If failed. + */ + private static void run(String benchmark, int threads, boolean client, CacheAtomicityMode atomicityMode, + CacheWriteSynchronizationMode writeSyncMode) throws Exception { + String simpleClsName = JmhCacheBenchmark.class.getSimpleName(); + + String output = simpleClsName + "-" + benchmark + + "-" + threads + "-threads" + + "-" + (client ? "client" : "data") + + "-" + atomicityMode + + "-" + writeSyncMode; + + JmhIdeBenchmarkRunner.create() + .forks(1) + .threads(threads) + .warmupIterations(10) + .measurementIterations(60) + .benchmarks(simpleClsName + "." + benchmark) + .output(output + ".jmh.log") + .profilers(GCProfiler.class) + .jvmArguments( + "-Xms4g", + "-Xmx4g", + "-XX:+UnlockCommercialFeatures", + "-XX:+FlightRecorder", + "-XX:StartFlightRecording=delay=30s,dumponexit=true,settings=alloc,filename=" + output + ".jfr", + JmhIdeBenchmarkRunner.createProperty(PROP_ATOMICITY_MODE, atomicityMode), + JmhIdeBenchmarkRunner.createProperty(PROP_WRITE_SYNC_MODE, writeSyncMode), + JmhIdeBenchmarkRunner.createProperty(PROP_DATA_NODES, 2), + JmhIdeBenchmarkRunner.createProperty(PROP_CLIENT_MODE, client)) + .run(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e2be94e6/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCachePutBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCachePutBenchmark.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCachePutBenchmark.java deleted file mode 100644 index 848e7ce..0000000 --- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCachePutBenchmark.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.ignite.internal.benchmarks.jmh.cache; - -import org.apache.ignite.IgniteDataStreamer; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner; -import org.apache.ignite.internal.benchmarks.model.IntValue; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.profile.GCProfiler; - -import java.util.concurrent.ThreadLocalRandom; - -/** - * Put benchmark. - */ -@SuppressWarnings("unchecked") -public class JmhCachePutBenchmark extends JmhCacheAbstractBenchmark { - /** Items count. */ - private static final int CNT = 100000; - - /** - * Set up routine. - * - * @throws Exception If failed. - */ - - public void setup() throws Exception { - super.setup(); - - IgniteDataStreamer<Integer, IntValue> dataLdr = node.dataStreamer(cache.getName()); - - for (int i = 0; i < CNT; i++) - dataLdr.addData(i, new IntValue(i)); - - dataLdr.close(); - - System.out.println("Cache populated."); - } - - /** - * Test PUT operation. - * - * @throws Exception If failed. - */ - @Benchmark - public void testPut() throws Exception { - int key = ThreadLocalRandom.current().nextInt(CNT); - - cache.put(key, new IntValue(key)); - } - - /** - * Run benchmarks. - * - * @param args Arguments. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - run(CacheAtomicityMode.ATOMIC); - } - - /** - * Run benchmarks for atomic cache. - * - * @param atomicityMode Atomicity mode. - * @throws Exception If failed. - */ - private static void run(CacheAtomicityMode atomicityMode) throws Exception { - run(4, true, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); - run(4, true, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); - run(4, false, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); - run(4, false, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); - } - - /** - * Run benchmark. - * - * @param client Client mode flag. - * @param writeSyncMode Write synchronization mode. - * @throws Exception If failed. - */ - private static void run(int threads, boolean client, CacheAtomicityMode atomicityMode, - CacheWriteSynchronizationMode writeSyncMode) throws Exception { - String output = "ignite-cache-put-" + threads + "-threads-" + (client ? "client" : "data") + - "-" + atomicityMode + "-" + writeSyncMode; - - JmhIdeBenchmarkRunner.create() - .forks(1) - .threads(threads) - .warmupIterations(10) - .measurementIterations(60) - .classes(JmhCachePutBenchmark.class) - .output(output + ".jmh.log") - .profilers(GCProfiler.class) - .jvmArguments( - "-Xms4g", - "-Xmx4g", - "-XX:+UnlockCommercialFeatures", - "-XX:+FlightRecorder", - "-XX:StartFlightRecording=delay=30s,dumponexit=true,settings=alloc,filename=" + output + ".jfr", - JmhIdeBenchmarkRunner.createProperty(PROP_ATOMICITY_MODE, atomicityMode), - JmhIdeBenchmarkRunner.createProperty(PROP_WRITE_SYNC_MODE, writeSyncMode), - JmhIdeBenchmarkRunner.createProperty(PROP_DATA_NODES, 2), - JmhIdeBenchmarkRunner.createProperty(PROP_CLIENT_MODE, client)) - .run(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/e2be94e6/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java ---------------------------------------------------------------------- diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java index af84862..0cad088 100644 --- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java +++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java @@ -42,8 +42,8 @@ public class JmhIdeBenchmarkRunner { /** Output time unit. */ private TimeUnit outputTimeUnit = TimeUnit.SECONDS; - /** Classes to run. */ - private Class[] clss; + /** Benchmarks to run. */ + private Object[] benchmarks; /** JVM arguments. */ private String[] jvmArgs; @@ -123,11 +123,11 @@ public class JmhIdeBenchmarkRunner { } /** - * @param clss Classes. + * @param benchmarks Benchmarks. * @return This instance. */ - public JmhIdeBenchmarkRunner classes(Class... clss) { - this.clss = clss; + public JmhIdeBenchmarkRunner benchmarks(Object... benchmarks) { + this.benchmarks = benchmarks; return this; } @@ -191,9 +191,13 @@ public class JmhIdeBenchmarkRunner { builder.getBenchModes().add(benchmarkMode); } - if (clss != null) { - for (Class cls : clss) - builder.include(cls.getSimpleName()); + if (benchmarks != null) { + for (Object benchmark : benchmarks) { + if (benchmark instanceof Class) + builder.include(((Class)benchmark).getSimpleName()); + else + builder.include(benchmark.toString()); + } } if (jvmArgs != null)
