在进行实际运行时才设置线程池数量,不应该过快进行设置
This commit is contained in:
@@ -60,13 +60,11 @@ namespace dotnetCampus.ApplicationStartupManager
|
||||
//}
|
||||
|
||||
_dispatcher = dispatcher;
|
||||
_shouldSetThreadPool = shouldSetThreadPool;
|
||||
|
||||
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,*/
|
||||
@@ -74,6 +72,8 @@ namespace dotnetCampus.ApplicationStartupManager
|
||||
Logger.RecordTime("ManagerInitialized");
|
||||
}
|
||||
|
||||
private readonly bool _shouldSetThreadPool;
|
||||
|
||||
///// <summary>
|
||||
///// 配置被 <see cref="StartupManager"/> 管理的程序集。
|
||||
///// 只有被管理的程序集中的启动信息、依赖注入信息才会被执行。
|
||||
@@ -227,6 +227,13 @@ namespace dotnetCampus.ApplicationStartupManager
|
||||
Logger.RecordTime("GraphBuilded");
|
||||
}
|
||||
|
||||
if(_shouldSetThreadPool)
|
||||
{
|
||||
//启动期间存在大量的线程池调用(包含IO操作),而创建的多数线程在等待 IO 时都是不会被调度的
|
||||
//设置更多的初始化线程数可以减少启动期间的线程调度等待
|
||||
ThreadPool.SetMinThreads(Math.Max(_workerThreads, 16), Math.Max(_completionPortThreads, 16));
|
||||
}
|
||||
|
||||
var dispatcher = _dispatcher;
|
||||
foreach (var wrapper in Graph)
|
||||
{
|
||||
@@ -245,13 +252,15 @@ namespace dotnetCampus.ApplicationStartupManager
|
||||
|
||||
Logger.RecordTime("AllStartupTasksCompleted");
|
||||
|
||||
Debug.WriteLine(Logger);
|
||||
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
|
||||
dispatcher.InvokeAsync(() =>
|
||||
Logger.ReportResult(Graph.OfType<IStartupTaskWrapper>().ToList()));
|
||||
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
|
||||
|
||||
ThreadPool.SetMinThreads(Math.Max(_workerThreads, 8), Math.Max(_completionPortThreads, 8));
|
||||
if(_shouldSetThreadPool)
|
||||
{
|
||||
ThreadPool.SetMinThreads(Math.Max(_workerThreads, 8), Math.Max(_completionPortThreads, 8));
|
||||
}
|
||||
}
|
||||
|
||||
private List<StartupTaskWrapper> BuildStartupGraph()
|
||||
|
||||
Reference in New Issue
Block a user