限制 Windows .NET 服务的 CPU 使用率
有什么方法可以限制用 .NET 编写的 Windows 服务的 CPU 使用率,无论是在服务代码内部还是外部。将当前线程设置为最低优先级不是一个选项,但是一旦异常开始发生,CPU 负载就会上升,是否可以限制这一点?
is there any way to throttle the cpu usage of a windows service that is written in .NET, either inside the service code or outside. Setting the current thread to the lowest priority is not an option but as soon as exceptions start to occur the cpu load goes up, is it possible to limit this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要仔细查看您的申请。为什么它会抛出异常,以及为什么这些异常会使用如此多的 CPU?
You need to take a closer look at your application. Why is it throwing exceptions, and why are those exceptions using so much CPU?
如今的内存带宽和处理器缓存的使用与 CPU 时间相匹配。
我不知道有哪个操作系统能够跟上...
您可以尝试使用 Thread.Sleep 来休眠 50% 的墙壁时间,虽然很混乱,但可能会起作用。
These days’ memory band-width and usage of the processor cache is as match of a problem is CPU time.
I don’t know of a OS that has kept up...
You could try using a Thread.Sleep to sleep for 50% of the wall time, messy but may work.
如果您需要从代码外部控制 CPU 使用情况,我建议使用 ThreadMaster http://threadmaster.tripod.com/ 它有点过时,但我过去使用过它,它能够成功解决我的问题。
这对于长期解决方案来说并不理想,但在某些特定场景中可能是一个很好的工具。
If you need to control the CPU usage from outside of the code I would suggest using ThreadMaster http://threadmaster.tripod.com/ It's a little outdated but I've used it in the past and it was able to successfully resolve my issue.
This isn't ideal for a long term solution, but could be a good tool in some specific scenarios.