ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject [16/48] ignite git commit: WIP on local benchmarks.
Date Mon, 01 Feb 2016 14:27:11 GMT
WIP on local benchmarks.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f74e8919
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f74e8919
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f74e8919

Branch: refs/heads/ignite-2454
Commit: f74e89190f241ba71d81f9c5e46b3ca9fb6a87ce
Parents: a34d705
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Thu Jan 28 13:24:22 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Thu Jan 28 13:24:22 2016 +0300

----------------------------------------------------------------------
 .../benchmarks/jmh/JmhAbstractBenchmark.java    | 150 +++++++++++++++
 .../jmh/cache/JmhCacheAbstractBenchmark.java    | 110 +++++++++++
 .../jmh/cache/JmhCachePutBenchmark.java         | 150 +++++++++++++++
 .../benchmarks/jmh/cache/PutBenchmark.java      | 170 -----------------
 .../jmh/runner/JmhIdeBenchmarkRunner.java       | 184 +++++++++++++++++++
 5 files changed, 594 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f74e8919/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/JmhAbstractBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/JmhAbstractBenchmark.java
b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/JmhAbstractBenchmark.java
new file mode 100644
index 0000000..69e4a78
--- /dev/null
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/JmhAbstractBenchmark.java
@@ -0,0 +1,150 @@
+/*
+ * 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;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Base class for all JMH-related benchmarks.
+ */
+public abstract class JmhAbstractBenchmark {
+    /**
+     * Generate random integer value.
+     *
+     * @return Value.
+     */
+    protected static int randomInt() {
+        return ThreadLocalRandom.current().nextInt();
+    }
+
+    /**
+     * Generate random integer value.
+     *
+     * @param max Upper bound.
+     * @return Value.
+     */
+    protected static int randomInt(int max) {
+        return ThreadLocalRandom.current().nextInt(max);
+    }
+
+    /**
+     * Get boolean property.
+     *
+     * @param name Name.
+     * @return Value.
+     */
+    protected static boolean booleanProperty(String name) {
+        return booleanProperty(name, false);
+    }
+
+    /**
+     * Get boolean property.
+     *
+     * @param name Name.
+     * @param dflt Default.
+     * @return Value.
+     */
+    protected static boolean booleanProperty(String name, boolean dflt) {
+        String val = property(name);
+
+        return val != null ? Boolean.parseBoolean(val) : dflt;
+    }
+
+    /**
+     * Get int property.
+     *
+     * @param name Name.
+     * @return Value.
+     */
+    protected static int intProperty(String name) {
+        return intProperty(name, 0);
+    }
+
+    /**
+     * Get int property.
+     *
+     * @param name Name.
+     * @param dflt Default value.
+     * @return Value.
+     */
+    protected static int intProperty(String name, int dflt) {
+        String val = property(name);
+
+        return val != null ? Integer.parseInt(val) : dflt;
+    }
+
+    /**
+     * Get string property.
+     *
+     * @param name Name.
+     * @return Result.
+     */
+    protected static String stringProperty(String name) {
+        return stringProperty(name, null);
+    }
+
+    /**
+     * Get string property.
+     *
+     * @param name Name.
+     * @param dflt Default value.
+     * @return Result.
+     */
+    protected static String stringProperty(String name, String dflt) {
+        String val = property(name);
+
+        return val != null ? val : dflt;
+    }
+
+    /**
+     * Get enum property.
+     *
+     * @param name Name.
+     * @param cls Class.
+     * @return Value.
+     */
+    @SuppressWarnings("unchecked")
+    protected static <T> T enumProperty(String name, Class cls) {
+        return enumProperty(name, cls, null);
+    }
+
+    /**
+     * Get enum property.
+     *
+     * @param name Name.
+     * @param cls Class.
+     * @param dflt Default value.
+     * @return Value.
+     */
+    @SuppressWarnings("unchecked")
+    protected static <T> T enumProperty(String name, Class cls, T dflt) {
+        String val = property(name);
+
+        return val != null ? (T)Enum.valueOf(cls, val) : dflt;
+    }
+
+    /**
+     * Get property's value.
+     *
+     * @param name Name.
+     * @return Value.
+     */
+    private static String property(String name) {
+        return System.getProperty(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f74e8919/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
new file mode 100644
index 0000000..1205650
--- /dev/null
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheAbstractBenchmark.java
@@ -0,0 +1,110 @@
+/*
+ * 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.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.benchmarks.jmh.JmhAbstractBenchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/**
+ * Base class for cache benchmarks.
+ */
+@State(Scope.Benchmark)
+public class JmhCacheAbstractBenchmark extends JmhAbstractBenchmark {
+    /** Property: backups. */
+    protected static final String PROP_BACKUPS = "ignite.jmh.cache.backups";
+
+    /** Property: atomicity mode. */
+    protected static final String PROP_ATOMICITY_MODE = "ignite.jmh.cache.atomicityMode";
+
+    /** Property: atomicity mode. */
+    protected static final String PROP_WRITE_SYNC_MODE = "ignite.jmh.cache.writeSynchronizationMode";
+
+    /**
+     * Setup routine. Child classes must invoke this method first.
+     *
+     * @throws Exception If failed.
+     */
+    @Setup
+    public void setup() throws Exception {
+        System.out.println();
+        System.out.println("--------------------");
+
+        System.out.println("IGNITE BENCHMARK INFO: ");
+
+        System.out.println("\tbackups:                    " + intProperty(PROP_BACKUPS));
+
+        System.out.println("\tatomicity mode:             " +
+            enumProperty(PROP_ATOMICITY_MODE, CacheAtomicityMode.class));
+
+        System.out.println("\twrite synchronization mode: " +
+            enumProperty(PROP_WRITE_SYNC_MODE, CacheWriteSynchronizationMode.class));
+
+        System.out.println("--------------------");
+        System.out.println();
+    }
+
+    /**
+     * Tear down routine.
+     *
+     * @throws Exception If failed.
+     */
+    @TearDown
+    public void tearDown() throws Exception {
+        Ignition.stopAll(true);
+    }
+
+    /**
+     * Create cache configuration.
+     *
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration cacheConfiguration() {
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setName(null);
+        cacheCfg.setCacheMode(CacheMode.PARTITIONED);
+        cacheCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
+
+        // Set atomicity mode.
+        CacheAtomicityMode atomicityMode = enumProperty(PROP_ATOMICITY_MODE, CacheAtomicityMode.class);
+
+        if (atomicityMode != null)
+            cacheCfg.setAtomicityMode(atomicityMode);
+
+        // Set write synchronization mode.
+        CacheWriteSynchronizationMode writeSyncMode =
+            enumProperty(PROP_WRITE_SYNC_MODE, CacheWriteSynchronizationMode.class);
+
+        if (writeSyncMode != null)
+            cacheCfg.setWriteSynchronizationMode(writeSyncMode);
+
+        // Set backups.
+        cacheCfg.setBackups(intProperty(PROP_BACKUPS));
+
+        return cacheCfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f74e8919/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
new file mode 100644
index 0000000..c05acf0
--- /dev/null
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCachePutBenchmark.java
@@ -0,0 +1,150 @@
+/*
+ * 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.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
+import org.apache.ignite.internal.benchmarks.model.IntValue;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Put benchmark.
+ */
+@SuppressWarnings({"unchecked", "unused", "FieldCanBeLocal"})
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.SECONDS)
+@Warmup(iterations = 10)
+@Measurement(iterations = 120)
+@Fork(1)
+public class JmhCachePutBenchmark extends JmhCacheAbstractBenchmark {
+    /** First Ignite instance. */
+    private static Ignite ignite1;
+
+    /** Second Ignite instance. */
+    private static Ignite ignite2;
+
+    /** Target cache. */
+    private static IgniteCache<Integer, IntValue> cache1;
+
+    /** Items count. */
+    private static final int CNT = 100000;
+
+    /** IP finder shared across nodes. */
+    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /**
+     * Set up routine.
+     *
+     * @throws Exception If failed.
+     */
+
+    public void setup() throws Exception {
+        super.setup();
+
+        ignite1 = Ignition.start(config("node1"));
+        ignite2 = Ignition.start(config("node2"));
+
+        cache1 = ignite1.cache(null);
+
+        IgniteDataStreamer<Integer, IntValue> dataLdr = ignite1.dataStreamer(cache1.getName());
+
+        for (int i = 0; i < CNT; i++)
+            dataLdr.addData(i, new IntValue(i));
+
+        dataLdr.close();
+
+        System.out.println("Cache populated.");
+    }
+
+    /**
+     * Create configuration.
+     *
+     * @param gridName Grid name.
+     * @return Configuration.
+     */
+    private IgniteConfiguration config(String gridName) {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        cfg.setGridName(gridName);
+
+        cfg.setLocalHost("127.0.0.1");
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+        discoSpi.setIpFinder(IP_FINDER);
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        return cfg;
+    }
+
+    /**
+     * Test PUT operation.
+     *
+     * @throws Exception If failed.
+     */
+    @Benchmark
+    @Threads(4)
+    public void testPut() throws Exception {
+        int key = ThreadLocalRandom.current().nextInt(CNT);
+
+        cache1.put(key, new IntValue(key));
+    }
+
+    /**
+     * Runner.
+     *
+     * @param args Arguments.
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        JmhIdeBenchmarkRunner.create()
+            .forks(1)
+            .warmupIterations(10)
+            .measurementIterations(2000)
+            .classes(JmhCachePutBenchmark.class)
+            .jvmArguments(
+                "-Xms4g",
+                "-Xmx4g",
+                "-XX:+UnlockCommercialFeatures",
+                "-XX:+FlightRecorder",
+                "-XX:StartFlightRecording=delay=20s,duration=60s,dumponexit=true,settings=alloc,filename=ignite-put_bench.jfr",
+                JmhIdeBenchmarkRunner.createProperty(PROP_BACKUPS, 1),
+                JmhIdeBenchmarkRunner.createProperty(PROP_ATOMICITY_MODE, CacheAtomicityMode.ATOMIC),
+                JmhIdeBenchmarkRunner.createProperty(PROP_WRITE_SYNC_MODE, CacheWriteSynchronizationMode.PRIMARY_SYNC))
+            .run();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f74e8919/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/PutBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/PutBenchmark.java
b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/PutBenchmark.java
deleted file mode 100644
index aa04389..0000000
--- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/PutBenchmark.java
+++ /dev/null
@@ -1,170 +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.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteDataStreamer;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.internal.benchmarks.model.IntValue;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheRebalanceMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.TearDown;
-import org.openjdk.jmh.annotations.Threads;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.OptionsBuilder;
-
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Put benchmark.
- */
-@SuppressWarnings({"unchecked", "unused", "FieldCanBeLocal"})
-@State(Scope.Benchmark)
-@BenchmarkMode(Mode.Throughput)
-@OutputTimeUnit(TimeUnit.SECONDS)
-@Warmup(iterations = 10)
-@Measurement(iterations = 120)
-@Fork(1)
-public class PutBenchmark {
-    /** First Ignite instance. */
-    private static Ignite ignite1;
-
-    /** Second Ignite instance. */
-    private static Ignite ignite2;
-
-    /** Target cache. */
-    private static IgniteCache<Integer, IntValue> cache1;
-
-    /** Items count. */
-    private static final int CNT = 100000;
-
-    /** IP finder shared across nodes. */
-    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /**
-     * Set up routine.
-     *
-     * @throws Exception If failed.
-     */
-    @Setup
-    public static void setup() throws Exception {
-        ignite1 = Ignition.start(config("node1"));
-        ignite2 = Ignition.start(config("node2"));
-
-        cache1 = ignite1.cache(null);
-
-        IgniteDataStreamer<Integer, IntValue> dataLdr = ignite1.dataStreamer(cache1.getName());
-
-        for (int i = 0; i < CNT; i++)
-            dataLdr.addData(i, new IntValue(i));
-
-        dataLdr.close();
-
-        System.out.println("Cache populated.");
-    }
-
-    /**
-     * Tear down routine.
-     *
-     * @throws Exception If failed.
-     */
-    @TearDown
-    public static void tearDown() throws Exception {
-        Ignition.stopAll(true);
-    }
-
-    /**
-     * Create configuration.
-     *
-     * @param gridName Grid name.
-     * @return Configuration.
-     */
-    private static IgniteConfiguration config(String gridName) {
-        IgniteConfiguration cfg = new IgniteConfiguration();
-
-        cfg.setGridName(gridName);
-
-        cfg.setLocalHost("127.0.0.1");
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-        discoSpi.setIpFinder(IP_FINDER);
-        cfg.setDiscoverySpi(discoSpi);
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setName(null);
-        cacheCfg.setCacheMode(CacheMode.PARTITIONED);
-        cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
-        cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
-        cacheCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
-        cacheCfg.setBackups(1);
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        return cfg;
-    }
-
-    /**
-     * Test PUT operation.
-     *
-     * @throws Exception If failed.
-     */
-    @Benchmark
-    @Threads(4)
-    public void testPut() throws Exception {
-        int key = ThreadLocalRandom.current().nextInt(CNT);
-
-        cache1.put(key, new IntValue(key));
-    }
-
-    /**
-     * Runner.
-     *
-     * @param args Arguments.
-     * @throws Exception If failed.
-     */
-    public static void main(String[] args) throws Exception {
-        // Use the following additional options to record JFR dump:
-        // "-XX:+UnlockCommercialFeatures", "-XX:+FlightRecorder", "-XX:StartFlightRecording=delay=20s,duration=60s,filename=ignite-put_bench.jfr"
-
-        String[] jvmArgs = new String[] { "-Xms4g", "-Xmx4g" };
-
-        Options opts = new OptionsBuilder().include(PutBenchmark.class.getSimpleName()).jvmArgs(jvmArgs).build();
-
-        new Runner(opts).run();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f74e8919/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
new file mode 100644
index 0000000..68e9000
--- /dev/null
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/runner/JmhIdeBenchmarkRunner.java
@@ -0,0 +1,184 @@
+/*
+ * 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.runner;
+
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * JMH IDE benchmark runner configuration.
+ */
+public class JmhIdeBenchmarkRunner {
+    /** Benchmark modes. */
+    private Mode[] benchmarkModes = new Mode[] { Mode.Throughput };
+
+    /** Amount of forks */
+    private int forks = 1;
+
+    /** Warmup iterations. */
+    private int warmupIterations = 10;
+
+    /** Measurement operations. */
+    private int measurementIterations = 10;
+
+    /** Output time unit. */
+    private TimeUnit outputTimeUnit = TimeUnit.SECONDS;
+
+    /** Classes to run. */
+    private Class[] clss;
+
+    /** JVM arguments. */
+    private String[] jvmArgs;
+
+    /**
+     * Create new runner.
+     *
+     * @return New runner.
+     */
+    public static JmhIdeBenchmarkRunner create() {
+        return new JmhIdeBenchmarkRunner();
+    }
+
+    /**
+     * Constructor.
+     */
+    private JmhIdeBenchmarkRunner() {
+        // No-op.
+    }
+
+    /**
+     * @param benchmarkModes Benchmark modes.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner benchmarkModes(Mode... benchmarkModes) {
+        this.benchmarkModes = benchmarkModes;
+
+        return this;
+    }
+
+    /**
+     * @param forks Forks.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner forks(int forks) {
+        this.forks = forks;
+
+        return this;
+    }
+
+    /**
+     * @param warmupIterations Warmup iterations.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner warmupIterations(int warmupIterations) {
+        this.warmupIterations = warmupIterations;
+
+        return this;
+    }
+
+    /**
+     * @param measurementIterations Measurement iterations.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner measurementIterations(int measurementIterations) {
+        this.measurementIterations = measurementIterations;
+
+        return this;
+    }
+    /**
+     * @param outputTimeUnit Output time unit.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner outputTimeUnit(TimeUnit outputTimeUnit) {
+        this.outputTimeUnit = outputTimeUnit;
+
+        return this;
+    }
+
+    /**
+     * @param clss Classes.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner classes(Class... clss) {
+        this.clss = clss;
+
+        return this;
+    }
+
+    /**
+     * @param jvmArgs JVM arguments.
+     * @return This instance.
+     */
+    public JmhIdeBenchmarkRunner jvmArguments(String... jvmArgs) {
+        this.jvmArgs = jvmArgs;
+
+        return this;
+    }
+
+    /**
+     * Get prepared options builder.
+     *
+     * @return Options builder.
+     */
+    public OptionsBuilder optionsBuilder() {
+        OptionsBuilder builder = new OptionsBuilder();
+
+        builder.forks(forks);
+        builder.warmupIterations(warmupIterations);
+        builder.measurementIterations(measurementIterations);
+        builder.timeUnit(outputTimeUnit);
+
+        if (benchmarkModes != null) {
+            for (Mode benchmarkMode : benchmarkModes)
+                builder.getBenchModes().add(benchmarkMode);
+        }
+
+        if (clss != null) {
+            for (Class cls : clss)
+                builder.include(cls.getSimpleName());
+        }
+
+        if (jvmArgs != null)
+            builder.jvmArgs(jvmArgs);
+
+        return builder;
+    }
+
+    /**
+     * Run benchmarks.
+     *
+     * @throws Exception If failed.
+     */
+    public void run() throws Exception {
+        new Runner(optionsBuilder().build()).run();
+    }
+
+    /**
+     * Create property.
+     *
+     * @param name Name.
+     * @param val Value.
+     * @return Result.
+     */
+    public static String createProperty(String name, Object val) {
+        return "-D" + name + "=" + val;
+    }
+}


Mime
View raw message