ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: Added benchmark.
Date Fri, 20 Jan 2017 08:54:05 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3477 670011b3d -> c47d0316b


Added benchmark.


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

Branch: refs/heads/ignite-3477
Commit: c47d0316b581583009fde97ffdf7f8310a936ba5
Parents: 670011b
Author: sboikov <sboikov@gridgain.com>
Authored: Fri Jan 20 11:54:09 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Fri Jan 20 11:54:09 2017 +0300

----------------------------------------------------------------------
 .../benchmarks/jmh/tree/BPlusTreeBenchmark.java | 333 +++++++++++++++++++
 1 file changed, 333 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c47d0316/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java
b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java
new file mode 100644
index 0000000..d1bca73
--- /dev/null
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/tree/BPlusTreeBenchmark.java
@@ -0,0 +1,333 @@
+/*
+ * 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.tree;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.benchmarks.jmh.JmhAbstractBenchmark;
+import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
+import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider;
+import org.apache.ignite.internal.pagemem.FullPageId;
+import org.apache.ignite.internal.pagemem.PageIdAllocator;
+import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.PageUtils;
+import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
+import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
+import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
+import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
+import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
+import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions;
+import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
+import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag;
+import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
+import org.apache.ignite.logger.java.JavaLogger;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/**
+ *
+ */
+@State(Scope.Benchmark)
+public class BPlusTreeBenchmark extends JmhAbstractBenchmark {
+    /** */
+    private static final short LONG_INNER_IO = 30000;
+
+    /** */
+    private static final short LONG_LEAF_IO = 30001;
+
+    /** */
+    private static final int PAGE_SIZE = 256;
+
+    /** */
+    private static final long MB = 1024 * 1024;
+
+    /** */
+    private static final int CPUS = Runtime.getRuntime().availableProcessors();
+
+    /** */
+    static int MAX_PER_PAGE = 0;
+
+    /** */
+    private static final int CACHE_ID = 100500;
+
+    /** */
+    private static final int KEYS = 1_000_000;
+
+    /** */
+    private TestTree tree;
+
+    /** */
+    private PageMemory pageMem;
+
+    /**
+     * Fake reuse list.
+     */
+    private static class FakeReuseList implements ReuseList {
+        /** */
+        private final ConcurrentLinkedDeque<Long> deque = new ConcurrentLinkedDeque<>();
+
+        /** {@inheritDoc} */
+        @Override public void addForRecycle(ReuseBag bag) throws IgniteCheckedException {
+            long pageId;
+
+            while ((pageId = bag.pollFreePage()) != 0L)
+                deque.addFirst(pageId);
+        }
+
+        /** {@inheritDoc} */
+        @Override public long takeRecycledPage() throws IgniteCheckedException {
+            Long pageId = deque.pollFirst();
+
+            return pageId == null ? 0L : pageId;
+        }
+
+        /** {@inheritDoc} */
+        @Override public long recycledPagesCount() throws IgniteCheckedException {
+            return deque.size();
+        }
+    }
+
+    /**
+     * @return Allocated meta page ID.
+     * @throws IgniteCheckedException If failed.
+     */
+    private FullPageId allocateMetaPage() throws IgniteCheckedException {
+        return new FullPageId(pageMem.allocatePage(CACHE_ID, PageIdAllocator.INDEX_PARTITION,
PageIdAllocator.FLAG_IDX), CACHE_ID);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Setup
+    public void setup() throws Exception {
+        pageMem = createPageMemory();
+
+        tree = new TestTree(new FakeReuseList(), CACHE_ID, pageMem, allocateMetaPage().pageId());
+
+        for (long l = 0; l < KEYS; l++)
+            tree.put(l);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @TearDown
+    public void tearDown() throws Exception {
+        tree.destroy();
+
+        pageMem.stop();
+    }
+
+    /**
+     * @throws Exception If failed.
+     * @return Value.
+     */
+    @Benchmark
+    public Long get() throws Exception {
+        Long key = ThreadLocalRandom.current().nextLong(KEYS);
+
+        return tree.findOne(key);
+    }
+
+    /**
+     * @throws Exception If failed.
+     * @return Value.
+     */
+    @Benchmark
+    public Long put() throws Exception {
+        Long key = ThreadLocalRandom.current().nextLong(KEYS);
+
+        return tree.put(key);
+    }
+
+    /**
+     * Test tree.
+     */
+    protected static class TestTree extends BPlusTree<Long, Long> {
+        /**
+         * @param reuseList Reuse list.
+         * @param cacheId Cache ID.
+         * @param pageMem Page memory.
+         * @param metaPageId Meta page ID.
+         * @throws IgniteCheckedException If failed.
+         */
+        TestTree(ReuseList reuseList, int cacheId, PageMemory pageMem, long metaPageId)
+            throws IgniteCheckedException {
+            super("test", cacheId, pageMem, null, new AtomicLong(), metaPageId, reuseList,
+                new IOVersions<>(new LongInnerIO()), new IOVersions<>(new LongLeafIO()));
+
+            PageIO.registerTest(latestInnerIO(), latestLeafIO());
+
+            initTree(true);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected int compare(BPlusIO<Long> io, long pageAddr, int idx, Long
n2)
+            throws IgniteCheckedException {
+            Long n1 = io.getLookupRow(this, pageAddr, idx);
+
+            return Long.compare(n1, n2);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Long getRow(BPlusIO<Long> io, long pageAddr, int idx) throws
IgniteCheckedException {
+            assert io.canGetRow() : io;
+
+            return io.getLookupRow(this, pageAddr, idx);
+        }
+    }
+
+    /**
+     * @return Page memory.
+     * @throws Exception If failed.
+     */
+    private PageMemory createPageMemory() throws Exception {
+        long[] sizes = new long[CPUS];
+
+        for (int i = 0; i < sizes.length; i++)
+            sizes[i] = 1024 * MB / CPUS;
+
+        PageMemory pageMem = new PageMemoryNoStoreImpl(new JavaLogger(),
+            new UnsafeMemoryProvider(sizes),
+            null,
+            PAGE_SIZE,
+            false);
+
+        pageMem.start();
+
+        return pageMem;
+    }
+
+    /**
+     * Run benchmarks.
+     *
+     * @param args Arguments.
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        run(8);
+    }
+
+    /**
+     * Run benchmark.
+     *
+     * @param threads Amount of threads.
+     * @throws Exception If failed.
+     */
+    private static void run(int threads) throws Exception {
+        JmhIdeBenchmarkRunner.create()
+            .forks(1)
+            .threads(threads)
+            .warmupIterations(10)
+            .measurementIterations(10)
+            .benchmarks(BPlusTreeBenchmark.class.getSimpleName())
+            .jvmArguments("-Xms4g", "-Xmx4g")
+            .run();
+    }
+
+    /**
+     * Long inner.
+     */
+    private static final class LongInnerIO extends BPlusInnerIO<Long> {
+        /**
+         */
+        LongInnerIO() {
+            super(LONG_INNER_IO, 1, true, 8);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int getMaxCount(long buf, int pageSize) {
+            if (MAX_PER_PAGE != 0)
+                return MAX_PER_PAGE;
+
+            return super.getMaxCount(buf, pageSize);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void store(long dst, int dstIdx, BPlusIO<Long> srcIo, long
src, int srcIdx)
+            throws IgniteCheckedException {
+            Long row = srcIo.getLookupRow(null, src, srcIdx);
+
+            store(dst, dstIdx, row, null);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void storeByOffset(ByteBuffer buf, int off, Long row) throws IgniteCheckedException
{
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void storeByOffset(long pageAddr, int off, Long row) {
+            PageUtils.putLong(pageAddr, off, row);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Long getLookupRow(BPlusTree<Long,?> tree, long pageAddr, int
idx)
+            throws IgniteCheckedException {
+            return PageUtils.getLong(pageAddr, offset(idx));
+        }
+    }
+
+    /**
+     * Long leaf.
+     */
+    private static final class LongLeafIO extends BPlusLeafIO<Long> {
+        /**
+         */
+        LongLeafIO() {
+            super(LONG_LEAF_IO, 1, 8);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int getMaxCount(long pageAddr, int pageSize) {
+            if (MAX_PER_PAGE != 0)
+                return MAX_PER_PAGE;
+
+            return super.getMaxCount(pageAddr, pageSize);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void storeByOffset(ByteBuffer buf, int off, Long row) throws IgniteCheckedException
{
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void storeByOffset(long pageAddr, int off, Long row) {
+            PageUtils.putLong(pageAddr, off, row);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void store(long dst, int dstIdx, BPlusIO<Long> srcIo, long
src, int srcIdx) {
+            assert srcIo == this;
+
+            PageUtils.putLong(dst, offset(dstIdx), PageUtils.getLong(src, offset(srcIdx)));
+        }
+
+        /** {@inheritDoc} */
+        @Override public Long getLookupRow(BPlusTree<Long,?> tree, long pageAddr, int
idx)
+            throws IgniteCheckedException {
+            return PageUtils.getLong(pageAddr, offset(idx));
+        }
+    }
+}


Mime
View raw message