473,394 Members | 1,867 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,394 software developers and data experts.

CPU usage

Hi, All!

We are developing one app for windows 95/98/Me/NT4.0/2000/XP/2003 using
Visual C++ 6.0. We need to set the % of CPU Usage to app process. Is there
an API to set % of CPU Usage? Can Someone help us?

Thanks in advance.
Nov 17 '05 #1
11 2450
Paulo Eduardo wrote:
Is there an API to set % of CPU Usage?


No.
What are you trying to do?

If your prcess has an endless-loop, then remove it and switch to
event-driven architecture...

If the work of your process is not important, then reduce the priority.

See: SetPriorityClass(..., BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en...orityclass.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Hi, Jochen

Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the 'thread control' sleep the process for 1s.

Thanks in advance.

"Jochen Kalmbach [MVP]" wrote:
Paulo Eduardo wrote:
Is there an API to set % of CPU Usage?


No.
What are you trying to do?

If your prcess has an endless-loop, then remove it and switch to
event-driven architecture...

If the work of your process is not important, then reduce the priority.

See: SetPriorityClass(..., BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en...orityclass.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #3
Hi Paulo!
Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the 'thread control' sleep the process for 1s.


Why do you want to limit your CPU usage? Why not just lower your priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #4
Jochen,
our app will be running in background (background process). Actually, we are
using the default settings for process. The app run when user log on in
windows. Then, for avoid to increase the cpu usage by process, we are trying
to control the cpu usage. Do you consider that only priority will resolve
this problem?

Thanks a lot in advance.

"Jochen Kalmbach [MVP]" wrote:
Hi Paulo!
Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the 'thread control' sleep the process for 1s.


Why do you want to limit your CPU usage? Why not just lower your priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #5
Paulo Eduardo wrote:
Jochen,
our app will be running in background (background process). Actually, we are
using the default settings for process. The app run when user log on in
windows. Then, for avoid to increase the cpu usage by process, we are trying
to control the cpu usage. Do you consider that only priority will resolve
this problem?

Thanks a lot in advance.

"Jochen Kalmbach [MVP]" wrote:

Hi Paulo!

Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the 'thread control' sleep the process for 1s.


Why do you want to limit your CPU usage? Why not just lower your priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

One solution is to: Run at a low priority, see how much CPU time you
used in the last 100 ms (or other reasonable interval) using the APi
sugegsted in this thread and then sleep for the appropriate time if it
exceeded your limit of much much you wanted to load the machine.

Specifically for managing competing processes'resource consumption on
Server 2003 Enterprise and ata Center editions, there is WSRM, you can
read up on what it is and how it works at:
http://www.microsoft.com/technet/pro...556306e91.mspx

Ronald Laeremans
Visual C++ team
Nov 17 '05 #6
No, it won't, if this is the only process in the system that has runnable
threads, nothing will stop the thread to consume 100% of the CPU, if on the
other hand other applications are running and their threads have higher
priority, your lower priority threads will get much less CPU resources, but
be carefull with this, on consumer windows this can lead to thread
starvation.
I'm also not clear on what your actual CPU consumption is, and why you need
to restrict this while it will probably be done automatically when there are
other programs running.
Willy.

"Paulo Eduardo" <Pa**********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Jochen,
our app will be running in background (background process). Actually, we
are
using the default settings for process. The app run when user log on in
windows. Then, for avoid to increase the cpu usage by process, we are
trying
to control the cpu usage. Do you consider that only priority will resolve
this problem?

Thanks a lot in advance.

"Jochen Kalmbach [MVP]" wrote:
Hi Paulo!
> Actually, if I understood you, we are using an event-driven
> architecture,.
> We are using in it c functions and c++ methods that use WMI service. We
> are
> not using one endless loop (for (;;)) too. Is some local of source
> code we
> need to access fixed drives (C:,E:) for search files in them
> (subdirectories
> too). Is it possible to control the cpu usage by process creating one
> thread
> that control the cpu usage of process? For example, If process is using
> more
> than 20% of CPU, the 'thread control' sleep the process for 1s.


Why do you want to limit your CPU usage? Why not just lower your
priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #7
Hi, Willy

Actually, the app process are using almost 40% of cpu usage. About % Cpu
Usage, we need this for avoid to decrease performance of system, and
consequently the user interactivity with it(slowly,freeze,etc). Also, we
will go to develop one part of system that scan fixed drives (c:,e:) and,
probably this will consume more cpu.

Thanks a lot in advance.
Best Regards,
Paulo Eduardo.

"Willy Denoyette [MVP]" wrote:
No, it won't, if this is the only process in the system that has runnable
threads, nothing will stop the thread to consume 100% of the CPU, if on the
other hand other applications are running and their threads have higher
priority, your lower priority threads will get much less CPU resources, but
be carefull with this, on consumer windows this can lead to thread
starvation.
I'm also not clear on what your actual CPU consumption is, and why you need
to restrict this while it will probably be done automatically when there are
other programs running.
Willy.

"Paulo Eduardo" <Pa**********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Jochen,
our app will be running in background (background process). Actually, we
are
using the default settings for process. The app run when user log on in
windows. Then, for avoid to increase the cpu usage by process, we are
trying
to control the cpu usage. Do you consider that only priority will resolve
this problem?

Thanks a lot in advance.

"Jochen Kalmbach [MVP]" wrote:
Hi Paulo!

> Actually, if I understood you, we are using an event-driven
> architecture,.
> We are using in it c functions and c++ methods that use WMI service. We
> are
> not using one endless loop (for (;;)) too. Is some local of source
> code we
> need to access fixed drives (C:,E:) for search files in them
> (subdirectories
> too). Is it possible to control the cpu usage by process creating one
> thread
> that control the cpu usage of process? For example, If process is using
> more
> than 20% of CPU, the 'thread control' sleep the process for 1s.

Why do you want to limit your CPU usage? Why not just lower your
priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


Nov 17 '05 #8
Hi, Jochen

In your response you mentioned 'resolution'. Are you speaking about time
slice of a process?

Thanks a lot in advance.
Best regards,
Paulo Eduardo.

"Jochen Kalmbach [MVP]" wrote:
Hi Paulo!
Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the 'thread control' sleep the process for 1s.


Why do you want to limit your CPU usage? Why not just lower your priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #9
The CPU usage is managed by the OS. Just reduce the priority to increase
the system performance. The system does an automatic load balancing. If
nothing else is running, your application will use close to 100% CPU,
but as soon as other processes come up, it may go down to 0%. I managed
to achieve extremely good results with low priority threads. The thread
works as hard as possible when it gets a chance, but it never takes away
any significant CPU time from other processes.

The actual CPU usage always depends on the current load. If you're only
tunning one application, it will have a high CPU usage. The lower the
priority, the lower the CPU usage during heavy load situations.
Hyperthreading helps significantly too.

Tom

Paulo Eduardo wrote:
Hi, Willy

Actually, the app process are using almost 40% of cpu usage. About % Cpu
Usage, we need this for avoid to decrease performance of system, and
consequently the user interactivity with it(slowly,freeze,etc). Also, we
will go to develop one part of system that scan fixed drives (c:,e:) and,
probably this will consume more cpu.

Thanks a lot in advance.
Best Regards,
Paulo Eduardo.

Nov 17 '05 #10
On Fri, 24 Jun 2005 14:47:03 -0700, "Paulo Eduardo"
<Pa**********@discussions.microsoft.com> wrote:
Hi, Willy

Actually, the app process are using almost 40% of cpu usage. About % Cpu
Usage, we need this for avoid to decrease performance of system, and
consequently the user interactivity with it(slowly,freeze,etc). Also, we
will go to develop one part of system that scan fixed drives (c:,e:) and,
probably this will consume more cpu.
If you reduce the priority, this will prevent your process from
interfering with other processes' CPU use; however, if you're doing
lots of disk I/O, you may need to throttle it manually to prevent
effects on the rest of the system.
"Willy Denoyette [MVP]" wrote:
No, it won't, if this is the only process in the system that has runnable
threads, nothing will stop the thread to consume 100% of the CPU, if on the
other hand other applications are running and their threads have higher
priority, your lower priority threads will get much less CPU resources, but
be carefull with this, on consumer windows this can lead to thread
starvation.
I'm also not clear on what your actual CPU consumption is, and why you need
to restrict this while it will probably be done automatically when there are
other programs running.
Willy.

"Paulo Eduardo" <Pa**********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
> Jochen,
> our app will be running in background (background process). Actually, we
> are
> using the default settings for process. The app run when user log on in
> windows. Then, for avoid to increase the cpu usage by process, we are
> trying
> to control the cpu usage. Do you consider that only priority will resolve
> this problem?
>
> Thanks a lot in advance.
>
>
>
> "Jochen Kalmbach [MVP]" wrote:
>
>> Hi Paulo!
>>
>> > Actually, if I understood you, we are using an event-driven
>> > architecture,.
>> > We are using in it c functions and c++ methods that use WMI service. We
>> > are
>> > not using one endless loop (for (;;)) too. Is some local of source
>> > code we
>> > need to access fixed drives (C:,E:) for search files in them
>> > (subdirectories
>> > too). Is it possible to control the cpu usage by process creating one
>> > thread
>> > that control the cpu usage of process? For example, If process is using
>> > more
>> > than 20% of CPU, the 'thread control' sleep the process for 1s.
>>
>> Why do you want to limit your CPU usage? Why not just lower your
>> priority?
>>
>> To get the process/thread-times you can use
>>
>> See: GetProcessTimes
>> http://msdn.microsoft.com/library/de...ocesstimes.asp
>>
>> or
>>
>> See: GetThreadTimes
>> http://msdn.microsoft.com/library/en...ocesstimes.asp
>>
>> You should be aware, that the resolution is about than 10-15 ms...
>>
>> To implement it correctly you also need to know the number of (logical)
>> processors...
>>
>> See: GetSystemInfo
>> http://msdn.microsoft.com/library/en...systeminfo.asp
>>
>> --
>> Greetings
>> Jochen
>>
>> My blog about Win32 and .NET
>> http://blog.kalmbachnet.de/
>>



--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
Nov 17 '05 #11
Hi Paulo!
In your response you mentioned 'resolution'. Are you speaking about time
slice of a process?


The others have suggested what you can further do... I donĀ“t need to add
something...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #12

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

Similar topics

8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
10
by: rdemyan via AccessMonster.com | last post by:
My app contains utility meter usage. One of the things we have to deal with is when a usage is clearly incorrect. Perhaps someone wrote the meter reading down incorrectly or made a factor of 10...
3
by: Sirisha | last post by:
I am using the following code to get the CPU usage PerformanceCounter myCounter; myCounter = new PerformanceCounter(); myCounter.CategoryName = "Processor"; myCounter.CounterName = "%...
1
by: spacecoyote | last post by:
I tried this: usage = "Something, by Spacecoyote\nusage: %prog file " parser = OptionParser(usage) test.py --help and I expected: Something, by Spacecoyote usage: test.py file
1
by: sowmya.rangineni | last post by:
Ours is a windows based application. When we open the application the CPU usage is 0% and the Memory Usage is 54,324Kb When I open a specific form in a module, the CPU usage is 0% and the...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.