Fixes TlsHandler from operation, perf and compat POVs.#116
Merged
Conversation
Member
Author
|
@mastermanu, @mtuchkov PTAL. TlsHandler.cs is the focus ( |
| State oldState = self.state; | ||
| if ((oldState & State.AuthenticationCompleted) == 0) | ||
| HandlerState oldState = self.state; | ||
| if (!oldState.Has(HandlerState.AuthenticationCompleted)) |
| public sealed class TlsHandler : ByteToMessageDecoder | ||
| { | ||
| const int ReadBufferSize = 4 * 1024; // todo: research perfect size | ||
| const int FallbackReadBufferSize = 256; |
Contributor
There was a problem hiding this comment.
[Nit] add InBytes suffix please
f595198 to
85bcf73
Compare
| static readonly Exception ChannelClosedException = new IOException("Channel is closed"); | ||
| static readonly Action<Task, object> AuthenticationCompletionCallback = new Action<Task, object>(HandleAuthenticationCompleted); | ||
| static readonly AsyncCallback SslStreamReadCallback = new AsyncCallback(HandleSslStreamRead); | ||
| static readonly Action<Task, object> AuthenticationCompletionCallback = new Action<Task, object>(HandleHandshakeCompleted); |
Contributor
There was a problem hiding this comment.
[Nit] HandshakeCompletionCallback
| } | ||
| else | ||
| { | ||
| buf = context.Allocator.Buffer((int)this.pendingUnencryptedWrites.CurrentSize); |
Contributor
There was a problem hiding this comment.
Why do we need buf? why can't we write to sslStream directly?
Member
Author
There was a problem hiding this comment.
not to package every single buffer as a separate SSL record. Every call to SslStream.Write(...) results in a new SSL record.
Contributor
|
|
Motivation: TlsHandler Fix TlsHandler, optimize encryption / decryption wrt Write vs Flush semantics, optimize memory retention for sparse communication, adopt IByteBuffer.GetIoBuffers() in TlsHandler. Modifications: - TlsHandler is rewritten to use batch->copy->write approach instead of writing directly to SslStream in order to reduce overhead of framing / writing out everything separately. - TlsHandler uses IByteBuffer.GetIoBuffers intead of direct array access increasing compatibility for non-array-backed buffers. - TlsHandler and TlsHandler.MediationStream use Task semantics now when reading through SslStream. - Extra: upgraded to NBench 2.2, xUnit 2.1.0. - Extra: better portability for .NET Core support. Result: TlsHandler provides better framing and much better (x2+) performance (depends on application control of flushing). TlsHandler operates properly in edge cases when more than one frame is accepted at once and if decrypted frame size is more than 4 KB. TlsHandler holds only 256 byte buffer while waiting for more data to arrive off the wire. Extra: DotNetty is almost .NET Core compatible.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation:
Fix
TlsHandler, optimize encryption / decryption wrt Write vs Flush semantics, optimize memory retention for sparse communication, adoptIByteBuffer.GetIoBuffers()inTlsHandler.Modifications:
TlsHandleris rewritten to use batch->copy->write approach instead of writing directly toSslStreamin order to reduce overhead of framing / writing out everything separately.TlsHandlerusesIByteBuffer.GetIoBuffers()instead of direct array access increasing compatibility for non-array-backed buffers.TlsHandlerandTlsHandler.MediationStreamuse Task semantics now when reading throughSslStream.Result:
TlsHandlerprovides better framing and much better (x2+) performance (depends on application control of flushing).TlsHandleroperates properly in edge cases when more than one frame is accepted at once and if decrypted frame size is more than 4 KB.TlsHandlerholds only 256 byte buffer while waiting for more data to arrive off the wire.Extra: DotNetty is almost .NET Core compatible.