-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reworks FluxPublish internals to relay on predictable state machine #3538
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a428c5
more changes
7dd2b28
fixes
7284be7
fixes
931d470
fixes
e824062
fixes
1d93148
more changes
95185dc
fixes
714b633
fixes
e73d3cb
fixes
6d1c8a7
fixes
fb69884
adds jmh test
58b0e42
fixes spotless
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
106 changes: 106 additions & 0 deletions
106
benchmarks/src/main/java/reactor/core/publisher/FluxPublishBenchmark.java
This file contains 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,106 @@ | ||
/* | ||
* Copyright (c) 2023 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 reactor.core.publisher; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
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.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.reactivestreams.Subscription; | ||
import reactor.core.CoreSubscriber; | ||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Fork(value = 1) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
public class FluxPublishBenchmark { | ||
@Param({"0", "10", "1000", "100000"}) | ||
int rangeSize; | ||
|
||
Flux<Integer> source; | ||
|
||
@Setup(Level.Invocation) | ||
public void setup() { | ||
source = Flux.range(0, rangeSize) | ||
.hide() | ||
.publish() | ||
.autoConnect(Runtime.getRuntime() | ||
.availableProcessors()); | ||
} | ||
|
||
|
||
@State(Scope.Thread) | ||
public static class JmhSubscriber<T> extends CountDownLatch implements CoreSubscriber<T> { | ||
|
||
Blackhole blackhole; | ||
|
||
Subscription s; | ||
|
||
public JmhSubscriber() { | ||
super(1); | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Subscription s) { | ||
if (Operators.validate(this.s, s)) { | ||
this.s = s; | ||
s.request(Long.MAX_VALUE); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNext(T t) { | ||
blackhole.consume(t); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
blackhole.consume(t); | ||
countDown(); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
countDown(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@Benchmark | ||
@Threads(Threads.MAX) | ||
public Object measureThroughput(Blackhole blackhole, JmhSubscriber<Integer> subscriber) throws InterruptedException { | ||
subscriber.blackhole = blackhole; | ||
source.subscribe(subscriber); | ||
subscriber.await(); | ||
return subscriber; | ||
} | ||
} |
This file contains 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
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.
Can we add tests that validate the changes?
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.
WDYM? For now discard is weak and the commented test is going to fail
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.
we can uncomment the test once we have an explicit discard hook for hot producers. E.g.
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.
What I mean is just: do we have any way to show these changes improve anything? Is improper discarding the only flaw right now? It would seem there can be regular omissions to deliver items due to improper concurrency handling right now. The original issue for refCount had a test suggestion validating the delivery of signals is appropriate, can we use a similar test for publish?
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.
oh, right. I wanted to perform jmh test. Will post results in a moment
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.
@chemicL added reasoning for this PR in the header.