Skip to content

General performance improvements #598

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

Merged
merged 6 commits into from
Mar 17, 2019

Conversation

OlegDokuka
Copy link
Member

@OlegDokuka OlegDokuka commented Mar 17, 2019

This PR provides a list of dramatical performance improvements:

  1. Reduce the number of used Atomics within the code base. As you can see in PR, there were a few places with applied first elements strategy. In all of those cases, usage of atomic was redundant since Reactive-Streams spec and Reactors implementation guarantees happens-before and serialized access to the object (Subscriber / Subscription) so having an additional object with volatile access is redundant and give more overhead
  2. Reduce the number of allocated objects. In many cases, we use too many Reactors operators where actual logic can be implemented within one BaseSubscriber. Thus, this PR eliminates redundant transformations and minimize function flow. Also, dynamic invocations give its overhead, so there are upcoming changes in Reactor 3 (Macro-fusion in primitive operators reactor/reactor-core#1556) that improves performance as well.
  3. Simplifies Lifecycle to more specific cases, so the number of used operators (hence allocated objects) also is reduced to the minimum.

General bugfixes and improvements

Along with performance improvements, this PR introduces Jmh tests so you can run benchmarks locally and observe 10-20% perf improvements comparing to the previous implementation.

Finally, this PR provides a couple of bugfixes found during development and testing

Signed-off-by: Oleh Dokuka [email protected]

@@ -490,8 +493,7 @@ private void handleFrame(int streamId, FrameType type, ByteBuf frame) {
LimitableRequestPublisher sender = senders.get(streamId);
if (sender != null) {
int n = RequestNFrameFlyweight.requestN(frame);
sender.increaseRequestLimit(n);
sendProcessor.drain();
sender.request(n >= Integer.MAX_VALUE ? Long.MAX_VALUE : n);
Copy link
Member

@yschimke yschimke Mar 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tangential: I'm trying to remember where we specify this rule? Integer.MAX_VALUE == Inifinite? Reactor? Reactive Streams? RSocket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what I'm asking is whether this rule needs to migrate into the spec

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not clarify that Int. Max Value should be considered as unbounded stream, then we have to mention that

@yschimke
Copy link
Member

Nice perf win!

Copy link
Member

@yschimke yschimke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - passing tests. One question about a release.

Signed-off-by: Oleh Dokuka <[email protected]>
Signed-off-by: Oleh Dokuka <[email protected]>
@OlegDokuka OlegDokuka removed the WIP label Mar 17, 2019
Signed-off-by: Oleh Dokuka <[email protected]>
@OlegDokuka OlegDokuka force-pushed the feature/performance-improvements branch from f282b76 to 12669c7 Compare March 17, 2019 15:42
Signed-off-by: Oleh Dokuka <[email protected]>
@robertroeser robertroeser merged commit f55cf8f into develop Mar 17, 2019
@robertroeser robertroeser deleted the feature/performance-improvements branch March 21, 2019 23:13
mostroverkhov added a commit that referenced this pull request Apr 5, 2019
mostroverkhov added a commit that referenced this pull request Apr 5, 2019
This reverts commit f55cf8f

Signed-off-by: Maksym Ostroverkhov <[email protected]>
robertroeser pushed a commit that referenced this pull request Apr 7, 2019
* channel load test

* Revert "General performance improvements (#598)"

This reverts commit f55cf8f

* use byte-count for frame positions

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* resume token is ByteBuf

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* Keep-alive connection, receiving remote implied position: replace Flux with simple onRemoteImpliedPosition(long) callback

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* better performance with resume on

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* keep alive handler: less allocations

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* remove ResumptionState to reduce allocations

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* remove ResumedFramesCalculator

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* rename ResumeAwareConnection to ResumePositionsConnection

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* ResumableDuplexConnection: use drain-queue for actions

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* tests

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* formatter

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* cleanup: resume token is released in ClientRSocketSession instead of
         RSocketFactory

         KeepAliveConnection: dispose KeepAliveHandler in onClose()

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* reduce allocations

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* resume: fix race between send / release of frames on received implied position from keepalives

replace state enum with constants

remove unnecessary allocation

make cleanup of store on keep-alive optional

formatter

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* remove unintended changes

Signed-off-by: Maksym Ostroverkhov <[email protected]>

* optimize KeepAliveConnection

optimize ResumableDuplexConnection

Signed-off-by: Maksym Ostroverkhov <[email protected]>
mostroverkhov added a commit that referenced this pull request May 16, 2019
mostroverkhov added a commit that referenced this pull request May 16, 2019
This reverts commit f55cf8f

Signed-off-by: Maksym Ostroverkhov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants