ignite-782 SortedEvictionPolicy performance test

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

Branch: refs/heads/ignite-646
Commit: dc455be3f8e16bc7098bbf654f087dc1b7177b64
Parents: 700cf08
Author: agura <ag...@gridgain.com>
Authored: Tue Apr 21 17:34:31 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Tue Apr 21 17:34:31 2015 +0300

----------------------------------------------------------------------
 ...acheSortedEvictionPolicyPerformanceTest.java | 136 +++++++++++++++++++
 1 file changed, 136 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/dc455be3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
new file mode 100644
index 0000000..7864903
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.processors.cache.eviction.sorted;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.eviction.sorted.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import org.jsr166.*;
+
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * {@link SortedEvictionPolicy} performance test.
+ */
+public class GridCacheSortedEvictionPolicyPerformanceTest extends 
GridCommonAbstractTest {
+    /** Threads. */
+    private static final int THREADS = 8;
+
+    /** Keys. */
+    private static final int KEYS = 100_000;
+
+    /** Max size. */
+    private static final int MAX_SIZE = 1000;
+
+    /** Put probability. */
+    private static final int P_PUT = 50;
+
+    /** Get probability. */
+    private static final int P_GET = 30;
+
+    /** Measurement count. */
+    private static final int MEASUREMENT_CNT = 100;
+
+    /** Rnd. */
+    private static final ThreadLocalRandom8 RND = ThreadLocalRandom8.current();
+
+    /** Ignite. */
+    private static Ignite ignite;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        ignite = startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+
+        ccfg.setCacheMode(CacheMode.PARTITIONED);
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+        ccfg.setNearConfiguration(null);
+        ccfg.setEvictionPolicy(new SortedEvictionPolicy(MAX_SIZE));
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * Tests throughput.
+     */
+    public void testThroughput() throws Exception {
+        final LongAdder8 cnt = new LongAdder8();
+        final AtomicBoolean finished = new AtomicBoolean();
+
+        final int pPut = P_PUT;
+        final int pGet = P_PUT + P_GET;
+
+        final IgniteCache<Integer, Integer> cache = ignite.cache(null);
+
+        multithreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                int c = MEASUREMENT_CNT;
+
+                for (; c > 0; c--) {
+                    U.sleep(1000);
+
+                    info("Ops/sec: " + cnt.sumThenReset());
+                }
+
+                finished.set(true);
+
+                return null;
+            }
+        }, 1);
+
+        multithreaded(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    while (!finished.get()) {
+                        int p = RND.nextInt(100);
+
+                        int key = RND.nextInt(KEYS);
+
+                        if (p >= 0 && p < pPut)
+                            cache.put(key, 0);
+                        else if (p >= pPut && p < pGet)
+                            cache.get(key);
+                        else
+                            cache.remove(key);
+
+                        cnt.increment();
+                    }
+
+                    return null;
+                }
+            }, THREADS);
+    }
+}

Reply via email to