zstan commented on code in PR #2955:
URL: https://github.com/apache/ignite-3/pull/2955#discussion_r1427652287


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/benchmark/SqlMultiStatementBenchmark.java:
##########
@@ -0,0 +1,484 @@
+/*
+ * 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.benchmark;
+
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.lang.IgniteStringBuilder;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.InternalSqlRow;
+import org.apache.ignite.internal.sql.engine.QueryProcessor;
+import org.apache.ignite.internal.sql.engine.property.SqlProperties;
+import org.apache.ignite.internal.sql.engine.property.SqlPropertiesHelper;
+import org.apache.ignite.internal.util.AsyncCursor.BatchedResult;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.Session;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.IgniteTransactions;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * Benchmark measures the time for sequential execution of different sets of 
statements and the time
+ * for executing the same set of statements, but running them as a script.
+ *
+ * <p>Include the following cases:
+ * <ol>
+ *     <li>{@code INSERT} the same key into different tables.</li>
+ *     <li>{@code SELECT COUNT(*)} from different tables.</li>
+ *     <li>{@code SELECT} using single key from multiple tables.</li>
+ *     <li>Multiple {@code SELECT} by key from one table.</li>
+ * </ol>
+ */
+@State(Scope.Benchmark)
+@Fork(1)
+@Threads(1)
+@Warmup(iterations = 10, time = 2)
+@Measurement(iterations = 20, time = 2)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+public class SqlMultiStatementBenchmark extends AbstractMultiNodeBenchmark {
+    private static final int TABLE_SIZE = 10_000;
+
+    @Param({"1"})
+    private int clusterSize;
+
+    @Param({"1", "2", "4"})
+    private static int statementsCount;
+
+    /** Creates tables. */
+    @Setup
+    public void createTables() {
+        for (int i = 0; i < statementsCount; i++) {
+            createTable("T" + i);
+        }
+    }
+
+    /** Benchmark for sequential {@code INSERT}. */
+    @Benchmark
+    public void insert(InsertState state, Blackhole bh) {
+        state.executeQuery(bh);
+    }
+
+    /** Benchmark for script {@code INSERT}. */
+    @Benchmark
+    public void insertScript(InsertState state, Blackhole bh) {
+        state.executeScript(bh);
+    }
+
+    /** Benchmark for sequential {@code COUNT}. */
+    @Benchmark
+    public void count(CountState state, Blackhole bh) {
+        state.executeQuery(bh);
+    }
+
+    /** Benchmark for script {@code COUNT}. */
+    @Benchmark
+    public void countScript(CountState state, Blackhole bh) {
+        state.executeScript(bh);
+    }
+
+    /** Benchmark for sequential single key {@code SELECT}. */
+    @Benchmark
+    public void selectMultipleTables(SelectSingleKeyMultipleTablesState state, 
Blackhole bh) {
+        state.executeQuery(bh);
+    }
+
+    /** Benchmark for script single key {@code SELECT}. */
+    @Benchmark
+    public void selectMultipleTablesScript(SelectSingleKeyMultipleTablesState 
state, Blackhole bh) {
+        state.executeScript(bh);
+    }
+
+    /** Benchmark for sequential single table {@code SELECT}. */
+    @Benchmark
+    public void selectMultipleKeys(SelectMultipleKeysSingleTableState state, 
Blackhole bh) {
+        state.executeQuery(bh);
+    }
+
+    /** Benchmark for script single table {@code SELECT}. */
+    @Benchmark
+    public void selectMultipleKeysScript(SelectMultipleKeysSingleTableState 
state, Blackhole bh) {
+        state.executeScript(bh);
+    }
+
+    /**
+     * Benchmark state for {@link #insert(InsertState, Blackhole)} and
+     * {@link #insertScript(InsertState, Blackhole)} benchmarks.
+     */
+    @State(Scope.Benchmark)
+    public static class InsertState {
+        private ScriptRunner scriptExec;
+        private Parameters parameters;
+        private Session session;
+
+        /** Generates required statements.*/
+        @Setup
+        public void setUp() {
+            session = clusterNode.sql().createSession();
+            parameters = new Parameters(statementsCount, n -> 
createInsertStatement("T" + n));
+            scriptExec = new ScriptRunner(
+                    clusterNode.queryEngine(),
+                    clusterNode.transactions(),
+                    session.defaultPageSize()
+            );
+        }
+
+        @TearDown
+        public void closeSession() throws Exception {
+            IgniteUtils.closeAll(session);
+        }
+
+        private int id = 0;
+
+        void executeQuery(Blackhole bh) {
+            int id0 = id++;
+
+            for (int i = 0; i < statementsCount; i++) {
+                try (ResultSet<?> rs = session.execute(null, 
parameters.statements.get(i), id0)) {
+                    // NO-OP

Review Comment:
   bh.consume(rs);



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to