Skip to content
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

Remove connection adapters and move things to middleware #11412

Merged
merged 3 commits into from
Jun 20, 2019

Conversation

davidfowl
Copy link
Member

  • Remove connection adapters from the public API surface (pubternal) and replace the existing adapters with connection middleware.
  • Updated the tests

Fixes #11402

- Remove connection adapters from the public API surface (pubternal) and replace the existing adapters with connection middleware.
- Updated the tests
@@ -160,24 +159,6 @@ public partial class MinDataRate
public System.TimeSpan GracePeriod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
}
}
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal
Copy link
Member Author

Choose a reason for hiding this comment

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

@sebastienros This will break the benchmarks.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -281,5 +260,19 @@ private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certif

return new X509Certificate2(certificate);
}

private class SslDuplexPipe : DuplexPipeStreamAdapter<SslStream>
Copy link
Member Author

Choose a reason for hiding this comment

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

@sebastienros I'd like to run a performance test with this change. It could affect SSL performance.

@davidfowl
Copy link
Member Author

The node services test exploded but things look good!

@analogrelay analogrelay added breaking-change This issue / pr will introduce a breaking change, when resolved / merged. area-servers labels Jun 20, 2019
@analogrelay analogrelay added this to the 3.0.0-preview7 milestone Jun 20, 2019
@@ -171,8 +171,7 @@ public async Task BindAsync(AddressBindContext context)
var httpsDefault = ParseAddress(Constants.DefaultServerHttpsAddress, out https);
context.ServerOptions.ApplyEndpointDefaults(httpsDefault);

if (httpsDefault.ConnectionAdapters.Any(f => f.IsHttps)
|| httpsDefault.TryUseHttps())
if (httpsDefault.IsTls || httpsDefault.TryUseHttps())
Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't this necessary in our last PR? Do we not have anything testing this address strategy?

Copy link
Member

Choose a reason for hiding this comment

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

Before this change, ParseAddress would never return a ListenOptions object with a ConnectionAdapter pre-attached anyway. It looks like httpsDefault.ConnectionAdapters.Any(f => f.IsHttps) was never tru before and httpsDefault.IsTls is never true now.

More evidence of this is that the https out var is completely ignored.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind. I now see the ApplyEndpointDefaults line. My bad.

Copy link
Member

Choose a reason for hiding this comment

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

Was calling UseHttps in the ConfigureEndpointDefaults callback broken before this change?

@@ -86,7 +86,7 @@ internal async Task Execute(KestrelConnection connection)
}
catch (Exception ex)
{
Log.LogCritical(0, ex, $"{nameof(ConnectionDispatcher)}.{nameof(Execute)}() {connectionContext.ConnectionId}");
Log.LogError(0, ex, "Unhandled exception while processing {ConnectionId}.", connectionContext.ConnectionId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this?

Copy link
Member Author

@davidfowl davidfowl Jun 20, 2019

Choose a reason for hiding this comment

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

It's not a critical exception if middleware throws, it's just an error now. Any user code can cause this to happen.

@@ -509,7 +506,7 @@ public async Task AbortingTheConnectionSendsFIN()
[MemberData(nameof(ConnectionAdapterData))]
public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions)
{
var testContext = new TestServiceContext(LoggerFactory);
var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count };
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove asserting the middleware count? I feel like it's causing a lot of code churn with very little value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should remove it, but let @halter73 decide, he's the one that added it.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with removing it. Before it was very unusual to have multiple, so it almost always signified a test bug where a ListenOptions object was being reused.

Now that so many tests add non-HttpConnectionMiddleware, I'm fine with removing it. Just watch out whenever you're writing kestrel tests not to reuse ListenOptions.

@sebastienros
Copy link
Member

sebastienros commented Jun 20, 2019

All good!

Citine/Windows

Before:

| Description |       RPS | CPU (%) | Memory (MB) | Avg. Latency (ms) | Startup (ms) | First Request (ms) | Latency (ms) | Errors |
| ----------- | --------- | ------- | ----------- | ----------------- | ------------ | ------------------ | ------------ | ------ |
|           √ | 2,481,298 |      95 |         411 |              1.34 |     412.5047 |           126.8114 |       0.1727 |      0 |
|           √ | 2,440,507 |      94 |         406 |              2.51 |     375.6787 |                  0 |            0 |      0 |
|           √ | 2,450,269 |      96 |         409 |              1.53 |     377.3042 |                  0 |            0 |      0 |

RequestsPerSecond:           2,457,358
Max CPU (%):                 95
WorkingSet (MB):             409
Avg. Latency (ms):           1.79
Startup (ms):                388
First Request (ms):          42.27
Latency (ms):                0.06
Total Requests:              37,104,666
Duration: (ms)               15,100
Socket Errors:               0
Bad Responses:               0
SDK:                         3.0.100-preview7-012531
Runtime:                     3.0.0-preview7-27812-08
ASP.NET Core:                3.0.0-preview7.19320.1

After:

| Description |       RPS | CPU (%) | Memory (MB) | Avg. Latency (ms) | Startup (ms) | First Request (ms) | Latency (ms) | Errors |
| ----------- | --------- | ------- | ----------- | ----------------- | ------------ | ------------------ | ------------ | ------ |
|           √ | 2,538,741 |      96 |         407 |              1.64 |      398.527 |           130.0194 |       0.1473 |      0 |
|           √ | 2,594,585 |      98 |         423 |              2.07 |     378.0464 |                  0 |            0 |      0 |
|           √ | 2,558,935 |      95 |         418 |              2.83 |     377.4521 |                  0 |            0 |      0 |

RequestsPerSecond:           2,564,087
Max CPU (%):                 96
WorkingSet (MB):             416
Avg. Latency (ms):           2.18
Startup (ms):                385
First Request (ms):          43.34
Latency (ms):                0.05
Total Requests:              38,701,248
Duration: (ms)               15,093
Socket Errors:               0
Bad Responses:               0
SDK:                         3.0.100-preview7-012531
Runtime:                     3.0.0-preview7-27812-08
ASP.NET Core:                3.0.0-preview7.19320.1

@@ -6,7 +6,6 @@
using System.Net;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: rename tests

{
internal sealed class RawStream : Stream
internal class DuplexPipeStream : Stream
Copy link
Member

Choose a reason for hiding this comment

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

You finally renamed it!!! 🎉🎆🎉

/// A helper for wrapping a Stream decorator from an <see cref="IDuplexPipe"/>.
/// </summary>
/// <typeparam name="TStream"></typeparam>
internal class DuplexPipeStreamAdapter<TStream> : DuplexPipeStream, IDuplexPipe where TStream : Stream
Copy link
Member

Choose a reason for hiding this comment

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

Are we planning to ship something like this in 3.1 in corefx?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've informally spoken to a few people about it.

@@ -125,6 +110,13 @@ internal virtual string GetDisplayName()

public override string ToString() => GetDisplayName();

/// <summary>
/// Adds a middleware delegate to the connection pipeline.
/// Configured by the <c>UseHttps()</c> and <see cref="Hosting.ListenOptionsConnectionLoggingExtensions.UseConnectionLogging(ListenOptions)"/>
Copy link
Member

Choose a reason for hiding this comment

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

Why no cref for UseHttps()?

@davidfowl davidfowl merged commit 25d5688 into master Jun 20, 2019
@ghost ghost deleted the davidfowl/remove-adapters branch June 20, 2019 22:26
davidfowl added a commit that referenced this pull request Jun 23, 2019
- Remove ExpectedMiddlewareCount since everything is middleware now
- Renamed everything adapter to middleware
- Added a regression test for an https scenario
- Don't send client certs for tests that don't expect it
davidfowl added a commit that referenced this pull request Jun 24, 2019
- Remove ExpectedMiddlewareCount since everything is middleware now
- Renamed everything adapter to middleware
- Added a regression test for an https scenario
- Don't send client certs for tests that don't expect it
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions breaking-change This issue / pr will introduce a breaking change, when resolved / merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove connection adapters
6 participants