支持配置是否设置线程池

This commit is contained in:
lindexi
2021-08-22 21:11:09 +08:00
parent 4afa7aa916
commit 51447f8c07

View File

@@ -49,7 +49,7 @@ namespace dotnetCampus.ApplicationStartupManager
private IStartupLogger Logger => Context.Logger;
public StartupManager(IStartupLogger logger, FileConfigurationRepo configurationRepo,
Func<Exception, Task> fastFailAction, IMainThreadDispatcher dispatcher)
Func<Exception, Task> fastFailAction, IMainThreadDispatcher dispatcher, bool shouldSetThreadPool = true)
{
if (logger == null)
{
@@ -63,12 +63,13 @@ namespace dotnetCampus.ApplicationStartupManager
_dispatcher = dispatcher;
ThreadPool.GetMinThreads(out _workerThreads, out _completionPortThreads);
//启动期间存在大量的线程池调用包含IO操作而创建的多数线程在等待 IO 时都是不会被调度的
//设置更多的初始化线程数可以减少启动期间的线程调度等待
ThreadPool.SetMinThreads(Math.Max(_workerThreads, 16), Math.Max(_completionPortThreads, 16));
// release bugfix code
if (shouldSetThreadPool)
{
ThreadPool.GetMinThreads(out _workerThreads, out _completionPortThreads);
//启动期间存在大量的线程池调用包含IO操作而创建的多数线程在等待 IO 时都是不会被调度的
//设置更多的初始化线程数可以减少启动期间的线程调度等待
ThreadPool.SetMinThreads(Math.Max(_workerThreads, 16), Math.Max(_completionPortThreads, 16));
}
Context = new StartupContext(logger, configurationRepo,
fastFailAction, WaitStartupTaskAsync);