-
Notifications
You must be signed in to change notification settings - Fork 354
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
Provides Prioritised delivering of Zero Streams Frames #718
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08cefe0
prioritization
OlegDokuka 111a3b8
provides prioritized sending for zero-stream frames; refactors benchm…
OlegDokuka 37142ea
provides minor cleanups
OlegDokuka 922effd
more fixes
OlegDokuka 70ec02e
fixes format
OlegDokuka 39a74d7
fixes
OlegDokuka 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
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
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
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
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ public final class UnboundedProcessor<T> extends FluxProcessor<T, T> | |
AtomicLongFieldUpdater.newUpdater(UnboundedProcessor.class, "requested"); | ||
|
||
final Queue<T> queue; | ||
final Queue<T> priorityQueue; | ||
volatile boolean done; | ||
Throwable error; | ||
volatile CoreSubscriber<? super T> actual; | ||
|
@@ -67,11 +68,12 @@ public final class UnboundedProcessor<T> extends FluxProcessor<T, T> | |
|
||
public UnboundedProcessor() { | ||
this.queue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE); | ||
this.priorityQueue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE); | ||
} | ||
|
||
@Override | ||
public int getBufferSize() { | ||
return Queues.capacity(this.queue); | ||
return Integer.MAX_VALUE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
} | ||
|
||
@Override | ||
|
@@ -84,6 +86,7 @@ void drainRegular(Subscriber<? super T> a) { | |
int missed = 1; | ||
|
||
final Queue<T> q = queue; | ||
final Queue<T> pq = priorityQueue; | ||
|
||
for (; ; ) { | ||
|
||
|
@@ -93,10 +96,18 @@ void drainRegular(Subscriber<? super T> a) { | |
while (r != e) { | ||
boolean d = done; | ||
|
||
T t = q.poll(); | ||
boolean empty = t == null; | ||
T t; | ||
boolean empty; | ||
|
||
if (!pq.isEmpty()) { | ||
t = pq.poll(); | ||
empty = false; | ||
} else { | ||
t = q.poll(); | ||
empty = t == null; | ||
} | ||
|
||
if (checkTerminated(d, empty, a, q)) { | ||
if (checkTerminated(d, empty, a)) { | ||
return; | ||
} | ||
|
||
|
@@ -110,7 +121,7 @@ void drainRegular(Subscriber<? super T> a) { | |
} | ||
|
||
if (r == e) { | ||
if (checkTerminated(done, q.isEmpty(), a, q)) { | ||
if (checkTerminated(done, q.isEmpty() && pq.isEmpty(), a)) { | ||
return; | ||
} | ||
} | ||
|
@@ -129,12 +140,10 @@ void drainRegular(Subscriber<? super T> a) { | |
void drainFused(Subscriber<? super T> a) { | ||
int missed = 1; | ||
|
||
final Queue<T> q = queue; | ||
|
||
for (; ; ) { | ||
|
||
if (cancelled) { | ||
q.clear(); | ||
clear(); | ||
actual = null; | ||
return; | ||
} | ||
|
@@ -188,14 +197,9 @@ public void drain() { | |
} | ||
} | ||
|
||
boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> a, Queue<T> q) { | ||
boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> a) { | ||
if (cancelled) { | ||
while (!q.isEmpty()) { | ||
T t = q.poll(); | ||
if (t != null) { | ||
release(t); | ||
} | ||
} | ||
clear(); | ||
actual = null; | ||
return true; | ||
} | ||
|
@@ -237,6 +241,23 @@ public Context currentContext() { | |
return actual != null ? actual.currentContext() : Context.empty(); | ||
} | ||
|
||
public void onNextPrioritized(T t) { | ||
if (done || cancelled) { | ||
Operators.onNextDropped(t, currentContext()); | ||
release(t); | ||
return; | ||
} | ||
|
||
if (!priorityQueue.offer(t)) { | ||
Throwable ex = | ||
Operators.onOperatorError(null, Exceptions.failWithOverflow(), t, currentContext()); | ||
onError(Operators.onOperatorError(null, ex, t, currentContext())); | ||
release(t); | ||
return; | ||
} | ||
drain(); | ||
} | ||
|
||
@Override | ||
public void onNext(T t) { | ||
if (done || cancelled) { | ||
|
@@ -319,25 +340,24 @@ public void cancel() { | |
} | ||
} | ||
|
||
@Override | ||
public T peek() { | ||
return queue.peek(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public T poll() { | ||
Queue<T> pq = this.priorityQueue; | ||
if (!pq.isEmpty()) { | ||
return pq.poll(); | ||
} | ||
return queue.poll(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return queue.size(); | ||
return priorityQueue.size() + queue.size(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return queue.isEmpty(); | ||
return priorityQueue.isEmpty() && queue.isEmpty(); | ||
} | ||
|
||
@Override | ||
|
@@ -348,6 +368,12 @@ public void clear() { | |
release(t); | ||
} | ||
} | ||
while (!priorityQueue.isEmpty()) { | ||
T t = priorityQueue.poll(); | ||
if (t != null) { | ||
release(t); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
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
20 changes: 0 additions & 20 deletions
20
rsocket-core/src/main/java/io/rsocket/internal/jctools/queues/SupportsIterator.java
This file was deleted.
Oops, something went wrong.
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
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.
We should tighten this up in the spec, whether it's stream 0 prioritised or KEEPALIVE and LEASE only as you have implemented. I'll generally defer to @robertroeser for this, but put my thoughts on the issue.
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.
Definitely. I have already created an issue on that!