Made ThreadCount configurable

This commit is contained in:
Kristian Hellang 2015-12-07 14:46:53 +01:00
parent 75cfe2c3bb
commit b6b8ea3c38
1 changed files with 19 additions and 14 deletions

View File

@ -41,12 +41,16 @@ namespace Microsoft.AspNet.Server.Kestrel
}
private static int GetThreadCount(IConfiguration configuration)
{
var threadCountString = configuration["server.threadCount"];
int threadCount;
if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount))
{
// 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;
threadCount = Environment.ProcessorCount >> 1;
if (threadCount < 1)
{
@ -60,6 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel
// would be better to check the NIC's current hardware queues; but xplat...
return 16;
}
}
return threadCount;
}