You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2021/06/25 09:37:43 UTC
[ignite-3] branch ignite-14743-row-formats updated: Add benchmarks
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-14743-row-formats
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-14743-row-formats by this push:
new 40eb4b7 Add benchmarks
40eb4b7 is described below
commit 40eb4b7da96907df7d021716a8fc42394789d521
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Fri Jun 25 12:37:23 2021 +0300
Add benchmarks
---
.../TupleMarshallerFixlenOnlyBenchmark.java | 149 ++++++++++++++++++++
.../TupleMarshallerVarlenOnlyBenchmark.java | 152 +++++++++++++++++++++
2 files changed, 301 insertions(+)
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerFixlenOnlyBenchmark.java b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerFixlenOnlyBenchmark.java
new file mode 100644
index 0000000..aff4b5e
--- /dev/null
+++ b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerFixlenOnlyBenchmark.java
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.Columns;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.schema.marshaller.TupleMarshaller;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.table.TupleBuilderImpl;
+import org.apache.ignite.internal.table.TupleMarshallerImpl;
+import org.apache.ignite.internal.util.Constants;
+import org.apache.ignite.table.Tuple;
+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.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;
+
+import static org.apache.ignite.internal.schema.NativeTypes.LONG;
+
+/**
+ * Serializer benchmark.
+ */
+@State(Scope.Benchmark)
+@Warmup(iterations = 1, time = 15, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 1, time = 30, timeUnit = TimeUnit.SECONDS)
+@BenchmarkMode({Mode.Throughput})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Fork(jvmArgs = "-Djava.lang.invoke.stringConcat=BC_SB" /* Workaround for Java 9+ */, value = 1)
+@SuppressWarnings("InstanceVariableMayNotBeInitialized")
+public class TupleMarshallerFixlenOnlyBenchmark {
+ /** Random. */
+ private Random rnd = new Random();
+
+ /** Tuple marshaller. */
+ private TupleMarshaller marshaller;
+
+ /** Object fields count. */
+ @Param({"1", "10", "100"})
+ public int fieldsCount;
+
+ /** Nullable cols. */
+ @Param({"true", "false"})
+ public boolean nullable;
+
+ /** Schema descriptor. */
+ private SchemaDescriptor schema;
+
+ /** Values. */
+ private Object[] vals;
+
+ /**
+ * Runner.
+ */
+ public static void main(String[] args) throws RunnerException {
+ new Runner(
+ new OptionsBuilder()
+ .include(TupleMarshallerFixlenOnlyBenchmark.class.getSimpleName())
+ .build()
+ ).run();
+ }
+
+ /**
+ *
+ */
+ @Setup
+ public void init() {
+ long seed = System.currentTimeMillis();
+
+ rnd = new Random(seed);
+
+ schema = new SchemaDescriptor(
+ UUID.randomUUID(),
+ 42,
+ new Column[] {new Column("key", LONG, false)},
+ IntStream.range(0, fieldsCount).boxed()
+ .map(i -> new Column("col" + i, LONG, nullable))
+ .toArray(Column[]::new)
+ );
+
+ marshaller = new TupleMarshallerImpl(new SchemaRegistry() {
+ @Override public SchemaDescriptor schema() {
+ return schema;
+ }
+
+ @Override public SchemaDescriptor schema(int ver) {
+ return schema;
+ }
+ });
+
+ vals = new Object[schema.valueColumns().length()];
+
+ for (int i = 0; i < vals.length; i++)
+ vals[i] = rnd.nextLong();
+ }
+
+ /**
+ * Measure tuple build then marshall.
+ *
+ * @param bh Black hole.
+ */
+ @Benchmark
+ public void measureTupleBuildAndMarshallerCost(Blackhole bh) {
+ final Columns cols = schema.valueColumns();
+
+ final TupleBuilderImpl valBld = new TupleBuilderImpl(schema);
+
+ for (int i = 0; i < cols.length(); i++)
+ valBld.set(cols.column(i).name(), vals[i]);
+
+ Tuple keyTuple = new TupleBuilderImpl(schema).set("key", rnd.nextLong()).build();
+
+ final Row row = marshaller.marshal(keyTuple, valBld.build());
+
+ bh.consume(row);
+ }
+}
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java
new file mode 100644
index 0000000..1c071b0
--- /dev/null
+++ b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java
@@ -0,0 +1,152 @@
+/*
+ * 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;
+
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.Columns;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.schema.marshaller.TupleMarshaller;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.table.TupleBuilderImpl;
+import org.apache.ignite.internal.table.TupleMarshallerImpl;
+import org.apache.ignite.table.Tuple;
+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.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;
+
+import static org.apache.ignite.internal.schema.NativeTypes.BYTES;
+import static org.apache.ignite.internal.schema.NativeTypes.LONG;
+
+/**
+ * Serializer benchmark.
+ */
+@State(Scope.Benchmark)
+@Warmup(iterations = 1, time = 15, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 1, time = 30, timeUnit = TimeUnit.SECONDS)
+@BenchmarkMode({Mode.Throughput})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Fork(jvmArgs = "-Djava.lang.invoke.stringConcat=BC_SB" /* Workaround for Java 9+ */, value = 1)
+public class TupleMarshallerVarlenOnlyBenchmark {
+ /** Random. */
+ private Random rnd = new Random();
+
+ /** Tuple marshaller. */
+ private TupleMarshaller marshaller;
+
+ /** Object fields count. */
+ @Param({"2", "10", "100"})
+ public int fieldsCount;
+
+ /** Payload size. */
+ @Param({"250", "64000", "65000"})
+ public int dataSize;
+
+ /** Nullable cols. */
+ @Param({"true", "false"})
+ public boolean nullable;
+
+ /** Schema descriptor. */
+ private SchemaDescriptor schema;
+
+ /** Values. */
+ private byte[] val;
+
+ /**
+ * Runner.
+ */
+ public static void main(String[] args) throws RunnerException {
+ new Runner(
+ new OptionsBuilder()
+ .include(TupleMarshallerVarlenOnlyBenchmark.class.getSimpleName())
+ .build()
+ ).run();
+ }
+
+ /**
+ *
+ */
+ @Setup
+ public void init() {
+ long seed = System.currentTimeMillis();
+
+ rnd = new Random(seed);
+
+ schema = new SchemaDescriptor(
+ UUID.randomUUID(),
+ 42,
+ new Column[] {new Column("key", LONG, false)},
+ IntStream.range(0, fieldsCount).boxed()
+ .map(i -> new Column("col" + i, BYTES, nullable))
+ .toArray(Column[]::new)
+ );
+
+ marshaller = new TupleMarshallerImpl(new SchemaRegistry() {
+ @Override public SchemaDescriptor schema() {
+ return schema;
+ }
+
+ @Override public SchemaDescriptor schema(int ver) {
+ return schema;
+ }
+ });
+
+ val = new byte[dataSize / fieldsCount];
+
+ rnd.nextBytes(val);
+ }
+
+ /**
+ * Measure tuple build then marshall.
+ *
+ * @param bh Black hole.
+ */
+ @Benchmark
+ public void measureTupleBuildAndMarshallerCost(Blackhole bh) {
+ final Columns cols = schema.valueColumns();
+
+ final TupleBuilderImpl valBld = new TupleBuilderImpl(schema);
+
+ for (int i = 0; i < cols.length(); i++)
+ valBld.set(cols.column(i).name(), val);
+
+ Tuple keyTuple = new TupleBuilderImpl(schema).set("key", rnd.nextLong()).build();
+
+ final Row row = marshaller.marshal(keyTuple, valBld.build());
+
+ bh.consume(row);
+ }
+}