Network thread count defaults

This commit is contained in:
Ben Adams 2015-11-13 08:23:13 +00:00
parent 2ac5e4c790
commit a95318c616
1 changed files with 24 additions and 1 deletions

View File

@ -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)