-
Notifications
You must be signed in to change notification settings - Fork 328
feat(java): add actor and data batch generator for java bench #3218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
slbotbm
wants to merge
3
commits into
apache:master
Choose a base branch
from
slbotbm:java-benchmarking-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
...n/java/org/apache/iggy/bench/benchmarks/actors/tcp/async/TcpAsyncPinnedProducerActor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * 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.iggy.bench.benchmarks.actors.tcp.async; | ||
|
|
||
| import org.apache.iggy.bench.models.cli.GlobalCliArgs; | ||
| import org.apache.iggy.bench.models.common.generator.DataBatch; | ||
| import org.apache.iggy.client.async.tcp.AsyncIggyTcpClient; | ||
| import org.apache.iggy.identifier.StreamId; | ||
| import org.apache.iggy.identifier.TopicId; | ||
| import org.apache.iggy.message.Partitioning; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CompletionException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public final class TcpAsyncPinnedProducerActor { | ||
|
|
||
| private static final long PARTITION_ID = 0L; | ||
|
|
||
| private final GlobalCliArgs globalCliArgs; | ||
| private final int actorId; | ||
| private final StreamId streamId; | ||
| private final TopicId topicId; | ||
| private final Partitioning partitioning; | ||
| private final DataBatch fullBatch; | ||
| private final long targetMessageBatches; | ||
| private final long targetDataBytes; | ||
| private AsyncIggyTcpClient client; | ||
|
|
||
| public TcpAsyncPinnedProducerActor( | ||
| GlobalCliArgs globalCliArgs, | ||
| int actorId, | ||
| String streamName, | ||
| String topicName, | ||
| DataBatch fullBatch, | ||
| long targetMessageBatches, | ||
| long targetDataBytes) { | ||
| this.globalCliArgs = globalCliArgs; | ||
| this.actorId = actorId; | ||
| this.streamId = StreamId.of(streamName); | ||
| this.topicId = TopicId.of(topicName); | ||
| this.partitioning = Partitioning.partitionId(PARTITION_ID); | ||
| this.fullBatch = fullBatch; | ||
| this.targetMessageBatches = targetMessageBatches; | ||
| this.targetDataBytes = targetDataBytes; | ||
| } | ||
|
|
||
| public CompletableFuture<Void> run() { | ||
| try { | ||
| return AsyncIggyTcpClient.builder() | ||
| .credentials(globalCliArgs.username(), globalCliArgs.password()) | ||
| .buildAndLogin() | ||
| .thenCompose(client -> { | ||
| this.client = client; | ||
| long warmupDeadline = globalCliArgs.warmupTimeMs() <= 0L | ||
| ? 0L | ||
| : System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(globalCliArgs.warmupTimeMs()); | ||
|
|
||
| return sendMessages(warmupDeadline, 0L, 0L) | ||
| .handle((ignored, sendFailure) -> { | ||
| CompletableFuture<Void> closeFuture = client.close(); | ||
|
|
||
| if (sendFailure != null) { | ||
| CompletableFuture<Void> failedAfterClose = | ||
| closeFuture.handle((closeIgnored, closeFailure) -> { | ||
| throw new CompletionException(sendFailure); | ||
| }); | ||
| return failedAfterClose; | ||
| } | ||
|
|
||
| return closeFuture; | ||
| }) | ||
| .thenCompose(future -> future); | ||
| }); | ||
| } catch (RuntimeException exception) { | ||
| return CompletableFuture.failedFuture(exception); | ||
| } | ||
| } | ||
|
|
||
| private CompletableFuture<Void> sendMessages(long warmupDeadline, long sentBatches, long sentBytes) { | ||
| if (warmupDeadline > 0L) { | ||
| if (System.nanoTime() >= warmupDeadline) { | ||
| return sendMessages(0L, 0L, 0L); | ||
| } | ||
|
|
||
| return sendBatch(fullBatch, false) | ||
| .thenCompose(ignored -> sendMessages(warmupDeadline, sentBatches, sentBytes)); | ||
| } | ||
|
|
||
| if (targetDataBytes > 0L ? sentBytes >= targetDataBytes : sentBatches >= targetMessageBatches) { | ||
| return CompletableFuture.completedFuture(null); | ||
| } | ||
|
|
||
| return sendBatch(fullBatch, true).thenCompose(ignored -> { | ||
| long updatedSentBatches = sentBatches + 1L; | ||
| long updatedSentBytes = sentBytes + fullBatch.userDataBytes(); | ||
| return sendMessages(0L, updatedSentBatches, updatedSentBytes); | ||
| }); | ||
| } | ||
|
|
||
| private CompletableFuture<Void> sendBatch(DataBatch currentBatch, boolean recordMetrics) { | ||
| return client.messages().sendMessages(streamId, topicId, partitioning, currentBatch.messages()); | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
.../main/java/org/apache/iggy/bench/benchmarks/runners/tcp/async/TcpAsyncPinnedProducer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * 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.iggy.bench.benchmarks.runners.tcp.async; | ||
|
|
||
| import org.apache.iggy.bench.benchmarks.actors.tcp.async.TcpAsyncPinnedProducerActor; | ||
| import org.apache.iggy.bench.common.generator.BenchmarkBatchGenerator; | ||
| import org.apache.iggy.bench.common.provision.ResourceProvisioner; | ||
| import org.apache.iggy.bench.models.cli.GlobalCliArgs; | ||
| import org.apache.iggy.bench.models.cli.PinnedProducerCliArgs; | ||
| import org.apache.iggy.bench.models.common.generator.DataBatch; | ||
| import org.apache.iggy.bench.models.common.provision.ProvisionedResources; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public final class TcpAsyncPinnedProducer { | ||
|
|
||
| private final GlobalCliArgs globalCliArgs; | ||
| private final PinnedProducerCliArgs pinnedProducerCliArgs; | ||
| private final ResourceProvisioner resourceProvisioner; | ||
| private ProvisionedResources provisionedResources; | ||
|
|
||
| TcpAsyncPinnedProducer( | ||
| GlobalCliArgs globalCliArgs, | ||
| PinnedProducerCliArgs pinnedProducerCliArgs, | ||
| ResourceProvisioner resourceProvisioner) { | ||
| this.globalCliArgs = globalCliArgs; | ||
| this.pinnedProducerCliArgs = pinnedProducerCliArgs; | ||
| this.resourceProvisioner = resourceProvisioner; | ||
|
|
||
| provisionResources(); | ||
| runBenchmark().join(); | ||
| } | ||
|
|
||
| public TcpAsyncPinnedProducer(GlobalCliArgs globalCliArgs, PinnedProducerCliArgs pinnedProducerCliArgs) { | ||
| this(globalCliArgs, pinnedProducerCliArgs, new ResourceProvisioner()); | ||
| } | ||
|
|
||
| private void provisionResources() { | ||
| this.provisionedResources = resourceProvisioner.provisionResources(globalCliArgs, pinnedProducerCliArgs); | ||
| } | ||
|
|
||
| private CompletableFuture<Void> runBenchmark() { | ||
| try { | ||
| String topicName = provisionedResources.topicNames().get(0); | ||
| var batchGenerator = | ||
| new BenchmarkBatchGenerator(globalCliArgs.messageSize(), globalCliArgs.messagesPerBatch()); | ||
| DataBatch fullBatch = batchGenerator.generateBatch(); | ||
| long targetMessageBatches = globalCliArgs.totalData() > 0L ? 0L : globalCliArgs.messageBatches(); | ||
| long targetDataBytes = | ||
| globalCliArgs.totalData() > 0L ? globalCliArgs.totalData() / pinnedProducerCliArgs.producers() : 0L; | ||
| var actorRuns = new CompletableFuture<?>[pinnedProducerCliArgs.producers()]; | ||
|
|
||
| for (int index = 0; index < pinnedProducerCliArgs.producers(); index++) { | ||
| String streamName = provisionedResources.streamNames().get(index); | ||
| var actor = new TcpAsyncPinnedProducerActor( | ||
| globalCliArgs, | ||
| index + 1, | ||
| streamName, | ||
| topicName, | ||
| fullBatch, | ||
| targetMessageBatches, | ||
| targetDataBytes); | ||
| actorRuns[index] = actor.run(); | ||
| } | ||
|
|
||
| return CompletableFuture.allOf(actorRuns); | ||
| } catch (RuntimeException exception) { | ||
| return CompletableFuture.failedFuture(exception); | ||
| } | ||
| } | ||
| } |
51 changes: 0 additions & 51 deletions
51
...ench/src/main/java/org/apache/iggy/bench/benchmarks/tcp/async/TcpAsyncPinnedProducer.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
foreign/java/bench/src/main/java/org/apache/iggy/bench/common/enums/ActorKind.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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.iggy.bench.common.enums; | ||
|
|
||
| public enum ActorKind { | ||
| PRODUCER("producer"), | ||
| CONSUMER("consumer"), | ||
| PRODUCING_CONSUMER("producing_consumer"); | ||
|
|
||
| private final String value; | ||
|
|
||
| ActorKind(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String value() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return value; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
foreign/java/bench/src/main/java/org/apache/iggy/bench/common/enums/BenchmarkKind.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.iggy.bench.common.enums; | ||
|
|
||
| public enum BenchmarkKind { | ||
| PINNED_PRODUCER("pinned_producer"), | ||
| PINNED_CONSUMER("pinned_consumer"), | ||
| PINNED_PRODUCER_AND_CONSUMER("pinned_producer_and_consumer"), | ||
| BALANCED_PRODUCER("balanced_producer"), | ||
| BALANCED_CONSUMER_GROUP("balanced_consumer_group"), | ||
| BALANCED_PRODUCER_AND_CONSUMER_GROUP("balanced_producer_and_consumer_group"), | ||
| END_TO_END_PRODUCING_CONSUMER("end_to_end_producing_consumer"), | ||
| END_TO_END_PRODUCING_CONSUMER_GROUP("end_to_end_producing_consumer_group"); | ||
|
|
||
| private final String value; | ||
|
|
||
| BenchmarkKind(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String value() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return value; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous approach was better. First initialize the object, then call
benchmark.run().