Moved GetThreadCount into KestrelServerInformation
This commit is contained in:
parent
706ff04160
commit
75cfe2c3bb
|
|
@ -11,10 +11,10 @@ namespace Microsoft.AspNet.Server.Kestrel
|
||||||
{
|
{
|
||||||
public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature
|
public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature
|
||||||
{
|
{
|
||||||
public KestrelServerInformation(IConfiguration configuration, int threadCount)
|
public KestrelServerInformation(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Addresses = GetAddresses(configuration);
|
Addresses = GetAddresses(configuration);
|
||||||
ThreadCount = threadCount;
|
ThreadCount = GetThreadCount(configuration);
|
||||||
NoDelay = true;
|
NoDelay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,5 +39,29 @@ namespace Microsoft.AspNet.Server.Kestrel
|
||||||
|
|
||||||
return addresses;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,36 +27,11 @@ namespace Microsoft.AspNet.Server.Kestrel
|
||||||
|
|
||||||
public IServer CreateServer(IConfiguration configuration)
|
public IServer CreateServer(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var threadCount = GetThreadCount();
|
var information = new KestrelServerInformation(configuration);
|
||||||
var information = new KestrelServerInformation(configuration, threadCount);
|
|
||||||
var serverFeatures = new FeatureCollection();
|
var serverFeatures = new FeatureCollection();
|
||||||
serverFeatures.Set<IKestrelServerInformation>(information);
|
serverFeatures.Set<IKestrelServerInformation>(information);
|
||||||
serverFeatures.Set<IServerAddressesFeature>(information);
|
serverFeatures.Set<IServerAddressesFeature>(information);
|
||||||
return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"));
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue