限制 Windows .NET 服务的 CPU 使用率

发布于 2024-08-24 19:20:50 字数 114 浏览 3 评论 0原文

有什么方法可以限制用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三月梨花 2024-08-31 19:20:50

您需要仔细查看您的申请。为什么它会抛出异常,以及为什么这些异常会使用如此多的 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?

第几種人 2024-08-31 19:20:50

如今的内存带宽和处理器缓存的使用与 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.

独孤求败 2024-08-31 19:20:50

如果您需要从代码外部控制 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文