From a95318c616e58786843f0a7e938e50317a751fee Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 08:23:13 +0000 Subject: [PATCH 1/2] Network thread count defaults --- .../KestrelServer.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index ff0ca62422..346808ebc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -75,14 +75,37 @@ namespace Microsoft.AspNet.Server.Kestrel _disposables.Push(engine); _disposables.Push(dateHeaderValueManager); + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + // Can be user overriden using IKestrelServerInformation.ThreadCount + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + threadCount = 1; + } + else if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + threadCount = 16; + } + if (information.ThreadCount < 0) { throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), information.ThreadCount, "ThreadCount cannot be negative"); } + else if (information.ThreadCount > 0) + { + // ThreadCount has been user set, use that value + threadCount = information.ThreadCount; + } - engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + engine.Start(threadCount); var atLeastOneListener = false; foreach (var address in information.Addresses) From d493667851d52b9a9e57b0709d68dba18df23141 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 08:44:27 +0000 Subject: [PATCH 2/2] Enable multi loop+thread tests Resolves #232 --- .../ThreadCountTests.cs | 1 - test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs | 3 --- 2 files changed, 4 deletions(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index ea654651e3..4bd434df68 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -15,7 +15,6 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class ThreadCountTests { - [Theory(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/232"), MemberData(nameof(OneToTen))] public async Task ZeroToTenThreads(int threadCount) { var config = new ConfigurationBuilder() diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 8293ad09b0..f57c899f6a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -21,7 +21,6 @@ namespace Microsoft.AspNet.Server.KestrelTests _logger = engine.Log; } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void InitAndCloseServerPipe() { var loop = new UvLoopHandle(_logger); @@ -39,7 +38,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); @@ -112,7 +110,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n");