anton-vinogradov commented on PR #13325:
URL: https://github.com/apache/ignite/pull/13325#issuecomment-4876129178
JMH benchmark used for the numbers in the description (not committed; drop
into
`modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/direct/`
and build with `-Pbenchmarks`):
```java
/*
* 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.direct;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.ignite.internal.CoreMessagesProvider;
import
org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
import org.apache.ignite.internal.direct.DirectMessageReader;
import org.apache.ignite.internal.direct.DirectMessageWriter;
import
org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl;
import
org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
import
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GroupPartitionIdPair;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
import
org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
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.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.ignite.marshaller.Marshallers.jdk;
import static org.openjdk.jmh.annotations.Mode.Throughput;
import static org.openjdk.jmh.annotations.Scope.Thread;
/** Benchmarks the {@link DirectMessageReader} compressed-field hot path. */
@State(Thread)
@BenchmarkMode(Throughput)
@Warmup(iterations = 5, time = 3, timeUnit = SECONDS)
@Measurement(iterations = 5, time = 3, timeUnit = SECONDS)
@Fork(1)
public class JmhDirectMessageReaderBenchmark {
/** */
@Param({"30", "500"})
private int entries;
/** */
private DirectMessageReader reader;
/** Fully serialized compressed message, as received from the network. */
private ByteBuffer buf;
/** */
public static void main(String[] args) throws Exception {
JmhIdeBenchmarkRunner.create()
.benchmarks(JmhDirectMessageReaderBenchmark.class.getName())
.run();
}
/** */
@Setup
public void setup() {
MessageFactory msgFactory = msgFactory();
reader = new DirectMessageReader(msgFactory, null);
Map<UUID, Map<GroupPartitionIdPair, Long>> partHistSuppliers = new
HashMap<>();
Map<UUID, Map<Integer, Set<Integer>>> partsToReload = new
HashMap<>();
for (int i = 0; i < entries; i++) {
UUID nodeId = UUID.randomUUID();
partHistSuppliers.put(nodeId, Map.of(new GroupPartitionIdPair(i,
i + 1), i + 2L));
partsToReload.put(nodeId, Map.of(i, Set.of(i + 1)));
}
GridDhtPartitionsFullMessage msg =
new GridDhtPartitionsFullMessage(null, null, new
AffinityTopologyVersion(0), partHistSuppliers, partsToReload);
DirectMessageWriter writer = new DirectMessageWriter(msgFactory);
buf = ByteBuffer.allocate(4 * 1024 * 1024);
writer.setBuffer(buf);
boolean finished = writer.writeMessage(msg, true);
assert finished;
buf.flip();
}
/** Exchange-style compressed message deserialization. */
@Benchmark
public Message compressedMessage() {
buf.rewind();
reader.setBuffer(buf);
Message msg = reader.readMessage(true);
reader.reset();
return msg;
}
/** */
private static MessageFactory msgFactory() {
return new IgniteMessageFactoryImpl(new MessageFactoryProvider[]{
new CoreMessagesProvider(jdk(), jdk(), U.gridClassLoader())});
}
}
```
<details><summary>Full JMH output (master)</summary>
```
JmhDirectMessageReaderBenchmark.compressedMessage
30 thrpt 5 15237,622 ± 34755,482 ops/s
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate
30 thrpt 5 969,148 ± 2210,662 MB/sec
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate.norm
30 thrpt 5 66704,169 ± 0,313 B/op
JmhDirectMessageReaderBenchmark.compressedMessage:gc.count
30 thrpt 5 16,000 counts
JmhDirectMessageReaderBenchmark.compressedMessage:gc.time
30 thrpt 5 1009,000 ms
JmhDirectMessageReaderBenchmark.compressedMessage
500 thrpt 5 4381,361 ± 306,078 ops/s
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate
500 thrpt 5 2183,663 ± 152,540 MB/sec
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate.norm
500 thrpt 5 522632,455 ± 0,030 B/op
JmhDirectMessageReaderBenchmark.compressedMessage:gc.count
500 thrpt 5 98,000 counts
JmhDirectMessageReaderBenchmark.compressedMessage:gc.time
500 thrpt 5 127,000 ms
```
</details>
<details><summary>Full JMH output (patched)</summary>
```
JmhDirectMessageReaderBenchmark.compressedMessage
30 thrpt 5 100917,005 ± 6158,924 ops/s
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate
30 thrpt 5 2429,778 ± 148,288 MB/sec
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate.norm
30 thrpt 5 25248,020 ± 0,001 B/op
JmhDirectMessageReaderBenchmark.compressedMessage:gc.count
30 thrpt 5 109,000 counts
JmhDirectMessageReaderBenchmark.compressedMessage:gc.time
30 thrpt 5 45,000 ms
JmhDirectMessageReaderBenchmark.compressedMessage
500 thrpt 5 5759,704 ± 464,057 ops/s
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate
500 thrpt 5 2366,737 ± 190,712 MB/sec
JmhDirectMessageReaderBenchmark.compressedMessage:gc.alloc.rate.norm
500 thrpt 5 430896,346 ± 0,032 B/op
JmhDirectMessageReaderBenchmark.compressedMessage:gc.count
500 thrpt 5 106,000 counts
JmhDirectMessageReaderBenchmark.compressedMessage:gc.time
500 thrpt 5 42,000 ms
```
</details>
--
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]