473,778 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2488
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: SetPriorityClas s(..., BELOW_NORMAL_PR IORITY_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: SetPriorityClas s(..., BELOW_NORMAL_PR IORITY_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'resou rce 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**********@d iscussions.micr osoft.com> wrote in message
news:36******** *************** ***********@mic rosoft.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,freez e,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**********@d iscussions.micr osoft.com> wrote in message
news:36******** *************** ***********@mic rosoft.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,freez e,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

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

Similar topics

8
3675
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 256 MB of Ram while the other has 2 GB of Ram. On the machine with less Ram, the process takes about 1 MB of Ram. On the machine with more Ram, it uses 9 MB of Ram. Is this normal and expected behavior?
2
460
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 the app I load some things into memory for global use of the app but I'll use only 2 starting forms to explain the situation) situation 1 start app with form 1 (72mb memory usage), show form 2 and hide form 1 (89 mb memory usage
3
4149
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 periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
26
10884
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 compiles the same solution much faster (about 10 seconds for the first project). My home computer is only marginally faster than the one I have at the office (P4 2.53 vs. P4 2.4, same amount of RAM). On the slow machine, the CPU usage is very low,...
10
2100
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 error when entering the reading, etc. At other times the usage is zero or somehow was entered as a negative number. So I'm thinking about adding functionality to search for such anomalies. For instance, show months where the meter reading is...
3
9403
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 = "% Processor Time"; myCounter.InstanceName = "_Total"; for(int i=0; i < 20; i++)
1
1997
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
2875
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 Memory Usage increases accordingly (67,730 Kb). Now when I lock and unlock the System the CPU usage increases to 50% with the Memory Usage being 67,730 kb.
2
2470
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 interactivity. The service suffers from a lot of restarts since discountasp enforces a 100mb per worker thread limit and when you top it, the service gets restarted. When there is a lot of traffic on the site, this happens
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.