473,385 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to limit CPU utilization in .NET app?

I have a Windows service that's built with .NET. The process is meant to run
in the background and not suck up too much CPU time. I set the thread
priority for the various threads in the service to Below Normal, but I'm
still getting reports that the service is making a noticable impact on
overall machine performance.

I stuck some Thread.Sleep calls in a various places in the code, but that
doesn't help much, since the service makes single API calls that are fairly
processor intesive (such as computing the checksum on a file) and can't be
broken down any further.

Is there some API (.NET or otherwise) or something that will allow me to to
say "Don't ever use more than 10% of the user's CPU time"?

Thanks
Jul 21 '05 #1
3 3729
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to limit the CPU utilization
in your windows service. If there is any misunderstanding, please feel free
to let me know.

As far as I know, there isn't such method to achieve this in .NET framework
or through Win32 API. Since CPU utilization is a caculated number by the
operating system, we can't simply tell the app that "Don't ever use more
than 10% of the user's CPU time", because the application doesn't know
anything about the utilization.

Setting the thread priority to a lower level might help. But it only makes
the thread sleep when there are other high priority threads available. If
no other threads, this thread also takes high CPU usage, if needed.

I think the only thing we can do is to make some Thread.Sleep call with
long sleep time. However, if there is a single CPU consuming API call in
the app, I don't think we can do much to avoid this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Thanks for the helpful reply. You did understand the issue correctly.

"Kevin Yu [MSFT]" wrote:
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to limit the CPU utilization
in your windows service. If there is any misunderstanding, please feel free
to let me know.

As far as I know, there isn't such method to achieve this in .NET framework
or through Win32 API. Since CPU utilization is a caculated number by the
operating system, we can't simply tell the app that "Don't ever use more
than 10% of the user's CPU time", because the application doesn't know
anything about the utilization.

Setting the thread priority to a lower level might help. But it only makes
the thread sleep when there are other high priority threads available. If
no other threads, this thread also takes high CPU usage, if needed.

I think the only thing we can do is to make some Thread.Sleep call with
long sleep time. However, if there is a single CPU consuming API call in
the app, I don't think we can do much to avoid this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
You're welcome. Thanks for sharing your experience with all the people
here. If you have any questions, please feel free to post them in the
community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anks | last post by:
hi I am testing my applet to servlet communication program using appletviewer. as soon as i start the applet the cpu utilization reaches to 100%.I am using apache tomcat 4.1 application...
1
by: 1944USA | last post by:
I have a C# application written as a Windows Service. It spawns a number of threads, each thread has very large memory intensive processes running on it. I can keep adding threads as long as the...
3
by: john | last post by:
I don't want to know what the CPU utilization is right now. I want to get the average utilization over the last, for example, hour. So I came up with a method where I would get a Process object...
0
by: bimalendug | last post by:
Hi All, I'm using the .NET performance counters to calculate the network utilization. But this value exceeds 100%. In most of the cases, it is very similar to the one shown in the task-manager....
3
by: Dathon | last post by:
I have a Windows service that's built with .NET. The process is meant to run in the background and not suck up too much CPU time. I set the thread priority for the various threads in the service...
0
by: spider007 | last post by:
i want to find out the CPU Utilization per application in my DB. The problem is that we have OLTP and DSS transactions happening on the same server and we are not able to convince the client that the...
0
by: PRR | last post by:
with WMI class Win32_Process i can get most details of Processes running one Pc.. except CPU utilization... THe class for CPU utilization u need to use Win32_PerfFormattedData_PerfProc_Process ...
1
by: Kaheru | last post by:
memory utilization increase? This is because when i try to keep track of the CPU utilization and memory utilization of my FTP server process (ftpserver.exe), the CPU utilization increase, but the...
7
by: balach | last post by:
hi all, i am new in .NET, some body please help me regarding calculating total cpu utilization and RAM memory utilization in percentage (Accurately) on page load event of ASP.NET. i found the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.