IGNITE-5567 Make benchmark Ignite.reentrantLock vs IgniteCache.lock

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

Branch: refs/heads/ignite-5578
Commit: 00c6b6c4ba00fa6577f74fc95b378737fb5a789c
Parents: 5394bbd
Author: Alexander Menshikov <sharple...@gmail.com>
Authored: Thu Jul 13 15:24:59 2017 +0300
Committer: Anton Vinogradov <a...@apache.org>
Committed: Thu Jul 13 15:24:59 2017 +0300

----------------------------------------------------------------------
 .../jmh/cache/JmhCacheLocksBenchmark.java       | 119 +++++++++++++++++++
 .../cache/IgniteCacheLockBenchmark.java         |  57 +++++++++
 .../yardstick/cache/IgniteLockBenchmark.java    |  47 ++++++++
 3 files changed, 223 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/00c6b6c4/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheLocksBenchmark.java
----------------------------------------------------------------------
diff --git 
a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheLocksBenchmark.java
 
b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheLocksBenchmark.java
new file mode 100644
index 0000000..677e767
--- /dev/null
+++ 
b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/cache/JmhCacheLocksBenchmark.java
@@ -0,0 +1,119 @@
+/*
+ * 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 java.util.concurrent.locks.Lock;
+import org.apache.ignite.IgniteLock;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Setup;
+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;
+
+/**
+ * IgniteCache.lock() vs Ignite.reentrantLock().
+ */
+@Warmup(iterations = 40)
+@Measurement(iterations = 20)
+@Fork(1)
+public class JmhCacheLocksBenchmark extends JmhCacheAbstractBenchmark {
+    /** Fixed lock key for Ignite.reentrantLock() and IgniteCache.lock(). */
+    private static final String lockKey = "key0";
+
+    /** Parameter for Ignite.reentrantLock(). */
+    private static final boolean failoverSafe = false;
+
+    /** Parameter for Ignite.reentrantLock(). */
+    private static final boolean fair = false;
+
+    /** IgniteCache.lock() with a fixed lock key. */
+    private Lock cacheLock;
+
+    /** Ignite.reentrantLock() with a fixed lock key. */
+    private IgniteLock igniteLock;
+
+    /**
+     * Test IgniteCache.lock() with fixed key and no-op inside.
+     */
+    @Benchmark
+    public void cacheLock() {
+        cacheLock.lock();
+        cacheLock.unlock();
+    }
+
+    /**
+     * Test Ignite.reentrantLock() with fixed key and no-op inside.
+     */
+    @Benchmark
+    public void igniteLock() {
+        igniteLock.lock();
+        igniteLock.unlock();
+    }
+
+    /**
+     * Create locks and put values in the cache.
+     */
+    @Setup(Level.Trial)
+    public void createLock() {
+        cacheLock = cache.lock(lockKey);
+
+        igniteLock = node.reentrantLock(lockKey, failoverSafe, fair, true);
+    }
+
+    /**
+     * Run benchmarks.
+     *
+     * @param args Arguments.
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        final String simpleClsName = 
JmhCacheLocksBenchmark.class.getSimpleName();
+        final int threads = 4;
+        final boolean client = true;
+        final CacheAtomicityMode atomicityMode = 
CacheAtomicityMode.TRANSACTIONAL;
+        final CacheWriteSynchronizationMode writeSyncMode = 
CacheWriteSynchronizationMode.FULL_SYNC;
+
+        final String output = simpleClsName +
+            "-" + threads + "-threads" +
+            "-" + (client ? "client" : "data") +
+            "-" + atomicityMode +
+            "-" + writeSyncMode;
+
+        final Options opt = new OptionsBuilder()
+            .threads(threads)
+            .include(simpleClsName)
+            .output(output + ".jmh.log")
+            .jvmArgs(
+                "-Xms1g",
+                "-Xmx1g",
+                "-XX:+UnlockCommercialFeatures",
+                JmhIdeBenchmarkRunner.createProperty(PROP_ATOMICITY_MODE, 
atomicityMode),
+                JmhIdeBenchmarkRunner.createProperty(PROP_WRITE_SYNC_MODE, 
writeSyncMode),
+                JmhIdeBenchmarkRunner.createProperty(PROP_DATA_NODES, 4),
+                JmhIdeBenchmarkRunner.createProperty(PROP_CLIENT_MODE, 
client)).build();
+
+        new Runner(opt).run();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/00c6b6c4/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheLockBenchmark.java
----------------------------------------------------------------------
diff --git 
a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheLockBenchmark.java
 
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheLockBenchmark.java
new file mode 100644
index 0000000..85cd5ae
--- /dev/null
+++ 
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheLockBenchmark.java
@@ -0,0 +1,57 @@
+/*
+ * 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.yardstick.cache;
+
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import org.apache.ignite.IgniteCache;
+import org.yardstickframework.BenchmarkConfiguration;
+
+/**
+ * Ignite benchmark that performs IgniteCache.lock operations.
+ */
+public class IgniteCacheLockBenchmark extends 
IgniteCacheAbstractBenchmark<String, Integer> {
+    /** Cache lock. */
+    private Lock lock;
+
+    /** {@inheritDoc} */
+    @Override public boolean test(Map<Object, Object> map) throws Exception {
+        lock.lock();
+        lock.unlock();
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteCache<String, Integer> cache() {
+        return ignite().cache("tx");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
+        super.setUp(cfg);
+
+        String key = "key";
+
+        IgniteCache<String, Integer> cache = cacheForOperation();
+
+        cache.put(key, 0);
+
+        lock = cache.lock(key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/00c6b6c4/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteLockBenchmark.java
----------------------------------------------------------------------
diff --git 
a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteLockBenchmark.java
 
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteLockBenchmark.java
new file mode 100644
index 0000000..5349b69
--- /dev/null
+++ 
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteLockBenchmark.java
@@ -0,0 +1,47 @@
+/*
+ * 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.yardstick.cache;
+
+import java.util.Map;
+import org.apache.ignite.IgniteLock;
+import org.yardstickframework.BenchmarkConfiguration;
+
+/**
+ * Ignite benchmark that performs Ignite.reentrantLock operations.
+ */
+public class IgniteLockBenchmark extends IgniteCacheLockBenchmark {
+    /** Reentrant lock. */
+    private IgniteLock lock;
+
+    /** {@inheritDoc} */
+    @Override public boolean test(Map<Object, Object> map) throws Exception {
+        lock.lock();
+        lock.unlock();
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
+        super.setUp(cfg);
+
+        String key = "key";
+
+        lock = ignite().reentrantLock(key, false, false, true);
+    }
+}

Reply via email to