ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [14/46] ignite git commit: Added --keysPerThread parameter for putAll benchmark.
Date Wed, 28 Oct 2015 09:30:17 GMT
Added --keysPerThread parameter for putAll benchmark.


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

Branch: refs/heads/ignite-843-rc1
Commit: 15cc1bdb0b35175b79487481966ad9e180927d84
Parents: e6e475c
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Oct 26 14:11:55 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Oct 26 14:11:55 2015 +0300

----------------------------------------------------------------------
 .../yardstick/IgniteBenchmarkArguments.java     | 11 ++++
 .../cache/IgniteCacheAbstractBenchmark.java     | 63 ++++++++++++++++++++
 .../cache/IgnitePutAllTxBenchmark.java          |  6 +-
 3 files changed, 78 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/15cc1bdb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
index 6e9059d..792d366 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkArguments.java
@@ -112,6 +112,10 @@ public class IgniteBenchmarkArguments {
     @Parameter(names = {"-jdbc", "--jdbcUrl"}, description = "JDBC url")
     private String jdbcUrl;
 
+    /** */
+    @Parameter(names = {"-kpt", "--keysPerThread"}, description = "Use not intersecting keys
in putAll benchmark")
+    private boolean keysPerThread;
+
     /**
      * @return JDBC url.
      */
@@ -274,6 +278,13 @@ public class IgniteBenchmarkArguments {
             (orderMode == null ? "" : "-wom=" + orderMode) + "-txc=" + txConcurrency;
     }
 
+    /**
+     * @return {@code True} if use not intersecting keys in putAll benchmark.
+     */
+    public boolean keysPerThread() {
+       return keysPerThread;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return GridToStringBuilder.toString(IgniteBenchmarkArguments.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/15cc1bdb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java
index 7b350c3..1260f9c 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteCacheAbstractBenchmark.java
@@ -17,9 +17,12 @@
 
 package org.apache.ignite.yardstick.cache;
 
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.yardstick.IgniteAbstractBenchmark;
 import org.yardstickframework.BenchmarkConfiguration;
+import org.yardstickframework.BenchmarkUtils;
 
 /**
  * Abstract class for Ignite benchmarks which use cache.
@@ -28,6 +31,12 @@ public abstract class IgniteCacheAbstractBenchmark extends IgniteAbstractBenchma
     /** Cache. */
     protected IgniteCache<Integer, Object> cache;
 
+    /** */
+    private ThreadLocal<ThreadRange> threadRange = new ThreadLocal<>();
+
+    /** */
+    private AtomicInteger threadIdx = new AtomicInteger();
+
     /** {@inheritDoc} */
     @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
         super.setUp(cfg);
@@ -36,9 +45,63 @@ public abstract class IgniteCacheAbstractBenchmark extends IgniteAbstractBenchma
     }
 
     /**
+     * @return Range.
+     */
+    protected final ThreadRange threadRange() {
+        ThreadRange r = threadRange.get();
+
+        if (r == null) {
+            if (args.keysPerThread()) {
+                int idx = threadIdx.getAndIncrement();
+
+                int keysPerThread = (int)(args.range() / (float)cfg.threads());
+
+                int min = keysPerThread * idx;
+                int max = min + keysPerThread;
+
+                r = new ThreadRange(min, max);
+            }
+            else
+                r = new ThreadRange(0, args.range());
+
+            BenchmarkUtils.println(cfg, "Initialized thread range [min=" + r.min + ", max="
+ r.max + ']');
+
+            threadRange.set(r);
+        }
+
+        return r;
+    }
+
+    /**
      * Each benchmark must determine which cache will be used.
      *
      * @return IgniteCache Cache to use.
      */
     protected abstract IgniteCache<Integer, Object> cache();
+
+    /**
+     *
+     */
+    static class ThreadRange {
+        /** */
+        final int min;
+        /** */
+        final int max;
+
+        /**
+         * @param min Min.
+         * @param max Max.
+         */
+        private ThreadRange(int min, int max) {
+            this.min = min;
+            this.max = max;
+        }
+
+        /**
+         * @return Next random key.
+         */
+        int nextRandom() {
+            return ThreadLocalRandom.current().nextInt(min, max);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/15cc1bdb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllTxBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllTxBenchmark.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllTxBenchmark.java
index dc8e3f8..32d5b02 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllTxBenchmark.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutAllTxBenchmark.java
@@ -41,12 +41,14 @@ public class IgnitePutAllTxBenchmark extends IgniteCacheAbstractBenchmark
{
 
     /** {@inheritDoc} */
     @Override public boolean test(Map<Object, Object> ctx) throws Exception {
+        ThreadRange r = threadRange();
+
         SortedMap<Integer, Integer> vals = new TreeMap<>();
 
-        ClusterNode node = args.collocated() ? aff.mapKeyToNode(nextRandom(args.range()))
: null;
+        ClusterNode node = args.collocated() ? aff.mapKeyToNode(r.nextRandom()) : null;
 
         for (int i = 0; i < args.batch(); ) {
-            int key = nextRandom(args.range());
+            int key = r.nextRandom();
 
             if (args.collocated() && !aff.isPrimary(node, key))
                 continue;


Mime
View raw message