Browse Source

Improvements to IIS IO (#32570)

* Improve IIS read IO performance
- Increase the IIS default pause threshold to 1MB by default. This matches kestrel. Today IIS only allows for 65K of slack for incoming request bodies. This affects the maximum size of the read possible when doing large uploads..
- Added public API for configuring the max body buffer
David Fowler 4 years ago
parent
commit
7b0f2b6804

+ 4 - 3
src/Servers/IIS/IIS/src/Core/IISHttpContext.cs

@@ -33,9 +33,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
     internal abstract partial class IISHttpContext : NativeRequestContext, IThreadPoolWorkItem, IDisposable
     {
         private const int MinAllocBufferSize = 2048;
-        private const int PauseWriterThreshold = 65536;
-        private const int ResumeWriterTheshold = PauseWriterThreshold / 2;
-
+        
         protected readonly NativeSafeHandle _requestNativeHandle;
 
         private readonly IISServerOptions _options;
@@ -93,6 +91,9 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
             ((IHttpBodyControlFeature)this).AllowSynchronousIO = _options.AllowSynchronousIO;
         }
 
+        private int PauseWriterThreshold => _options.MaxRequestBodyBufferSize;
+        private int ResumeWriterTheshold => PauseWriterThreshold / 2;
+
         public Version HttpVersion { get; set; } = default!;
         public string Scheme { get; set; } = default!;
         public string Method { get; set; } = default!;

+ 8 - 0
src/Servers/IIS/IIS/src/IISServerOptions.cs

@@ -33,6 +33,14 @@ namespace Microsoft.AspNetCore.Builder
         /// </summary>
         public string? AuthenticationDisplayName { get; set; }
 
+        /// <summary>
+        /// Gets or sets the maximum unconsumed incoming bytes the server will buffer for incoming request body.
+        /// </summary>
+        /// <value>
+        /// Defaults to 1 MB.
+        /// </value>
+        public int MaxRequestBodyBufferSize { get; set; } = 1024 * 1024; // Matches kestrel (sorta)
+
         /// <summary>
         /// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates
         /// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information.

+ 2 - 0
src/Servers/IIS/IIS/src/PublicAPI.Unshipped.txt

@@ -13,6 +13,8 @@
 *REMOVED*~override Microsoft.AspNetCore.Server.IIS.Core.WriteOnlyStream.ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<int>
 *REMOVED*~static Microsoft.AspNetCore.Hosting.WebHostBuilderIISExtensions.UseIIS(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder) -> Microsoft.AspNetCore.Hosting.IWebHostBuilder
 *REMOVED*~static Microsoft.AspNetCore.Server.IIS.HttpContextExtensions.GetIISServerVariable(this Microsoft.AspNetCore.Http.HttpContext context, string variableName) -> string
+Microsoft.AspNetCore.Builder.IISServerOptions.MaxRequestBodyBufferSize.get -> int
+Microsoft.AspNetCore.Builder.IISServerOptions.MaxRequestBodyBufferSize.set -> void
 Microsoft.AspNetCore.Http.Features.IServerVariablesFeature.this[string! variableName].get -> string? (forwarded, contained in Microsoft.AspNetCore.Http.Features)
 Microsoft.AspNetCore.Builder.IISServerOptions.AuthenticationDisplayName.get -> string?
 Microsoft.AspNetCore.Builder.IISServerOptions.AuthenticationDisplayName.set -> void