Skip to content

Commit 8046091

Browse files
authored
Increase the default number of IO queues on larger machines (#56501)
1 parent d301328 commit 8046091

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal;
1010

1111
internal sealed class IOQueue : PipeScheduler, IThreadPoolWorkItem
1212
{
13+
public static readonly int DefaultCount = DetermineDefaultCount();
14+
1315
private readonly ConcurrentQueue<Work> _workItems = new ConcurrentQueue<Work>();
1416
private int _doingWork;
1517

@@ -73,4 +75,22 @@ public Work(Action<object?> callback, object? state)
7375
State = state;
7476
}
7577
}
78+
79+
private static int DetermineDefaultCount()
80+
{
81+
// Since each IOQueue schedules one work item to process its work, the number of IOQueues determines the maximum
82+
// parallelism of processing work queued to IOQueues. The default number below is based on the processor count and tries
83+
// to use a high-enough number for that to not be a significant limiting factor for throughput.
84+
//
85+
// On Windows, the default number is limited due to some other perf issues. Once those are fixed, the same heuristic
86+
// could apply there as well.
87+
88+
int processorCount = Environment.ProcessorCount;
89+
if (OperatingSystem.IsWindows() || processorCount <= 32)
90+
{
91+
return Math.Min(processorCount, 16);
92+
}
93+
94+
return processorCount / 2;
95+
}
7696
}

src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionFactoryOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ internal SocketConnectionFactoryOptions(SocketTransportOptions transportOptions)
3333
/// The number of I/O queues used to process requests. Set to 0 to directly schedule I/O to the ThreadPool.
3434
/// </summary>
3535
/// <remarks>
36-
/// Defaults to <see cref="Environment.ProcessorCount" /> rounded down and clamped between 1 and 16.
36+
/// Defaults to a value based on and limited to <see cref="Environment.ProcessorCount" />.
3737
/// </remarks>
38-
public int IOQueueCount { get; set; } = Math.Min(Environment.ProcessorCount, 16);
38+
public int IOQueueCount { get; set; } = Internal.IOQueue.DefaultCount;
3939

4040
/// <summary>
4141
/// Wait until there is data available to allocate a buffer. Setting this to false can increase throughput at the cost of increased memory usage.

src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ static SocketTransportOptions()
2828
/// The number of I/O queues used to process requests. Set to 0 to directly schedule I/O to the ThreadPool.
2929
/// </summary>
3030
/// <remarks>
31-
/// Defaults to <see cref="Environment.ProcessorCount" /> rounded down and clamped between 1 and 16.
31+
/// Defaults to a value based on and limited to <see cref="Environment.ProcessorCount" />.
3232
/// </remarks>
33-
public int IOQueueCount { get; set; } = Math.Min(Environment.ProcessorCount, 16);
33+
public int IOQueueCount { get; set; } = Internal.IOQueue.DefaultCount;
3434

3535
/// <summary>
3636
/// Wait until there is data available to allocate a buffer. Setting this to false can increase throughput at the cost of increased memory usage.

0 commit comments

Comments
 (0)