Skip to content

Commit 31afef5

Browse files
author
Koundinya Veluri
committed
Increase the default number of IO queues on larger machines
The number of IO queues is currently limited to 16. On machines with more processors, increasing the number of IO queues appears to improve throughput on some benchmarks.
1 parent 4c8b5fe commit 31afef5

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 17 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,19 @@ 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+
int processorCount = Environment.ProcessorCount;
86+
if (OperatingSystem.IsWindows() || processorCount <= 32)
87+
{
88+
return Math.Min(processorCount, 16);
89+
}
90+
91+
return (processorCount + 1) / 2;
92+
}
7693
}

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)