ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [36/50] incubator-ignite git commit: ignite-sql-tests - bench
Date Wed, 18 Mar 2015 14:06:48 GMT
ignite-sql-tests - bench


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

Branch: refs/heads/ignite-424
Commit: b10ae795e1c3760aeb5763fa23c7f929f240b98a
Parents: 52ee235
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Tue Mar 17 21:34:30 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Tue Mar 17 21:34:30 2015 +0300

----------------------------------------------------------------------
 .../cache/GridCacheQuerySimpleBenchmark.java    | 200 +++++++++++++++++++
 1 file changed, 200 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b10ae795/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySimpleBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySimpleBenchmark.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySimpleBenchmark.java
new file mode 100644
index 0000000..54f9f93
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySimpleBenchmark.java
@@ -0,0 +1,200 @@
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jdk8.backport.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ *
+ */
+public class GridCacheQuerySimpleBenchmark extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private Ignite ignite;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        c.setDiscoverySpi(disco);
+
+        CacheConfiguration<?,?> ccfg = new CacheConfiguration<>();
+
+        ccfg.setName("offheap-cache");
+        ccfg.setCacheMode(CacheMode.PARTITIONED);
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+        ccfg.setSwapEnabled(false);
+        ccfg.setQueryIndexEnabled(true);
+
+        ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED);
+
+        c.setCacheConfiguration(ccfg);
+
+        QueryConfiguration qcfg = new QueryConfiguration();
+
+        qcfg.setMaxOffHeapMemory(0);
+
+        c.setQueryConfiguration(qcfg);
+
+        return c;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        ignite = startGridsMultiThreaded(3);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        ignite = null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 15 * 60 * 1000;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPerformance() throws Exception {
+        Random rnd = new GridRandom();
+
+        final IgniteCache<Long,Person> c = ignite.jcache("offheap-cache");
+
+        X.println("___ PUT start");
+
+        final int cnt = 100_000;
+        final int maxSalary = cnt / 10;
+
+        for (long i = 0; i < cnt; i++)
+            c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
+
+        X.println("___ PUT end");
+
+        final AtomicBoolean end = new AtomicBoolean();
+
+        final LongAdder puts = new LongAdder();
+
+        IgniteInternalFuture<?> fut0 = multithreadedAsync(new Callable<Void>()
{
+            @Override public Void call() throws Exception {
+                Random rnd = new GridRandom();
+
+                while (!end.get()) {
+                    long i = rnd.nextInt(cnt);
+
+                    c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
+
+                    puts.increment();
+                }
+
+                return null;
+            }
+        }, 10);
+
+        final LongAdder qrys = new LongAdder();
+
+        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Callable<Void>()
{
+            @Override public Void call() throws Exception {
+                Random rnd = new GridRandom();
+
+                while (!end.get()) {
+                    int salary = rnd.nextInt(maxSalary);
+
+                    c.queryFields(new SqlFieldsQuery("select name from Person where salary
= ?").setArgs(salary))
+                        .getAll();
+
+                    qrys.increment();
+                }
+
+                return null;
+            }
+        }, 10);
+
+        int runTimeSec = 600;
+
+        for (int s = 0; s < runTimeSec; s++) {
+            Thread.sleep(1000);
+
+            long puts0 = puts.sum();
+            long qrys0 = qrys.sum();
+
+            puts.add(-puts0);
+            qrys.add(-qrys0);
+
+            X.println("___ puts: " + puts0 + " qrys: " + qrys0);
+        }
+
+        end.set(true);
+
+        fut0.get();
+        fut1.get();
+
+        X.println("___ STOP");
+    }
+
+    /**
+     *
+     */
+    private static class Person implements Externalizable {
+        /** */
+        @QuerySqlField(index = true)
+        int salary;
+
+        /** */
+        @QuerySqlField
+        String name;
+
+        /**
+         *
+         */
+        public Person() {
+            // No-op.
+        }
+
+        /**
+         * @param salary Salary.
+         * @param name Name.
+         */
+        Person(int salary, String name) {
+            this.salary = salary;
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeInt(salary);
+            U.writeString(out, name);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
+            salary = in.readInt();
+            name = U.readString(in);
+        }
+    }
+}


Mime
View raw message