Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes TlsHandler from operation, perf and compat POVs.#116

Merged
nayato merged 1 commit intoAzure:devfrom
nayato:tls
Jun 1, 2016
Merged

Fixes TlsHandler from operation, perf and compat POVs.#116
nayato merged 1 commit intoAzure:devfrom
nayato:tls

Conversation

@nayato
Copy link
Member

@nayato nayato commented May 24, 2016

Motivation:
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() instead 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.

@nayato
Copy link
Member Author

nayato commented May 24, 2016

@mastermanu, @mtuchkov PTAL. TlsHandler.cs is the focus (TlsHandler.Unwrap and Wrap to be precise).

State oldState = self.state;
if ((oldState & State.AuthenticationCompleted) == 0)
HandlerState oldState = self.state;
if (!oldState.Has(HandlerState.AuthenticationCompleted))
Copy link
Member Author

Choose a reason for hiding this comment

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

.HasAny

@nayato nayato changed the title Fixes TlsHandler operation and perf Fixes TlsHandler from operation, perf and compat POVs. May 24, 2016
public sealed class TlsHandler : ByteToMessageDecoder
{
const int ReadBufferSize = 4 * 1024; // todo: research perfect size
const int FallbackReadBufferSize = 256;
Copy link
Contributor

Choose a reason for hiding this comment

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

[Nit] add InBytes suffix please

@nayato nayato force-pushed the tls branch 2 times, most recently from f595198 to 85bcf73 Compare May 27, 2016 00:57
@nayato nayato added this to the 0.3.1 milestone May 27, 2016
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Nit] HandshakeCompletionCallback

}
else
{
buf = context.Allocator.Buffer((int)this.pendingUnencryptedWrites.CurrentSize);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need buf? why can't we write to sslStream directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

not to package every single buffer as a separate SSL record. Every call to SslStream.Write(...) results in a new SSL record.

@mastermanu
Copy link
Contributor

:shipit:

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.
@nayato nayato merged commit acab5fc into Azure:dev Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants