Repository: incubator-ignite Updated Branches: refs/heads/yard-client-thread [created] 7ae1470a5
#Yardstick Added benchmarks for clients. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7ae1470a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7ae1470a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7ae1470a Branch: refs/heads/yard-client-thread Commit: 7ae1470a559d8aa7ee3ee977ddb7e2df9c82b9b0 Parents: 928be42 Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Wed Jun 10 10:25:41 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Wed Jun 10 10:25:41 2015 +0300 ---------------------------------------------------------------------- .../IgnitePutGetClientPerThreadBenchmark.java | 78 +++++++++++++++++ .../IgnitePutGetTxClientPerThreadBenchmark.java | 89 ++++++++++++++++++++ 2 files changed, 167 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ae1470a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetClientPerThreadBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetClientPerThreadBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetClientPerThreadBenchmark.java new file mode 100644 index 0000000..e33b7b7 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetClientPerThreadBenchmark.java @@ -0,0 +1,78 @@ +/* + * 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 org.apache.ignite.*; +import org.apache.ignite.yardstick.*; +import org.apache.ignite.yardstick.cache.model.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * Ignite benchmark that performs put and get operations. + */ +public class IgnitePutGetClientPerThreadBenchmark extends IgniteCacheAbstractBenchmark { + /** Id sequence. */ + private AtomicInteger idSeq = new AtomicInteger(0); + + /** Nodes. */ + private Map<Integer, IgniteNode> nodes = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + IgniteCache<Integer, Object> cache = (IgniteCache<Integer, Object>)ctx.get(0); + + if (cache == null) { + IgniteNode node = new IgniteNode(true); + + node.start(cfg); + + cache = node.ignite().cache("atomic"); + + ctx.put(0, cache); + + nodes.put(idSeq.getAndIncrement(), node); + } + + int key = nextRandom(args.range()); + + Object val = cache.get(key); + + if (val != null) + key = nextRandom(args.range()); + + cache.put(key, new SampleValue(key)); + + return true; + } + + /** {@inheritDoc} */ + @Override public void tearDown() throws Exception { + for (IgniteNode node : nodes.values()) + node.stop(); + + super.tearDown(); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Integer, Object> cache() { + return ignite().cache("atomic"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ae1470a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxClientPerThreadBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxClientPerThreadBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxClientPerThreadBenchmark.java new file mode 100644 index 0000000..5f89e37 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutGetTxClientPerThreadBenchmark.java @@ -0,0 +1,89 @@ +/* + * 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 org.apache.ignite.*; +import org.apache.ignite.transactions.*; +import org.apache.ignite.yardstick.*; +import org.apache.ignite.yardstick.cache.model.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * Ignite benchmark that performs transactional put and get operations. + */ +public class IgnitePutGetTxClientPerThreadBenchmark extends IgniteCacheAbstractBenchmark { + /** Id sequence. */ + private AtomicInteger idSeq = new AtomicInteger(0); + + /** Nodes. */ + private Map<Integer, IgniteNode> nodes = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + IgniteCache<Integer, Object> cache = (IgniteCache<Integer, Object>)ctx.get(0); + + Ignite ignite = (Ignite)ctx.get(1); + + if (cache == null || ignite == null) { + IgniteNode node = new IgniteNode(true); + + node.start(cfg); + + ignite = node.ignite(); + + cache = node.ignite().cache("tx"); + + ctx.put(0, cache); + + ctx.put(1, ignite); + + nodes.put(idSeq.getAndIncrement(), node); + } + + int key = nextRandom(0, args.range() / 2); + + try (Transaction tx = ignite.transactions().txStart()) { + Object val = cache.get(key); + + if (val != null) + key = nextRandom(args.range() / 2, args.range()); + + cache.put(key, new SampleValue(key)); + + tx.commit(); + } + + return true; + } + + /** {@inheritDoc} */ + @Override public void tearDown() throws Exception { + for (IgniteNode node : nodes.values()) + node.stop(); + + super.tearDown(); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Integer, Object> cache() { + return ignite().cache("tx"); + } +}