CPU utilization
CPU utilization
Hi all,
I noticed that the Windows Task Manager indicates that my (small, CPU intensive) PB applications are using only 50% of the CPU time, the other 50% going to System Idle. Both applications I wrote so far seem to get almost exactly 50%. Initially I thought this was because I was using the Demo Version, but I just bought the full version and the same thing is happening even if I run the executable by itself. Can anybody comment on or explain this to me? I hope I can get close to 100% CPU utilization somehow!
I am also a bit disappointed that the applications do not run noticably faster as a compiled excutable than under the debugger in the demo version.... Am I doing something wrong?
Thanks.
I noticed that the Windows Task Manager indicates that my (small, CPU intensive) PB applications are using only 50% of the CPU time, the other 50% going to System Idle. Both applications I wrote so far seem to get almost exactly 50%. Initially I thought this was because I was using the Demo Version, but I just bought the full version and the same thing is happening even if I run the executable by itself. Can anybody comment on or explain this to me? I hope I can get close to 100% CPU utilization somehow!
I am also a bit disappointed that the applications do not run noticably faster as a compiled excutable than under the debugger in the demo version.... Am I doing something wrong?
Thanks.
You wouldn't want an application to use %100 of the CPU - even %50 is pretty high if it's constant usage (unless you're constantly doing something of course). For the most part, applications will use as much CPU as they need to get the job done. Of course all this depends on what kind of applications you're writing too... What are you working on? Business apps? Games?
As far as the debugger does - you might not see a gigantic difference in speed. Even PB with the debugger enabled creates executables that run pretty damn fast!
Good luck!
As far as the debugger does - you might not see a gigantic difference in speed. Even PB with the debugger enabled creates executables that run pretty damn fast!
Good luck!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Hi Karbon,
I guess I am not sure what the definition of "application" is ....
Anyway the two "programs" (safer) should be running continuously at full blast. The first is a very simple "ecological" simulation that simulates a closed world with with some geography, growing grass and rabbits that eat, multiply and die etc. During the evolution the program needs no input and is constantly doing calculations to advance the evolution, so I think it should be grabbing as much CPU as it can get...
If anybody has an interest they can find the source code at
home.netspeed.com.au/dekool/RabbitWorld.pb
A much shorter program that also is running continously but only gets 50% is
home.netspeed.com.au/dekool/Life2.pb
Cheers.
I guess I am not sure what the definition of "application" is ....
Anyway the two "programs" (safer) should be running continuously at full blast. The first is a very simple "ecological" simulation that simulates a closed world with with some geography, growing grass and rabbits that eat, multiply and die etc. During the evolution the program needs no input and is constantly doing calculations to advance the evolution, so I think it should be grabbing as much CPU as it can get...
If anybody has an interest they can find the source code at
home.netspeed.com.au/dekool/RabbitWorld.pb
A much shorter program that also is running continously but only gets 50% is
home.netspeed.com.au/dekool/Life2.pb
Cheers.
Application, program, same thing to me 
These sims are pretty cool! I can see myself getting distracted playing with them for quite a while! Thanks!
While running both shoot my 3Ghz P4 running XP Pro SP1 up to %100 CPU utilization... What kind of hardware/OS are you working with?

These sims are pretty cool! I can see myself getting distracted playing with them for quite a while! Thanks!
While running both shoot my 3Ghz P4 running XP Pro SP1 up to %100 CPU utilization... What kind of hardware/OS are you working with?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
OK, here some more information about my CPU usage problem that may or may not help:
running PB app : 50% PB 50% Idle
running two PB apps : 33 % PB1 33% PB2 33% Idle
PB app + Moviemaker : 75% Movie 25 % PB app 0% Idle
I checked the priority of the different tasks, PB apps and Moviemaker both have 8 , System Idle 0 ???
I also did a more detailed comparison between running times of compiled executables and the same program running under the debugger and I can not measure a significant difference at all. This surprises me a lot, since I use many statements involving arrays, and I would think the array bound checking alone would make some difference...
running PB app : 50% PB 50% Idle
running two PB apps : 33 % PB1 33% PB2 33% Idle
PB app + Moviemaker : 75% Movie 25 % PB app 0% Idle
I checked the priority of the different tasks, PB apps and Moviemaker both have 8 , System Idle 0 ???
I also did a more detailed comparison between running times of compiled executables and the same program running under the debugger and I can not measure a significant difference at all. This surprises me a lot, since I use many statements involving arrays, and I would think the array bound checking alone would make some difference...
-
- User
- Posts: 30
- Joined: Wed Aug 06, 2003 5:52 pm
- Location: Florida, USA
CPU Usage
Most PCs only have one CPU (Central Processing Unit, or the "brains" of the comuter) which has to do all the work, even in a multi-tasking environment where several programs (or applications) are running at once. IIf you open up the Tasl Manager (use Ctrl+Alt+Del) and then pick Processes, you will see every preloaded process (program) and the currently running processes all there together. Each of these is taking up both memory and CPU time. Even though additional time is being reported to be System Idle time, it is not actually idle, but being used for internal maintenance - recovering resources, allocating resources, performing delayed write operations, updating directories and the allocation tables, verifying disk integrity, managing virtual and real memory, and so on. So call this system idle is a misnomer. But the system will cut back on system idel time if you add more processes to be run, or if you open more windows, since these also involve processes.
The percentage range of CPU usage from 0% to 100% is nonlinear, but rather expodential. That is, the rise from 9% to 50% is relatively flat, while the rise from 50% to 100% becomes increasingly steep. It fact, it sppears to be only a short leap from 50% to 100%, and at 100%, the CPU enters a state called "threshing", where it is spending so much effort on just trying to manage its many resources and requests, and to swap program segments in and out of memory with the swap area on the hard drive, that very little real work in terms of the applications themselves is getting done. In extreme cases, your machine will "freeze up" and will not even respond to the mouse. In this state you can expect recovery time to run into hours, even days, and the more you fuss with the mouse or keyboard, the longer it will take. Most people just give up and perform a hardware reset or kill power.
In other words, running at about 50% is close to optimal in terms of balancing performance between the different applications and other administrative needs that have to be carried out by the CPU. Trying to push usage to 100% is wrongheaded, because you are then overloading your system to the point where it will verge on seizing up. Remember, a 100% used CPU simply cannot do any more -- there is no such thing as a 110% effort out of a CPU.
If you are one of those looking at 100% usage, then yhou had better consider what is causing your PC to overload in that manner. Possibly you need more memory, a larger swap file for your Virtual Memory setting (look under System in you Control Panel), or need to look at all the processes you currently have loaded and running at one time. In my case, I carry a fairly hefty load of 59 processesd, including anit-virus and firewall processes, whereas my wife's PC gets by with just 42 processes.
Note that some windows systems allow you to designate how much of the CPU time will be given to foreground process and how much to background processes, with the possibility you will give way too much to the foreground processes and drive your system to the brink of overload. Other windows (including 2000) instead allow whether to optimize your usage in favor of your applications or other processes. If you regularly push the 100% limit, you might have to take the step of changing this setting to favor your background processes.
The percentage range of CPU usage from 0% to 100% is nonlinear, but rather expodential. That is, the rise from 9% to 50% is relatively flat, while the rise from 50% to 100% becomes increasingly steep. It fact, it sppears to be only a short leap from 50% to 100%, and at 100%, the CPU enters a state called "threshing", where it is spending so much effort on just trying to manage its many resources and requests, and to swap program segments in and out of memory with the swap area on the hard drive, that very little real work in terms of the applications themselves is getting done. In extreme cases, your machine will "freeze up" and will not even respond to the mouse. In this state you can expect recovery time to run into hours, even days, and the more you fuss with the mouse or keyboard, the longer it will take. Most people just give up and perform a hardware reset or kill power.
In other words, running at about 50% is close to optimal in terms of balancing performance between the different applications and other administrative needs that have to be carried out by the CPU. Trying to push usage to 100% is wrongheaded, because you are then overloading your system to the point where it will verge on seizing up. Remember, a 100% used CPU simply cannot do any more -- there is no such thing as a 110% effort out of a CPU.
If you are one of those looking at 100% usage, then yhou had better consider what is causing your PC to overload in that manner. Possibly you need more memory, a larger swap file for your Virtual Memory setting (look under System in you Control Panel), or need to look at all the processes you currently have loaded and running at one time. In my case, I carry a fairly hefty load of 59 processesd, including anit-virus and firewall processes, whereas my wife's PC gets by with just 42 processes.
Note that some windows systems allow you to designate how much of the CPU time will be given to foreground process and how much to background processes, with the possibility you will give way too much to the foreground processes and drive your system to the brink of overload. Other windows (including 2000) instead allow whether to optimize your usage in favor of your applications or other processes. If you regularly push the 100% limit, you might have to take the step of changing this setting to favor your background processes.
Has-been Wanna-be (You may not like what I say, but it will make you think)
Hi Oldefoxx,
I guess in general you shouldn't overload your computer, but for me speed will be important, since I hope to code some scientific simulation/modelling problems that may take hours to run. So a factor of two is a big thing.
I still think something is not working the way it should, first because other applications on my computer that use a lot of CPU for a long time -do- use about 97-98% of CPU resources, and second because other people running my PB code on their computer get close to 100% ...
I know next to nothing about the internal workings of Windows, but I would think that as long as the important system processes have a higher priority it should not be problem. At the research institute where I used to work our computers were running at full capacity all the time.
Cheers.
I guess in general you shouldn't overload your computer, but for me speed will be important, since I hope to code some scientific simulation/modelling problems that may take hours to run. So a factor of two is a big thing.
I still think something is not working the way it should, first because other applications on my computer that use a lot of CPU for a long time -do- use about 97-98% of CPU resources, and second because other people running my PB code on their computer get close to 100% ...
I know next to nothing about the internal workings of Windows, but I would think that as long as the important system processes have a higher priority it should not be problem. At the research institute where I used to work our computers were running at full capacity all the time.
Cheers.
-
- User
- Posts: 30
- Joined: Wed Aug 06, 2003 5:52 pm
- Location: Florida, USA
Esperience is the best teaher.
If you can get to 100% and not find any downside to your efforts, then why not. But pushing foreground operations at the cost of your background functions is problematic. Finetuning the results then becomes somewhat difficult, unless you have tools for that purpose. A good memory manager, like Memory Turbo or Memory Zipper can be a great help.
A couple of years ago, I acted as a beta texter to the new compilers from PowerBASIC. This was for their current PB/CC and PB/DLL products. A couple of other beta testers complained at one point that the programs that they were compiling were usurping all the available cycles from the CPU, and as a result, only their compiled programs were getting processed. Everything else basically stopped. They could not open or close windows, click on the task bar, or perform any other action through the keyboard or mouse. And background tasks came to a complete stop.
If you have a dedicated machine and want just that one task to run, then that may be fine, but most of us like the option of minimizing a task that is going to take awhile and checking our e-mail, or bringing up a web site to visit one of our favorite online haunts. So be careful what you wish for.
A couple of years ago, I acted as a beta texter to the new compilers from PowerBASIC. This was for their current PB/CC and PB/DLL products. A couple of other beta testers complained at one point that the programs that they were compiling were usurping all the available cycles from the CPU, and as a result, only their compiled programs were getting processed. Everything else basically stopped. They could not open or close windows, click on the task bar, or perform any other action through the keyboard or mouse. And background tasks came to a complete stop.
If you have a dedicated machine and want just that one task to run, then that may be fine, but most of us like the option of minimizing a task that is going to take awhile and checking our e-mail, or bringing up a web site to visit one of our favorite online haunts. So be careful what you wish for.
Has-been Wanna-be (You may not like what I say, but it will make you think)
-
- Enthusiast
- Posts: 202
- Joined: Sun Apr 27, 2003 4:44 am
- Location: Michigan, USA
- Contact:
Hi Tiuri,
I tried both of your samples and hit 100% CPU Usage. This is just a thought and I don't know about this for sure but does your procesor have Hyper-Threading? I think you can chck in your 'Task Manager' And see if you see to 2 graphs for CPU history. I wonder if that has anything to do with the 50% and if you had your app fire off another thread you could then hit 100%.
This is just a thought because I don't have a P4 but I know a bit about them.
I tried both of your samples and hit 100% CPU Usage. This is just a thought and I don't know about this for sure but does your procesor have Hyper-Threading? I think you can chck in your 'Task Manager' And see if you see to 2 graphs for CPU history. I wonder if that has anything to do with the 50% and if you had your app fire off another thread you could then hit 100%.
This is just a thought because I don't have a P4 but I know a bit about them.
-Ryan
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
Hi Ryan,
Thanks for your reply. I checked and I -indeed- have 2 graphs for CPU history, so I guess I have hyperthreading. The fact that i get exactly 50 % had made me think about this possibility before. (But I had already tried to implicate hyperthreading for another problem I posted about recently that turned out to have nothing to do with it, so I was reluctant to mention it again so as not to appear silly...)
I would have hoped however that HT does not go so far as to give each thread no more than 50% of the processor. Splitting all tasks into two threads should not be the programmers responsibility.
Without having tried, I would guess that this would still not solve the problem completely since (as I mentioned above) when I run 2 instances of the application simultaneously I still get only 33% for each task and 33% system idle.
It would nice if somebody with a relatively new PC that also has hyperthreading could try my code and see if they get the same effect.
Thanks for your reply. I checked and I -indeed- have 2 graphs for CPU history, so I guess I have hyperthreading. The fact that i get exactly 50 % had made me think about this possibility before. (But I had already tried to implicate hyperthreading for another problem I posted about recently that turned out to have nothing to do with it, so I was reluctant to mention it again so as not to appear silly...)
I would have hoped however that HT does not go so far as to give each thread no more than 50% of the processor. Splitting all tasks into two threads should not be the programmers responsibility.
Without having tried, I would guess that this would still not solve the problem completely since (as I mentioned above) when I run 2 instances of the application simultaneously I still get only 33% for each task and 33% system idle.
It would nice if somebody with a relatively new PC that also has hyperthreading could try my code and see if they get the same effect.
My machine's hardware is exactly the same as yours down to the video card. Only difference is that I'm running XP Pro. I get %100 CPU utilization.
Last edited by Karbon on Thu Aug 28, 2003 3:05 am, edited 1 time in total.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
-
- Enthusiast
- Posts: 202
- Joined: Sun Apr 27, 2003 4:44 am
- Location: Michigan, USA
- Contact:
Huh that is wierd. I wouldn't think it would limit but just do a better job at minimizing the use of the processor.
On a side note: Do you guys feel like it realy makes any difference having hyper-threading? I am assuming not because Tiuri didn't even notice. (Not meaning anything just that it didn't make you fall off your chair and scream "Those Intel people are geniouses!!!")
On a side note: Do you guys feel like it realy makes any difference having hyper-threading? I am assuming not because Tiuri didn't even notice. (Not meaning anything just that it didn't make you fall off your chair and scream "Those Intel people are geniouses!!!")

-Ryan
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
I don't even begin to understand all I know about hyperthreading. I read a white paper on it and on paper it does seem to do *something*. In reality I don't really know if it's a help or not... Maybe I'll see once I finish this threaded server app...
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net