user1534113
user1534113

Reputation: 23

application not using 100% of the CPU

When I run an application I wrote on one machine, Windows 7 Professional 32 bit SP 1, it runs just fine and uses 100% of the CPU in the system.

However, when I run the same application on a Windows Server 2008, I do not see 100% CPU usage.

Why does it not use 100% of the CPU as well, and how can I make it so that it does?

Upvotes: 1

Views: 3715

Answers (2)

Mike Dunlavey
Mike Dunlavey

Reputation: 40669

The percent of CPU that a program uses has nothing to do with how efficient it is.

It has everything to do with the CPU just feeling like doing other things some of the time.

If fact, if your program does any I/O, the CPU percent will go down just because when your program is waiting for that, it's not running.

Upvotes: 1

thecoshman
thecoshman

Reputation: 8650

Well, normally you do not want to be using 100% CPU, as you want to leave your self head room for when you have increased load. Usually a program will not use the CPU all the time, as it will start to become limited by other factors, usually I/O.

Take for instance a GUI application, until a user clicks something, the is nothing for it do, other then keep waiting for user input.

You might foolishly write this as

while(true){
  if(there is user input){
    use the user input
  }
}

This will burn up the CPU, as it will run this loop really fast. So a canny shopper might realise that the user can cope with say, an up to 50 ms delay between clicking and response. and so add in some sort of sleep, such as...

while(true){
  if(there is user input){
    use the user input
  }
  sleep for 50 ms
}

it is important to give the CPU a chance to do other things, as they are important to, else your program is like that fat kid who just sticks his head under the icecream machine and never lets any one else have some tasty tasty icecream.

edit

I love me a metaphor, so here is one for you.

Think of CPU usage as roads and programs as cars, if the roads are all clear, then it's relatively safe for your car to burn rubber and go as fast as it can down the streets. The more cars there are, the more they are going to have to yield for each other, let wait for people to turn off or on.

If you where to dedicate your road (CPU) for something like racing (gaming) you would be inclined to remove things like pedestrians and non racing cars (other programs) so that you can more safely go as fast as possible.

Now, I never said I was any good at metaphors. And remember drive safe, and enjoy the icecream!

Upvotes: 6

Related Questions