-
Notifications
You must be signed in to change notification settings - Fork 357
perf changes #552
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
perf changes #552
Changes from all commits
a2facb3
b2023ff
c3c5c47
0aafe02
514b680
0c544aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,4 @@ | |
| # limitations under the License. | ||
| # | ||
|
|
||
| version=0.11.13.BUILD-SNAPSHOT | ||
| version=0.11.14.BUILD-SNAPSHOT | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,23 +16,29 @@ | |
|
|
||
| package io.rsocket; | ||
|
|
||
| import static io.rsocket.Frame.Request.initialRequestN; | ||
| import static io.rsocket.frame.FrameHeaderFlyweight.FLAGS_C; | ||
| import static io.rsocket.frame.FrameHeaderFlyweight.FLAGS_M; | ||
|
|
||
| import io.netty.util.collection.IntObjectHashMap; | ||
| import io.rsocket.exceptions.ApplicationErrorException; | ||
| import io.rsocket.exceptions.ConnectionErrorException; | ||
| import io.rsocket.framing.FrameType; | ||
| import io.rsocket.internal.LimitableRequestPublisher; | ||
| import io.rsocket.internal.UnboundedProcessor; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
| import org.jctools.maps.NonBlockingHashMapLong; | ||
| import org.reactivestreams.Publisher; | ||
| import org.reactivestreams.Subscriber; | ||
| import org.reactivestreams.Subscription; | ||
| import reactor.core.Disposable; | ||
| import reactor.core.publisher.*; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.core.publisher.Mono; | ||
| import reactor.core.publisher.SignalType; | ||
| import reactor.core.publisher.UnicastProcessor; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
||
| import static io.rsocket.Frame.Request.initialRequestN; | ||
| import static io.rsocket.frame.FrameHeaderFlyweight.FLAGS_C; | ||
| import static io.rsocket.frame.FrameHeaderFlyweight.FLAGS_M; | ||
|
|
||
| /** Server side RSocket. Receives {@link Frame}s from a {@link RSocketClient} */ | ||
| class RSocketServer implements RSocket { | ||
|
|
@@ -42,8 +48,8 @@ class RSocketServer implements RSocket { | |
| private final Function<Frame, ? extends Payload> frameDecoder; | ||
| private final Consumer<Throwable> errorConsumer; | ||
|
|
||
| private final NonBlockingHashMapLong<Subscription> sendingSubscriptions; | ||
|
Member
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. I think handleSendProcessorError and handleSendProcessorCancel should now be synchronized as they iterate over sendingSubscriptions/channelProcessors (previously this wasn't necessary because of Cliff Click magic).
Member
Author
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. I wrapped the map with Collections.synchronizedMap so it should effectively be doing that.
Member
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. Collections.synchronizedMap doesn't actually help when you iterate over any of its collection views -- per the documentation:
If we use forEach everywhere instead of a for loop that would also be fine.
Member
Author
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. I looked at the code again. I think we are fine - the problem would be if something adds something to map while we're iterating over it. Looking at the non blocking map the same thing would happen. We should probably add something to the request* methods so that you can't add items to the map when handling a cancel or an error, and then this isn't a problem. |
||
| private final NonBlockingHashMapLong<UnicastProcessor<Payload>> channelProcessors; | ||
| private final Map<Integer, Subscription> sendingSubscriptions; | ||
| private final Map<Integer, UnicastProcessor<Payload>> channelProcessors; | ||
|
|
||
| private final UnboundedProcessor<Frame> sendProcessor; | ||
| private KeepAliveHandler keepAliveHandler; | ||
|
|
@@ -69,8 +75,8 @@ class RSocketServer implements RSocket { | |
| this.requestHandler = requestHandler; | ||
| this.frameDecoder = frameDecoder; | ||
| this.errorConsumer = errorConsumer; | ||
| this.sendingSubscriptions = new NonBlockingHashMapLong<>(); | ||
| this.channelProcessors = new NonBlockingHashMapLong<>(); | ||
| this.sendingSubscriptions = Collections.synchronizedMap(new IntObjectHashMap<>()); | ||
| this.channelProcessors = Collections.synchronizedMap(new IntObjectHashMap<>()); | ||
|
|
||
| // DO NOT Change the order here. The Send processor must be subscribed to before receiving | ||
| // connections | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 handleSendProcessorError and handleSendProcessorCancel and terminate should now be synchronized as they iterate over senders/receivers (previously this wasn't necessary because of Cliff Click magic).