From b6b8ea3c384c61912dd54ea79b0c3b518842a936 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 14:46:53 +0100 Subject: [PATCH] Made ThreadCount configurable --- .../KestrelServerInformation.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 9619df7c1d..84b2fcab57 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -42,23 +42,28 @@ namespace Microsoft.AspNet.Server.Kestrel private static int GetThreadCount(IConfiguration configuration) { - // 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; + var threadCountString = configuration["server.threadCount"]; - if (threadCount < 1) + int threadCount; + if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount)) { - // Ensure shifted value is at least one - return 1; - } + // 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). + threadCount = Environment.ProcessorCount >> 1; - 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... - return 16; + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + 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... + return 16; + } } return threadCount;