Skip to content

Commit 7b0f2b6

Browse files
authored
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
1 parent 1632a6f commit 7b0f2b6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpContext.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
3333
internal abstract partial class IISHttpContext : NativeRequestContext, IThreadPoolWorkItem, IDisposable
3434
{
3535
private const int MinAllocBufferSize = 2048;
36-
private const int PauseWriterThreshold = 65536;
37-
private const int ResumeWriterTheshold = PauseWriterThreshold / 2;
38-
36+
3937
protected readonly NativeSafeHandle _requestNativeHandle;
4038

4139
private readonly IISServerOptions _options;
@@ -93,6 +91,9 @@ internal unsafe IISHttpContext(
9391
((IHttpBodyControlFeature)this).AllowSynchronousIO = _options.AllowSynchronousIO;
9492
}
9593

94+
private int PauseWriterThreshold => _options.MaxRequestBodyBufferSize;
95+
private int ResumeWriterTheshold => PauseWriterThreshold / 2;
96+
9697
public Version HttpVersion { get; set; } = default!;
9798
public string Scheme { get; set; } = default!;
9899
public string Method { get; set; } = default!;

src/Servers/IIS/IIS/src/IISServerOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public class IISServerOptions
3333
/// </summary>
3434
public string? AuthenticationDisplayName { get; set; }
3535

36+
/// <summary>
37+
/// Gets or sets the maximum unconsumed incoming bytes the server will buffer for incoming request body.
38+
/// </summary>
39+
/// <value>
40+
/// Defaults to 1 MB.
41+
/// </value>
42+
public int MaxRequestBodyBufferSize { get; set; } = 1024 * 1024; // Matches kestrel (sorta)
43+
3644
/// <summary>
3745
/// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates
3846
/// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information.

src/Servers/IIS/IIS/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*REMOVED*~override Microsoft.AspNetCore.Server.IIS.Core.WriteOnlyStream.ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<int>
1414
*REMOVED*~static Microsoft.AspNetCore.Hosting.WebHostBuilderIISExtensions.UseIIS(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder) -> Microsoft.AspNetCore.Hosting.IWebHostBuilder
1515
*REMOVED*~static Microsoft.AspNetCore.Server.IIS.HttpContextExtensions.GetIISServerVariable(this Microsoft.AspNetCore.Http.HttpContext context, string variableName) -> string
16+
Microsoft.AspNetCore.Builder.IISServerOptions.MaxRequestBodyBufferSize.get -> int
17+
Microsoft.AspNetCore.Builder.IISServerOptions.MaxRequestBodyBufferSize.set -> void
1618
Microsoft.AspNetCore.Http.Features.IServerVariablesFeature.this[string! variableName].get -> string? (forwarded, contained in Microsoft.AspNetCore.Http.Features)
1719
Microsoft.AspNetCore.Builder.IISServerOptions.AuthenticationDisplayName.get -> string?
1820
Microsoft.AspNetCore.Builder.IISServerOptions.AuthenticationDisplayName.set -> void

0 commit comments

Comments
 (0)