From 9502400e348c8a0184ff11a26a3c0ed893bb4d82 Mon Sep 17 00:00:00 2001 From: oleg-ostanin Date: Wed, 12 Jul 2017 14:06:32 +0300 Subject: [PATCH 1/3] IGNITE-5740 created new benchmark for load transaction --- .../yardstick/IgniteBenchmarkArguments.java | 33 ++++++ .../cache/IgnitePutTxLoadBenchmark.java | 107 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.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 5ec6c54c53551..594fa1f1b5907 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 @@ -208,6 +208,18 @@ public class IgniteBenchmarkArguments { @Parameter(names = {"-ps", "--pageSize"}, description = "Page size") private int pageSize = MemoryConfiguration.DFLT_PAGE_SIZE; + /** */ + @Parameter(names = {"-sl", "--stringLength"}, description = "Test string length") + private int stringLength = 500; + + /** */ + @Parameter(names = {"-wt", "--warningTime"}, description = "Warning time interval for printing log") + private long warningTime = 500; + + /** */ + @Parameter(names = {"-prb", "--printRollBacks"}, description = "Print rollBacks") + private boolean printRollBacks; + /** */ @Parameter(names = {"-prt", "--partitions"}, description = "Number of cache partitions") private int partitions = 10; @@ -506,6 +518,27 @@ public int getPageSize() { return pageSize; } + /** + * @return Test string length. + */ + public int getStringLength() { + return stringLength; + } + + /** + * @return Warning time interval. + */ + public long getWarningTime() { + return warningTime; + } + + /** + * @return Flag for printing rollbacks. + */ + public boolean printRollBacks() { + return printRollBacks; + } + /** * @return Number of partitioned caches. */ diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java new file mode 100644 index 0000000000000..6c15589d4431c --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java @@ -0,0 +1,107 @@ +/* + * 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 java.util.ArrayList; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.IgniteTransactions; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionMetrics; +import org.yardstickframework.BenchmarkConfiguration; +import org.yardstickframework.BenchmarkUtils; + +/** + * Ignite benchmark that performs transactional load put operations. + */ +public class IgnitePutTxLoadBenchmark extends IgniteCacheAbstractBenchmark { + /** */ + private ArrayList> cacheList; + + /** */ + private String val; + + /** */ + private Random random; + + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + if (!IgniteSystemProperties.getBoolean("SKIP_MAP_CHECK")) + ignite().compute().broadcast(new WaitMapExchangeFinishCallable()); + + cacheList = new ArrayList<>(args.cachesCount()); + + for (int i = 0; i < args.cachesCount(); i++) + cacheList.add(ignite().cache("tx-" + i)); + + val = createVal(args.getStringLength()); + + random = new Random(); + } + + /** {@inheritDoc} */ + @Override public boolean test(Map ctx) throws Exception { + IgniteTransactions transactions = ignite().transactions(); + + long startTime; + + try (Transaction tx = transactions.txStart(args.txConcurrency(), args.txIsolation())) { + for (int i = 0; i < args.scaleFactor(); i++){ + IgniteCache curCache = cacheList.get(random.nextInt(cacheList.size())); + curCache.put(random.nextLong(), val); + } + + startTime = System.currentTimeMillis(); + + tx.commit(); + } + + TransactionMetrics tm = transactions.metrics(); + + if (tm.commitTime() - startTime > args.getWarningTime()) + BenchmarkUtils.println("Transaction commit time = " + (tm.commitTime() - startTime)); + + if (tm.txRollbacks() > 0 && args.printRollBacks()) + BenchmarkUtils.println("Transaction rollbacks = " + tm.txRollbacks()); + + return true; + } + + /** {@inheritDoc} */ + @Override protected IgniteCache cache() { + return ignite().cache("tx"); + } + + /** + * Creates String val + * @param lgth String length + * @return String for inserting in cache + */ + private String createVal(int lgth){ + StringBuilder sb = new StringBuilder(lgth); + + for(int i = 0; i < lgth; i++) + sb.append('x'); + + return sb.toString(); + } +} From 2d76a6f6d0e40c7a4b71651acf21aea4439ace70 Mon Sep 17 00:00:00 2001 From: oleg-ostanin Date: Wed, 12 Jul 2017 15:40:39 +0300 Subject: [PATCH 2/3] IGNITE-5740 changed transaction end time definition --- .../ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java index 6c15589d4431c..22f85a8dee8e8 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java @@ -63,6 +63,7 @@ public class IgnitePutTxLoadBenchmark extends IgniteCacheAbstractBenchmark args.getWarningTime()) + if (endTime - startTime > args.getWarningTime()) BenchmarkUtils.println("Transaction commit time = " + (tm.commitTime() - startTime)); if (tm.txRollbacks() > 0 && args.printRollBacks()) From 48c438100b0aee1c9c803c333166bb29bae784b4 Mon Sep 17 00:00:00 2001 From: oleg-ostanin Date: Wed, 12 Jul 2017 15:52:34 +0300 Subject: [PATCH 3/3] IGNITE-5740 added list for sorting keys before transaction --- .../yardstick/cache/IgnitePutTxLoadBenchmark.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java index 22f85a8dee8e8..dc2547c656089 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgnitePutTxLoadBenchmark.java @@ -18,6 +18,8 @@ package org.apache.ignite.yardstick.cache; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.Random; import org.apache.ignite.IgniteCache; @@ -66,9 +68,16 @@ public class IgnitePutTxLoadBenchmark extends IgniteCacheAbstractBenchmark keyList = new ArrayList<>(args.scaleFactor()); + + for (int i = 0; i < args.scaleFactor(); i++) + keyList.add(random.nextLong()); + + Collections.sort(keyList); + for (int i = 0; i < args.scaleFactor(); i++){ IgniteCache curCache = cacheList.get(random.nextInt(cacheList.size())); - curCache.put(random.nextLong(), val); + curCache.put(keyList.get(i), val); } startTime = System.currentTimeMillis();