主线程 +线程池和CPU使用率
如果我构建一个控制台应用程序并执行大量线程池工作,并使用单个 Console.ReadLine(); 使控制台应用程序保持活动状态;
在这种情况下,应用程序会发挥最大性能吗? 线程池能消耗尽可能多的CPU吗? 或者 Console.ReadLine 是否以从线程池中窃取 CPU 的方式占用主线程?
(我假设 ReadLine 不会大量占用 cpu 时间,但根据 JetBrains profiler,60% 的 CPU 时间花费在我的单个 ReadLine 语句上)
If I build a console app and do a lot of thread pool work, and keep the console app alive using a single Console.ReadLine();
Will the app perform to its maximum in this case?
Will the thread pool be able to consume as much CPU as possible?
Or do the Console.ReadLine hog the main thread in such a way that it steals CPU from the thread pool?
(I was under the assumption that ReadLine does not steal cpu time in a significan way, but according to JetBrains profiler, 60% of the CPU time is spent in my single ReadLine statement)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
计算机未在 Console.RealLine 上使用,只需查看任务管理器即可。
但是应用程序的主线程“挂在”Console.Readline 上,这就是探查器报告它的原因。
您所说的正确,它将其报告为热点,因为主线程在该函数上花费了绝大多数时间(并且探查器假设花费的时间=使用的CPU)。
The computer is NOT using the on the Console.RealLine just look at the task manager.
But the main thread of your application is "hanging" on the Console.Readline, thats why the profiler reports it.
Its correct what you say it reports it as a hotspot, its because the main thread is spending a vast majority of the time on this function ( And the profiler assumes time spent = CPU used ).