From a5411de678409d51f66c1a3526e68d180b928909 Mon Sep 17 00:00:00 2001 From: Dylan Dmitri Gray Date: Sat, 13 Jul 2019 08:08:21 -0700 Subject: [PATCH] ConcurrencyLimiter polishing and cleanup (#12127) * renames and cleanup --- eng/ProjectReferences.props | 2 +- .../ConcurrencyLimiter.slnf} | 12 ++-- .../perf/Microbenchmarks/AssemblyInfo.cs | 0 ...ConcurrencyLimiter.Microbenchmarks.csproj} | 6 +- .../Microbenchmarks/QueueEmptyOverhead.cs | 8 +-- .../perf/Microbenchmarks/QueueFullOverhead.cs | 8 +-- ...soft.AspNetCore.ConcurrencyLimiter.csproj} | 2 +- ...tCore.ConcurrencyLimiter.netcoreapp3.0.cs} | 32 ++++----- .../sample/ConcurrencyLimiterSample.csproj} | 4 +- .../ConcurrencyLimiter/sample/Startup.cs | 47 +++++++++++++ .../src/ConcurrencyLimiterEventSource.cs} | 16 ++--- .../src/ConcurrencyLimiterExtensions.cs} | 12 ++-- .../src/ConcurrencyLimiterMiddleware.cs} | 20 +++--- .../src/ConcurrencyLimiterOptions.cs} | 6 +- ...soft.AspNetCore.ConcurrencyLimiter.csproj} | 0 .../src/Properties/AssemblyInfo.cs | 6 ++ .../src/QueuePolicies/FIFOQueuePolicy.cs} | 6 +- .../src/QueuePolicies/IQueuePolicy.cs | 4 +- .../src/QueuePolicies/LIFOQueuePolicy.cs} | 6 +- .../src/QueuePolicies/QueuePolicyOptions.cs | 4 +- .../QueuePolicyServiceCollectionExtensions.cs | 10 +-- .../ConcurrencyLimiterEventSourceTests.cs} | 20 +++--- ...spNetCore.ConcurrencyLimiter.Tests.csproj} | 2 +- .../test/MiddlewareTests.cs | 2 +- .../test/PolicyTests/StackQueueTests.cs | 14 ++-- .../test/PolicyTests/TailDropTests.cs | 2 +- .../test/TaskExtensions.cs | 0 .../test/TestUtils.cs | 20 +++--- src/Middleware/Middleware.sln | 10 +-- .../RequestThrottling/sample/Startup.cs | 66 ------------------- .../src/Properties/AssemblyInfo.cs | 6 -- 31 files changed, 167 insertions(+), 186 deletions(-) rename src/Middleware/{RequestThrottling/RequestThrottling.slnf => ConcurrencyLimiter/ConcurrencyLimiter.slnf} (73%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/perf/Microbenchmarks/AssemblyInfo.cs (100%) rename src/Middleware/{RequestThrottling/perf/Microbenchmarks/Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj => ConcurrencyLimiter/perf/Microbenchmarks/Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj} (56%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/perf/Microbenchmarks/QueueEmptyOverhead.cs (89%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/perf/Microbenchmarks/QueueFullOverhead.cs (90%) rename src/Middleware/{RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.csproj => ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.csproj} (86%) rename src/Middleware/{RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.netcoreapp3.0.cs => ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.netcoreapp3.0.cs} (68%) rename src/Middleware/{RequestThrottling/sample/RequestThrottlingSample.csproj => ConcurrencyLimiter/sample/ConcurrencyLimiterSample.csproj} (79%) create mode 100644 src/Middleware/ConcurrencyLimiter/sample/Startup.cs rename src/Middleware/{RequestThrottling/src/RequestThrottlingEventSource.cs => ConcurrencyLimiter/src/ConcurrencyLimiterEventSource.cs} (83%) rename src/Middleware/{RequestThrottling/src/RequestThrottlingExtensions.cs => ConcurrencyLimiter/src/ConcurrencyLimiterExtensions.cs} (55%) rename src/Middleware/{RequestThrottling/src/RequestThrottlingMiddleware.cs => ConcurrencyLimiter/src/ConcurrencyLimiterMiddleware.cs} (85%) rename src/Middleware/{RequestThrottling/src/RequestThrottlingOptions.cs => ConcurrencyLimiter/src/ConcurrencyLimiterOptions.cs} (78%) rename src/Middleware/{RequestThrottling/src/Microsoft.AspNetCore.RequestThrottling.csproj => ConcurrencyLimiter/src/Microsoft.AspNetCore.ConcurrencyLimiter.csproj} (100%) create mode 100644 src/Middleware/ConcurrencyLimiter/src/Properties/AssemblyInfo.cs rename src/Middleware/{RequestThrottling/src/QueuePolicies/TailDropQueuePolicy.cs => ConcurrencyLimiter/src/QueuePolicies/FIFOQueuePolicy.cs} (91%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/src/QueuePolicies/IQueuePolicy.cs (90%) rename src/Middleware/{RequestThrottling/src/QueuePolicies/StackQueuePolicy.cs => ConcurrencyLimiter/src/QueuePolicies/LIFOQueuePolicy.cs} (94%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/src/QueuePolicies/QueuePolicyOptions.cs (87%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs (80%) rename src/Middleware/{RequestThrottling/test/RequestThrottlingEventSourceTests.cs => ConcurrencyLimiter/test/ConcurrencyLimiterEventSourceTests.cs} (85%) rename src/Middleware/{RequestThrottling/test/Microsoft.AspNetCore.RequestThrottling.Tests.csproj => ConcurrencyLimiter/test/Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj} (87%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/test/MiddlewareTests.cs (99%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/test/PolicyTests/StackQueueTests.cs (84%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/test/PolicyTests/TailDropTests.cs (95%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/test/TaskExtensions.cs (100%) rename src/Middleware/{RequestThrottling => ConcurrencyLimiter}/test/TestUtils.cs (74%) delete mode 100644 src/Middleware/RequestThrottling/sample/Startup.cs delete mode 100644 src/Middleware/RequestThrottling/src/Properties/AssemblyInfo.cs diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props index 932cec9dce..a54507bbb0 100644 --- a/eng/ProjectReferences.props +++ b/eng/ProjectReferences.props @@ -73,6 +73,7 @@ + @@ -87,7 +88,6 @@ - diff --git a/src/Middleware/RequestThrottling/RequestThrottling.slnf b/src/Middleware/ConcurrencyLimiter/ConcurrencyLimiter.slnf similarity index 73% rename from src/Middleware/RequestThrottling/RequestThrottling.slnf rename to src/Middleware/ConcurrencyLimiter/ConcurrencyLimiter.slnf index 55e6a99067..cff033d73c 100644 --- a/src/Middleware/RequestThrottling/RequestThrottling.slnf +++ b/src/Middleware/ConcurrencyLimiter/ConcurrencyLimiter.slnf @@ -1,6 +1,6 @@ { "solution": { - "path": "..\\Middleware.sln", + "path": "C:\\Users\\t-dygra\\Desktop\\AspNetCore\\src\\Middleware\\Middleware.sln", "projects": [ "..\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", "..\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj", @@ -15,11 +15,11 @@ "..\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", "..\\http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", "..\\http\\http\\src\\Microsoft.AspNetCore.Http.csproj", - "HttpsPolicy\\src\\Microsoft.AspNetCore.HttpsPolicy.csproj", - "RequestThrottling\\sample\\RequestThrottlingSample.csproj", - "RequestThrottling\\src\\Microsoft.AspNetCore.RequestThrottling.csproj", - "RequestThrottling\\test\\Microsoft.AspNetCore.RequestThrottling.Tests.csproj", - "RequestThrottling\\perf\\Microbenchmarks\\Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj" + "ConcurrencyLimiter\\perf\\Microbenchmarks\\Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj", + "ConcurrencyLimiter\\sample\\ConcurrencyLimiterSample.csproj", + "ConcurrencyLimiter\\src\\Microsoft.AspNetCore.ConcurrencyLimiter.csproj", + "ConcurrencyLimiter\\test\\Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj", + "HttpsPolicy\\src\\Microsoft.AspNetCore.HttpsPolicy.csproj" ] } } \ No newline at end of file diff --git a/src/Middleware/RequestThrottling/perf/Microbenchmarks/AssemblyInfo.cs b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/AssemblyInfo.cs similarity index 100% rename from src/Middleware/RequestThrottling/perf/Microbenchmarks/AssemblyInfo.cs rename to src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/AssemblyInfo.cs diff --git a/src/Middleware/RequestThrottling/perf/Microbenchmarks/Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj similarity index 56% rename from src/Middleware/RequestThrottling/perf/Microbenchmarks/Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj rename to src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj index fd1f069214..45f51fb5eb 100644 --- a/src/Middleware/RequestThrottling/perf/Microbenchmarks/Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj +++ b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj @@ -3,16 +3,16 @@ Exe netcoreapp3.0 - + - + - + diff --git a/src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueEmptyOverhead.cs b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueEmptyOverhead.cs similarity index 89% rename from src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueEmptyOverhead.cs rename to src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueEmptyOverhead.cs index b4145022b2..a20e68486f 100644 --- a/src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueEmptyOverhead.cs +++ b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueEmptyOverhead.cs @@ -5,16 +5,16 @@ using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.RequestThrottling.Tests; +using Microsoft.AspNetCore.ConcurrencyLimiter.Tests; -namespace Microsoft.AspNetCore.RequestThrottling.Microbenchmarks +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks { public class QueueEmptyOverhead { private const int _numRequests = 20000; - private RequestThrottlingMiddleware _middlewareFIFO; - private RequestThrottlingMiddleware _middlewareLIFO; + private ConcurrencyLimiterMiddleware _middlewareFIFO; + private ConcurrencyLimiterMiddleware _middlewareLIFO; private RequestDelegate _restOfServer; [GlobalSetup] diff --git a/src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueFullOverhead.cs b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueFullOverhead.cs similarity index 90% rename from src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueFullOverhead.cs rename to src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueFullOverhead.cs index 2cdfdc1f83..bd47f120e1 100644 --- a/src/Middleware/RequestThrottling/perf/Microbenchmarks/QueueFullOverhead.cs +++ b/src/Middleware/ConcurrencyLimiter/perf/Microbenchmarks/QueueFullOverhead.cs @@ -5,9 +5,9 @@ using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.RequestThrottling.Tests; +using Microsoft.AspNetCore.ConcurrencyLimiter.Tests; -namespace Microsoft.AspNetCore.RequestThrottling.Microbenchmarks +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks { public class QueueFullOverhead { @@ -15,8 +15,8 @@ namespace Microsoft.AspNetCore.RequestThrottling.Microbenchmarks private int _requestCount = 0; private ManualResetEventSlim _mres = new ManualResetEventSlim(); - private RequestThrottlingMiddleware _middleware_FIFO; - private RequestThrottlingMiddleware _middleware_LIFO; + private ConcurrencyLimiterMiddleware _middleware_FIFO; + private ConcurrencyLimiterMiddleware _middleware_LIFO; [Params(8)] public int MaxConcurrentRequests; diff --git a/src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.csproj b/src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.csproj similarity index 86% rename from src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.csproj rename to src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.csproj index ba0a06082e..9744b563e9 100644 --- a/src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.csproj +++ b/src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.csproj @@ -4,7 +4,7 @@ netcoreapp3.0 - + diff --git a/src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.netcoreapp3.0.cs b/src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.netcoreapp3.0.cs similarity index 68% rename from src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.netcoreapp3.0.cs rename to src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.netcoreapp3.0.cs index d1ded94586..dd8206d528 100644 --- a/src/Middleware/RequestThrottling/ref/Microsoft.AspNetCore.RequestThrottling.netcoreapp3.0.cs +++ b/src/Middleware/ConcurrencyLimiter/ref/Microsoft.AspNetCore.ConcurrencyLimiter.netcoreapp3.0.cs @@ -3,13 +3,24 @@ namespace Microsoft.AspNetCore.Builder { - public static partial class RequestThrottlingExtensions + public static partial class ConcurrencyLimiterExtensions { - public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseRequestThrottling(this Microsoft.AspNetCore.Builder.IApplicationBuilder app) { throw null; } + public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseConcurrencyLimiter(this Microsoft.AspNetCore.Builder.IApplicationBuilder app) { throw null; } } } -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { + public partial class ConcurrencyLimiterMiddleware + { + public ConcurrencyLimiterMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.ConcurrencyLimiter.IQueuePolicy queue, Microsoft.Extensions.Options.IOptions options) { } + [System.Diagnostics.DebuggerStepThroughAttribute] + public System.Threading.Tasks.Task Invoke(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } + } + public partial class ConcurrencyLimiterOptions + { + public ConcurrencyLimiterOptions() { } + public Microsoft.AspNetCore.Http.RequestDelegate OnRejected { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + } public partial interface IQueuePolicy { void OnExit(); @@ -21,23 +32,12 @@ namespace Microsoft.AspNetCore.RequestThrottling public int MaxConcurrentRequests { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public int RequestQueueLimit { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } } - public partial class RequestThrottlingMiddleware - { - public RequestThrottlingMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.RequestThrottling.IQueuePolicy queue, Microsoft.Extensions.Options.IOptions options) { } - [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task Invoke(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - } - public partial class RequestThrottlingOptions - { - public RequestThrottlingOptions() { } - public Microsoft.AspNetCore.Http.RequestDelegate OnRejected { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - } } namespace Microsoft.Extensions.DependencyInjection { public static partial class QueuePolicyServiceCollectionExtensions { - public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddStackQueue(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configure) { throw null; } - public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddTailDropQueue(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configure) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddStackQueue(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configure) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddTailDropQueue(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configure) { throw null; } } } diff --git a/src/Middleware/RequestThrottling/sample/RequestThrottlingSample.csproj b/src/Middleware/ConcurrencyLimiter/sample/ConcurrencyLimiterSample.csproj similarity index 79% rename from src/Middleware/RequestThrottling/sample/RequestThrottlingSample.csproj rename to src/Middleware/ConcurrencyLimiter/sample/ConcurrencyLimiterSample.csproj index 3262b0749b..cb1aa19fa2 100644 --- a/src/Middleware/RequestThrottling/sample/RequestThrottlingSample.csproj +++ b/src/Middleware/ConcurrencyLimiter/sample/ConcurrencyLimiterSample.csproj @@ -6,13 +6,13 @@ - + - + diff --git a/src/Middleware/ConcurrencyLimiter/sample/Startup.cs b/src/Middleware/ConcurrencyLimiter/sample/Startup.cs new file mode 100644 index 0000000000..618d6e56f6 --- /dev/null +++ b/src/Middleware/ConcurrencyLimiter/sample/Startup.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace ConcurrencyLimiterSample +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddStackQueue((options) => { + options.MaxConcurrentRequests = Environment.ProcessorCount; + options.RequestQueueLimit = 50; + }); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + app.UseConcurrencyLimiter(); + app.Run(async context => + { + var delay = 100; + Task.Delay(delay).Wait(); + + await context.Response.WriteAsync("Hello World!"); + }); + } + + public static void Main(string[] args) + { + new WebHostBuilder() + .UseKestrel() + .UseStartup() + .Build() + .Run(); + } + } +} diff --git a/src/Middleware/RequestThrottling/src/RequestThrottlingEventSource.cs b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterEventSource.cs similarity index 83% rename from src/Middleware/RequestThrottling/src/RequestThrottlingEventSource.cs rename to src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterEventSource.cs index fe62439858..3582c83e63 100644 --- a/src/Middleware/RequestThrottling/src/RequestThrottlingEventSource.cs +++ b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterEventSource.cs @@ -8,11 +8,11 @@ using System.Text; using System.Threading; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { - internal sealed class RequestThrottlingEventSource : EventSource + internal sealed class ConcurrencyLimiterEventSource : EventSource { - public static readonly RequestThrottlingEventSource Log = new RequestThrottlingEventSource(); + public static readonly ConcurrencyLimiterEventSource Log = new ConcurrencyLimiterEventSource(); private static readonly QueueFrame CachedNonTimerResult = new QueueFrame(timer: null, parent: Log); private PollingCounter _rejectedRequestsCounter; @@ -22,13 +22,13 @@ namespace Microsoft.AspNetCore.RequestThrottling private long _rejectedRequests; private int _queueLength; - internal RequestThrottlingEventSource() - : base("Microsoft.AspNetCore.RequestThrottling") + internal ConcurrencyLimiterEventSource() + : base("Microsoft.AspNetCore.ConcurrencyLimiter") { } // Used for testing - internal RequestThrottlingEventSource(string eventSourceName) + internal ConcurrencyLimiterEventSource(string eventSourceName) : base(eventSourceName) { } @@ -65,9 +65,9 @@ namespace Microsoft.AspNetCore.RequestThrottling internal struct QueueFrame : IDisposable { private ValueStopwatch? _timer; - private RequestThrottlingEventSource _parent; + private ConcurrencyLimiterEventSource _parent; - public QueueFrame(ValueStopwatch? timer, RequestThrottlingEventSource parent) + public QueueFrame(ValueStopwatch? timer, ConcurrencyLimiterEventSource parent) { _timer = timer; _parent = parent; diff --git a/src/Middleware/RequestThrottling/src/RequestThrottlingExtensions.cs b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterExtensions.cs similarity index 55% rename from src/Middleware/RequestThrottling/src/RequestThrottlingExtensions.cs rename to src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterExtensions.cs index 17968b44d5..d02c55f6cd 100644 --- a/src/Middleware/RequestThrottling/src/RequestThrottlingExtensions.cs +++ b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterExtensions.cs @@ -2,28 +2,28 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.RequestThrottling; +using Microsoft.AspNetCore.ConcurrencyLimiter; namespace Microsoft.AspNetCore.Builder { /// - /// Extension methods for adding the to an application. + /// Extension methods for adding the to an application. /// - public static class RequestThrottlingExtensions + public static class ConcurrencyLimiterExtensions { /// - /// Adds the to limit the number of concurrently-executing requests. + /// Adds the to limit the number of concurrently-executing requests. /// /// The . /// The . - public static IApplicationBuilder UseRequestThrottling(this IApplicationBuilder app) + public static IApplicationBuilder UseConcurrencyLimiter(this IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } - return app.UseMiddleware(); + return app.UseMiddleware(); } } } diff --git a/src/Middleware/RequestThrottling/src/RequestThrottlingMiddleware.cs b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterMiddleware.cs similarity index 85% rename from src/Middleware/RequestThrottling/src/RequestThrottlingMiddleware.cs rename to src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterMiddleware.cs index c9a56944af..f2c6cf821d 100644 --- a/src/Middleware/RequestThrottling/src/RequestThrottlingMiddleware.cs +++ b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterMiddleware.cs @@ -7,12 +7,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { /// /// Limits the number of concurrent requests allowed in the application. /// - public class RequestThrottlingMiddleware + public class ConcurrencyLimiterMiddleware { private readonly IQueuePolicy _queuePolicy; private readonly RequestDelegate _next; @@ -20,13 +20,13 @@ namespace Microsoft.AspNetCore.RequestThrottling private readonly ILogger _logger; /// - /// Creates a new . + /// Creates a new . /// /// The representing the next middleware in the pipeline. /// The used for logging. /// The queueing strategy to use for the server. /// The options for the middleware, currently containing the 'OnRejected' callback. - public RequestThrottlingMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IQueuePolicy queue, IOptions options) + public ConcurrencyLimiterMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IQueuePolicy queue, IOptions options) { if (options.Value.OnRejected == null) { @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.RequestThrottling } _next = next; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); _onRejected = options.Value.OnRejected; _queuePolicy = queue; } @@ -50,11 +50,11 @@ namespace Microsoft.AspNetCore.RequestThrottling if (waitInQueueTask.IsCompleted) { - RequestThrottlingEventSource.Log.QueueSkipped(); + ConcurrencyLimiterEventSource.Log.QueueSkipped(); } else { - using (RequestThrottlingEventSource.Log.QueueTimer()) + using (ConcurrencyLimiterEventSource.Log.QueueTimer()) { await waitInQueueTask; } @@ -73,14 +73,14 @@ namespace Microsoft.AspNetCore.RequestThrottling } else { - RequestThrottlingEventSource.Log.RequestRejected(); - RequestThrottlingLog.RequestRejectedQueueFull(_logger); + ConcurrencyLimiterEventSource.Log.RequestRejected(); + ConcurrencyLimiterLog.RequestRejectedQueueFull(_logger); context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; await _onRejected(context); } } - private static class RequestThrottlingLog + private static class ConcurrencyLimiterLog { private static readonly Action _requestEnqueued = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "RequestEnqueued"), "MaxConcurrentRequests limit reached, request has been queued. Current active requests: {ActiveRequests}."); diff --git a/src/Middleware/RequestThrottling/src/RequestThrottlingOptions.cs b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterOptions.cs similarity index 78% rename from src/Middleware/RequestThrottling/src/RequestThrottlingOptions.cs rename to src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterOptions.cs index 8efcc64ccf..429c6a4777 100644 --- a/src/Middleware/RequestThrottling/src/RequestThrottlingOptions.cs +++ b/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterOptions.cs @@ -4,12 +4,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { /// - /// Specifies options for the . + /// Specifies options for the . /// - public class RequestThrottlingOptions + public class ConcurrencyLimiterOptions { /// /// A that handles requests rejected by this middleware. diff --git a/src/Middleware/RequestThrottling/src/Microsoft.AspNetCore.RequestThrottling.csproj b/src/Middleware/ConcurrencyLimiter/src/Microsoft.AspNetCore.ConcurrencyLimiter.csproj similarity index 100% rename from src/Middleware/RequestThrottling/src/Microsoft.AspNetCore.RequestThrottling.csproj rename to src/Middleware/ConcurrencyLimiter/src/Microsoft.AspNetCore.ConcurrencyLimiter.csproj diff --git a/src/Middleware/ConcurrencyLimiter/src/Properties/AssemblyInfo.cs b/src/Middleware/ConcurrencyLimiter/src/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..1a93825d99 --- /dev/null +++ b/src/Middleware/ConcurrencyLimiter/src/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.ConcurrencyLimiter.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Middleware/RequestThrottling/src/QueuePolicies/TailDropQueuePolicy.cs b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/FIFOQueuePolicy.cs similarity index 91% rename from src/Middleware/RequestThrottling/src/QueuePolicies/TailDropQueuePolicy.cs rename to src/Middleware/ConcurrencyLimiter/src/QueuePolicies/FIFOQueuePolicy.cs index 3a98fac973..addf7e263b 100644 --- a/src/Middleware/RequestThrottling/src/QueuePolicies/TailDropQueuePolicy.cs +++ b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/FIFOQueuePolicy.cs @@ -6,9 +6,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { - internal class TailDropQueuePolicy : IQueuePolicy, IDisposable + internal class FIFOQueuePolicy : IQueuePolicy, IDisposable { private readonly int _maxConcurrentRequests; private readonly int _requestQueueLimit; @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.RequestThrottling private object _totalRequestsLock = new object(); public int TotalRequests { get; private set; } - public TailDropQueuePolicy(IOptions options) + public FIFOQueuePolicy(IOptions options) { _maxConcurrentRequests = options.Value.MaxConcurrentRequests; if (_maxConcurrentRequests <= 0) diff --git a/src/Middleware/RequestThrottling/src/QueuePolicies/IQueuePolicy.cs b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/IQueuePolicy.cs similarity index 90% rename from src/Middleware/RequestThrottling/src/QueuePolicies/IQueuePolicy.cs rename to src/Middleware/ConcurrencyLimiter/src/QueuePolicies/IQueuePolicy.cs index ebaa753ffb..e8e86d5c22 100644 --- a/src/Middleware/RequestThrottling/src/QueuePolicies/IQueuePolicy.cs +++ b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/IQueuePolicy.cs @@ -4,10 +4,10 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { /// - /// Queueing policies, meant to be used with the . + /// Queueing policies, meant to be used with the . /// public interface IQueuePolicy { diff --git a/src/Middleware/RequestThrottling/src/QueuePolicies/StackQueuePolicy.cs b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/LIFOQueuePolicy.cs similarity index 94% rename from src/Middleware/RequestThrottling/src/QueuePolicies/StackQueuePolicy.cs rename to src/Middleware/ConcurrencyLimiter/src/QueuePolicies/LIFOQueuePolicy.cs index b8b3feca63..122c87196e 100644 --- a/src/Middleware/RequestThrottling/src/QueuePolicies/StackQueuePolicy.cs +++ b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/LIFOQueuePolicy.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { - internal class StackQueuePolicy : IQueuePolicy + internal class LIFOQueuePolicy : IQueuePolicy { private readonly List> _buffer; private readonly int _maxQueueCapacity; @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.RequestThrottling private int _freeServerSpots; - public StackQueuePolicy(IOptions options) + public LIFOQueuePolicy(IOptions options) { _buffer = new List>(); _maxQueueCapacity = options.Value.RequestQueueLimit; diff --git a/src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyOptions.cs b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyOptions.cs similarity index 87% rename from src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyOptions.cs rename to src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyOptions.cs index 1a36fcef64..53923ccd1b 100644 --- a/src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyOptions.cs +++ b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyOptions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace Microsoft.AspNetCore.RequestThrottling +namespace Microsoft.AspNetCore.ConcurrencyLimiter { /// /// Specifies options for the @@ -19,6 +19,6 @@ namespace Microsoft.AspNetCore.RequestThrottling /// Maximum number of queued requests before the server starts rejecting connections with '503 Service Unavailible'. /// Defaults to 5000 queued requests. /// - public int RequestQueueLimit { get; set; } = 5000; + public int RequestQueueLimit { get; set; } } } diff --git a/src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs similarity index 80% rename from src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs rename to src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs index c5ba0464b0..021ae8278a 100644 --- a/src/Middleware/RequestThrottling/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs +++ b/src/Middleware/ConcurrencyLimiter/src/QueuePolicies/QueuePolicyServiceCollectionExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.RequestThrottling; +using Microsoft.AspNetCore.ConcurrencyLimiter; namespace Microsoft.Extensions.DependencyInjection { @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection public static class QueuePolicyServiceCollectionExtensions { /// - /// Tells to use a FIFO queue as its queueing strategy. + /// Tells to use a FIFO queue as its queueing strategy. /// /// The to add services to. /// Set the options used by the queue. @@ -21,12 +21,12 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection AddTailDropQueue(this IServiceCollection services, Action configure) { services.Configure(configure); - services.AddSingleton(); + services.AddSingleton(); return services; } /// - /// Tells to use a LIFO stack as its queueing strategy. + /// Tells to use a LIFO stack as its queueing strategy. /// /// The to add services to. /// Set the options used by the queue. @@ -35,7 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection AddStackQueue(this IServiceCollection services, Action configure) { services.Configure(configure); - services.AddSingleton(); + services.AddSingleton(); return services; } } diff --git a/src/Middleware/RequestThrottling/test/RequestThrottlingEventSourceTests.cs b/src/Middleware/ConcurrencyLimiter/test/ConcurrencyLimiterEventSourceTests.cs similarity index 85% rename from src/Middleware/RequestThrottling/test/RequestThrottlingEventSourceTests.cs rename to src/Middleware/ConcurrencyLimiter/test/ConcurrencyLimiterEventSourceTests.cs index 7725f6d7c4..9728d63b90 100644 --- a/src/Middleware/RequestThrottling/test/RequestThrottlingEventSourceTests.cs +++ b/src/Middleware/ConcurrencyLimiter/test/ConcurrencyLimiterEventSourceTests.cs @@ -9,17 +9,17 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Internal; using Xunit; -namespace Microsoft.AspNetCore.RequestThrottling.Tests +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Tests { - public class RequestThrottlingEventSourceTests + public class ConcurrencyLimiterEventSourceTests { [Fact] public void MatchesNameAndGuid() { - var eventSource = new RequestThrottlingEventSource(); + var eventSource = new ConcurrencyLimiterEventSource(); - Assert.Equal("Microsoft.AspNetCore.RequestThrottling", eventSource.Name); - Assert.Equal(Guid.Parse("436f1cb1-8acc-56c0-86ec-e0832bd696ed"), eventSource.Guid); + Assert.Equal("Microsoft.AspNetCore.ConcurrencyLimiter", eventSource.Name); + Assert.Equal(Guid.Parse("a605548a-6963-55cf-f000-99a6013deb01"), eventSource.Guid); } [Fact] @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests // Arrange var expectedId = 1; var eventListener = new TestEventListener(expectedId); - var eventSource = GetRequestThrottlingEventSource(); + var eventSource = GetConcurrencyLimiterEventSource(); eventListener.EnableEvents(eventSource, EventLevel.Informational); // Act @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests "requests-rejected", }); - using var eventSource = GetRequestThrottlingEventSource(); + using var eventSource = GetConcurrencyLimiterEventSource(); using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests "requests-rejected", }); - using var eventSource = GetRequestThrottlingEventSource(); + using var eventSource = GetConcurrencyLimiterEventSource(); using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5)); @@ -140,9 +140,9 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests return false; } - private static RequestThrottlingEventSource GetRequestThrottlingEventSource() + private static ConcurrencyLimiterEventSource GetConcurrencyLimiterEventSource() { - return new RequestThrottlingEventSource(Guid.NewGuid().ToString()); + return new ConcurrencyLimiterEventSource(Guid.NewGuid().ToString()); } } } diff --git a/src/Middleware/RequestThrottling/test/Microsoft.AspNetCore.RequestThrottling.Tests.csproj b/src/Middleware/ConcurrencyLimiter/test/Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj similarity index 87% rename from src/Middleware/RequestThrottling/test/Microsoft.AspNetCore.RequestThrottling.Tests.csproj rename to src/Middleware/ConcurrencyLimiter/test/Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj index 759af99f21..99bf7ae196 100644 --- a/src/Middleware/RequestThrottling/test/Microsoft.AspNetCore.RequestThrottling.Tests.csproj +++ b/src/Middleware/ConcurrencyLimiter/test/Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj @@ -12,6 +12,6 @@ - + diff --git a/src/Middleware/RequestThrottling/test/MiddlewareTests.cs b/src/Middleware/ConcurrencyLimiter/test/MiddlewareTests.cs similarity index 99% rename from src/Middleware/RequestThrottling/test/MiddlewareTests.cs rename to src/Middleware/ConcurrencyLimiter/test/MiddlewareTests.cs index becace2358..b285ad518a 100644 --- a/src/Middleware/RequestThrottling/test/MiddlewareTests.cs +++ b/src/Middleware/ConcurrencyLimiter/test/MiddlewareTests.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Xunit; -namespace Microsoft.AspNetCore.RequestThrottling.Tests +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Tests { public class MiddlewareTests { diff --git a/src/Middleware/RequestThrottling/test/PolicyTests/StackQueueTests.cs b/src/Middleware/ConcurrencyLimiter/test/PolicyTests/StackQueueTests.cs similarity index 84% rename from src/Middleware/RequestThrottling/test/PolicyTests/StackQueueTests.cs rename to src/Middleware/ConcurrencyLimiter/test/PolicyTests/StackQueueTests.cs index e109a08bbc..cce15aec2d 100644 --- a/src/Middleware/RequestThrottling/test/PolicyTests/StackQueueTests.cs +++ b/src/Middleware/ConcurrencyLimiter/test/PolicyTests/StackQueueTests.cs @@ -3,14 +3,14 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Xunit; -namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Tests.PolicyTests { public static class StackQueueTests { [Fact] public static void BaseFunctionality() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions { + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 0, RequestQueueLimit = 2, })); @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests [Fact] public static void OldestRequestOverwritten() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions { + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 0, RequestQueueLimit = 3, })); @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests [Fact] public static void RespectsMaxConcurrency() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions { + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 2, RequestQueueLimit = 2, })); @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests [Fact] public static void ExitRequestsPreserveSemaphoreState() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions { + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 1, RequestQueueLimit = 2, })); @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests [Fact] public static void StaleRequestsAreProperlyOverwritten() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 0, RequestQueueLimit = 4, @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests [Fact] public static async Task OneTryEnterAsyncOneOnExit() { - var stack = new StackQueuePolicy(Options.Create(new QueuePolicyOptions + var stack = new LIFOQueuePolicy(Options.Create(new QueuePolicyOptions { MaxConcurrentRequests = 1, RequestQueueLimit = 4, diff --git a/src/Middleware/RequestThrottling/test/PolicyTests/TailDropTests.cs b/src/Middleware/ConcurrencyLimiter/test/PolicyTests/TailDropTests.cs similarity index 95% rename from src/Middleware/RequestThrottling/test/PolicyTests/TailDropTests.cs rename to src/Middleware/ConcurrencyLimiter/test/PolicyTests/TailDropTests.cs index 82ea4e2ceb..67b7880d77 100644 --- a/src/Middleware/RequestThrottling/test/PolicyTests/TailDropTests.cs +++ b/src/Middleware/ConcurrencyLimiter/test/PolicyTests/TailDropTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Internal; using Xunit; -namespace Microsoft.AspNetCore.RequestThrottling.Tests.PolicyTests +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Tests.PolicyTests { public class TailDropTests { diff --git a/src/Middleware/RequestThrottling/test/TaskExtensions.cs b/src/Middleware/ConcurrencyLimiter/test/TaskExtensions.cs similarity index 100% rename from src/Middleware/RequestThrottling/test/TaskExtensions.cs rename to src/Middleware/ConcurrencyLimiter/test/TaskExtensions.cs diff --git a/src/Middleware/RequestThrottling/test/TestUtils.cs b/src/Middleware/ConcurrencyLimiter/test/TestUtils.cs similarity index 74% rename from src/Middleware/RequestThrottling/test/TestUtils.cs rename to src/Middleware/ConcurrencyLimiter/test/TestUtils.cs index 1b386d9cfe..5e2c0fdd78 100644 --- a/src/Middleware/RequestThrottling/test/TestUtils.cs +++ b/src/Middleware/ConcurrencyLimiter/test/TestUtils.cs @@ -8,18 +8,18 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.RequestThrottling.Tests +namespace Microsoft.AspNetCore.ConcurrencyLimiter.Tests { public static class TestUtils { - public static RequestThrottlingMiddleware CreateTestMiddleware(IQueuePolicy queue = null, RequestDelegate onRejected = null, RequestDelegate next = null) + public static ConcurrencyLimiterMiddleware CreateTestMiddleware(IQueuePolicy queue = null, RequestDelegate onRejected = null, RequestDelegate next = null) { - var options = Options.Create(new RequestThrottlingOptions + var options = Options.Create(new ConcurrencyLimiterOptions { OnRejected = onRejected ?? (context => Task.CompletedTask), }); - return new RequestThrottlingMiddleware( + return new ConcurrencyLimiterMiddleware( next: next ?? (context => Task.CompletedTask), loggerFactory: NullLoggerFactory.Instance, queue: queue ?? CreateTailDropQueue(1, 0), @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests ); } - public static RequestThrottlingMiddleware CreateTestMiddleware_TailDrop(int maxConcurrentRequests, int requestQueueLimit, RequestDelegate onRejected = null, RequestDelegate next = null) + public static ConcurrencyLimiterMiddleware CreateTestMiddleware_TailDrop(int maxConcurrentRequests, int requestQueueLimit, RequestDelegate onRejected = null, RequestDelegate next = null) { return CreateTestMiddleware( queue: CreateTailDropQueue(maxConcurrentRequests, requestQueueLimit), @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests ); } - public static RequestThrottlingMiddleware CreateTestMiddleware_StackPolicy(int maxConcurrentRequests, int requestQueueLimit, RequestDelegate onRejected = null, RequestDelegate next = null) + public static ConcurrencyLimiterMiddleware CreateTestMiddleware_StackPolicy(int maxConcurrentRequests, int requestQueueLimit, RequestDelegate onRejected = null, RequestDelegate next = null) { return CreateTestMiddleware( queue: CreateStackPolicy(maxConcurrentRequests, requestQueueLimit), @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests ); } - internal static StackQueuePolicy CreateStackPolicy(int maxConcurrentRequests, int requestsQueuelimit = 100) + internal static LIFOQueuePolicy CreateStackPolicy(int maxConcurrentRequests, int requestsQueuelimit = 100) { var options = Options.Create(new QueuePolicyOptions { @@ -53,10 +53,10 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests RequestQueueLimit = requestsQueuelimit }); - return new StackQueuePolicy(options); + return new LIFOQueuePolicy(options); } - internal static TailDropQueuePolicy CreateTailDropQueue(int maxConcurrentRequests, int requestQueueLimit = 100) + internal static FIFOQueuePolicy CreateTailDropQueue(int maxConcurrentRequests, int requestQueueLimit = 100) { var options = Options.Create(new QueuePolicyOptions { @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests RequestQueueLimit = requestQueueLimit }); - return new TailDropQueuePolicy(options); + return new FIFOQueuePolicy(options); } } diff --git a/src/Middleware/Middleware.sln b/src/Middleware/Middleware.sln index aa94cdf17f..f62cfabeb6 100644 --- a/src/Middleware/Middleware.sln +++ b/src/Middleware/Middleware.sln @@ -277,19 +277,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeaderPropagationSample", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.IIS", "..\Servers\IIS\IIS\src\Microsoft.AspNetCore.Server.IIS.csproj", "{B9BE1823-B555-4AAB-AEBC-C8C3F48C8861}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RequestThrottling", "RequestThrottling", "{8C9AA8A2-9D1F-4450-9F8D-56BAB6F3D343}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConcurrencyLimiter", "ConcurrencyLimiter", "{8C9AA8A2-9D1F-4450-9F8D-56BAB6F3D343}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RequestThrottlingSample", "RequestThrottling\sample\RequestThrottlingSample.csproj", "{6720919C-0DEA-49E1-90DC-F1883F7919CD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConcurrencyLimiterSample", "ConcurrencyLimiter\sample\ConcurrencyLimiterSample.csproj", "{6720919C-0DEA-49E1-90DC-F1883F7919CD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.RequestThrottling", "RequestThrottling\src\Microsoft.AspNetCore.RequestThrottling.csproj", "{4CE2384D-6B88-4824-ADD1-4183D180FEFF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.ConcurrencyLimiter", "ConcurrencyLimiter\src\Microsoft.AspNetCore.ConcurrencyLimiter.csproj", "{4CE2384D-6B88-4824-ADD1-4183D180FEFF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.RequestThrottling.Tests", "RequestThrottling\test\Microsoft.AspNetCore.RequestThrottling.Tests.csproj", "{353AA2B0-1013-486C-B5BD-9379385CA403}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.ConcurrencyLimiter.Tests", "ConcurrencyLimiter\test\Microsoft.AspNetCore.ConcurrencyLimiter.Tests.csproj", "{353AA2B0-1013-486C-B5BD-9379385CA403}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Metadata", "..\Http\Metadata\src\Microsoft.AspNetCore.Metadata.csproj", "{7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authorization", "..\Security\Authorization\Core\src\Microsoft.AspNetCore.Authorization.csproj", "{CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.RequestThrottling.Microbenchmarks", "RequestThrottling\perf\Microbenchmarks\Microsoft.AspNetCore.RequestThrottling.Microbenchmarks.csproj", "{737B26B4-CFC6-4B44-9070-DD36334E85B3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks", "ConcurrencyLimiter\perf\Microbenchmarks\Microsoft.AspNetCore.ConcurrencyLimiter.Microbenchmarks.csproj", "{737B26B4-CFC6-4B44-9070-DD36334E85B3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDestination", "CORS\test\testassets\TestDestination\TestDestination.csproj", "{DFEB537A-2D35-4C62-8A13-42798DF66A80}" EndProject diff --git a/src/Middleware/RequestThrottling/sample/Startup.cs b/src/Middleware/RequestThrottling/sample/Startup.cs deleted file mode 100644 index 846a7cc186..0000000000 --- a/src/Middleware/RequestThrottling/sample/Startup.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace RequestThrottlingSample -{ - public class Startup - { - static IConfiguration _config; - - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - services.AddStackQueue((options) => - { - options.MaxConcurrentRequests = Math.Max(1, _config.GetValue("maxConcurrent")); - options.RequestQueueLimit = Math.Max(1, _config.GetValue("maxQueue")); - }); - - services.AddLogging(); - } - - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) - { - app.UseRequestThrottling(); - app.Run(async context => - { - await context.Response.WriteAsync("Hello Request Throttling! If you rapidly refresh this page, it will 503."); - await Task.Delay(400); - }); - } - - // Entry point for the application. - public static void Main(string[] args) - { - _config = new ConfigurationBuilder() - .AddEnvironmentVariables(prefix: "ASPNETCORE_") - .AddCommandLine(args) - .Build(); - - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) // for the cert file - .ConfigureLogging(factory => - { - factory.SetMinimumLevel(LogLevel.Debug); - factory.AddConsole(); - }) - .UseStartup() - .Build(); - - host.Run(); - } - } -} diff --git a/src/Middleware/RequestThrottling/src/Properties/AssemblyInfo.cs b/src/Middleware/RequestThrottling/src/Properties/AssemblyInfo.cs deleted file mode 100644 index 1dcaedfaa6..0000000000 --- a/src/Middleware/RequestThrottling/src/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.RequestThrottling.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]