Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 11-Apr-18 21:25pm

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...
 
Share this answer
 
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.
 
Share this answer
 
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).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900