CPU很高,运行C#控制台应用程序 [英] CPU is high which runs C# console application

查看:146
本文介绍了CPU很高,运行C#控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在其中一台服务器上运行了一些控制台应用程序。这些都是用C#编写的。有时它消耗100%的CPU和服务器冻结。有2-3个应用程序,每个需要20%的CPU。我想知道我们是否可以限制这种控制台应用程序的CPU使用率。



我尝试过:



我是系统管理员。我还没有尝试过任何东西。

We run few console application on one of our server. Those are coded in C#.Sometimes it consumes 100 % CPU and server freezes. There are 2-3 applications which takes 20% CPU each. I would like to know if we can limit CPU usage for such console application.

What I have tried:

I am a system administrator. I haven't tried anything yet.

推荐答案

这个问题无法解答...

如果你运行一个无限的应用程序没有做任何事情的循环会占用你拥有的所有CPU能力,所以你会跳到100%(但不会冻结)...

要解决这个问题,你首先必须找出罪魁祸首。在一台单独的机器上逐个运行它们可能是一个好主意 - 错误也会破坏该机器......

获得应用程序后你必须开始并接受它分开并检查和调试并询问......



至于限制CPU - 你不能在你的应用程序中做到这一点,但有(大多数是昂贵的 - 在钱和资源)你可能会购买的外部解决方案...说实话,你不太可能需要它们......
This can not be answered...
If you run a single application with an infinite loop that does nothing it will take all the CPU power you have, so you will jump to 100% (but not freezing)...
To handle the problem you first have to identify the culprit... It may be a good idea to run them one-by-one on a separate machine - the wrong will break that machine too...
After you have the app you have to start and take it apart and examine and debug and ask...

As for limiting CPU - you can not do it from within you application, but there are (mostly expensive - in money and resources) external solutions you may buy... To be honest it is very unlikely you need any of them...


你可能会觉得这很有用:如何限制和管理Windows 10中的CPU使用率 [ ^ ]如果服务器没有运行Win10,然后快速谷歌应该为您获得其他操作系统的类似信息。
You may find this useful: How to Limit and Manage the CPU Usage in Windows 10[^] If the server does not run Win10, then a quick google should get you similar info for other OSes.


如前所述,如果不知道您的应用程序正在做什么以及如何实现它们,这是无法回答的。 br />


他们应该避免轮询(检查循环内的状态)和调用阻塞函数。通常需要使用事件来创建线程。



如果应用程序执行长时间运行的计算产生高负载,则可能会更改执行这些操作的线程的优先级(请参阅 Thread.Priority Property(System.Threading) [ ^ ])和/或插入睡眠期(通常不使用 Sleep()但其中一个 Wait()带有超时参数的方法,允许处理事件)。
As already mentioned this can't be answered without knowing what your applications are doing and how they are implemented.

They should avoid polling (checking states inside loops) and calling blocking functions. Use events instead which usually requires creating threads.

If applications perform long running calculations producing a high load you might change the priority of the threads performing these operations (see Thread.Priority Property (System.Threading)[^] ) and/or insert sleep periods (usually not using Sleep() but one of the Wait() methods with timeout parameter to allow handling events).


这篇关于CPU很高,运行C#控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆