Moved GetThreadCount into KestrelServerInformation

This commit is contained in:
Kristian Hellang 2015-12-07 14:45:35 +01:00
parent 706ff04160
commit 75cfe2c3bb
2 changed files with 27 additions and 28 deletions

View File

@ -11,10 +11,10 @@ namespace Microsoft.AspNet.Server.Kestrel
{
public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature
{
public KestrelServerInformation(IConfiguration configuration, int threadCount)
public KestrelServerInformation(IConfiguration configuration)
{
Addresses = GetAddresses(configuration);
ThreadCount = threadCount;
ThreadCount = GetThreadCount(configuration);
NoDelay = true;
}
@ -39,5 +39,29 @@ namespace Microsoft.AspNet.Server.Kestrel
return addresses;
}
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;
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;
}
}
}

View File

@ -27,36 +27,11 @@ namespace Microsoft.AspNet.Server.Kestrel
public IServer CreateServer(IConfiguration configuration)
{
var threadCount = GetThreadCount();
var information = new KestrelServerInformation(configuration, threadCount);
var information = new KestrelServerInformation(configuration);
var serverFeatures = new FeatureCollection();
serverFeatures.Set<IKestrelServerInformation>(information);
serverFeatures.Set<IServerAddressesFeature>(information);
return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"));
}
private static int GetThreadCount()
{
// 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
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;
}
}
}