CPU Usage not near 100% when running code

  • Thread starter SpringFlowers AutumnMoon
  • Start date
S

SpringFlowers AutumnMoon

I tested some computation intensive Ruby code. When running, the CPU
usage on the machines are no where near 100%. One is an Intel Hyper
Threading machine. One is an Intel Core 2 Duo.

on the Hyper Threading machine, the CPU usage went up from 10% both to
70% for one and 30% for the other...

on the Core 2 Duo, the CPU usage went from 20% both to about 70% for
both CPU core.

I guess both CPUs know how to distrubute the calculations among two
cores or two virtual cores? But the question is, why not both near
100%? Why allow some slack for CPU idle time?

but then again, if I run a similar program using Python, it is the same
thing. I tried and set the process priority of the programs to the
highest and nothing changed.
 
M

Marcin Raczkowski

SpringFlowers said:
I tested some computation intensive Ruby code. When running, the CPU
usage on the machines are no where near 100%. One is an Intel Hyper
Threading machine. One is an Intel Core 2 Duo.

on the Hyper Threading machine, the CPU usage went up from 10% both to
70% for one and 30% for the other...

on the Core 2 Duo, the CPU usage went from 20% both to about 70% for
both CPU core.

I guess both CPUs know how to distrubute the calculations among two
cores or two virtual cores? But the question is, why not both near
100%? Why allow some slack for CPU idle time?

but then again, if I run a similar program using Python, it is the same
thing. I tried and set the process priority of the programs to the
highest and nothing changed.

becouse ruby VM uses only one processor - always
 
J

John Joyce

your cpu is smarter than you.
the people who design them are smarter than most.
it's like most things, you would be hard pressed to actually get 100%
out of it, and if you did, it would probably be bad.
It probably reserves something for the system.
most likely a question for a systems engineer or you might look on
the ars technica site.
 
R

Robert Klemme

2007/9/18 said:
I tested some computation intensive Ruby code. When running, the CPU
usage on the machines are no where near 100%. One is an Intel Hyper
Threading machine. One is an Intel Core 2 Duo.

on the Hyper Threading machine, the CPU usage went up from 10% both to
70% for one and 30% for the other...

on the Core 2 Duo, the CPU usage went from 20% both to about 70% for
both CPU core.

I guess both CPUs know how to distrubute the calculations among two
cores or two virtual cores? But the question is, why not both near
100%? Why allow some slack for CPU idle time?

but then again, if I run a similar program using Python, it is the same
thing. I tried and set the process priority of the programs to the
highest and nothing changed.

Maybe your process is IO bound - probably without you being aware of
it (e.g. through paging, network IO, IPC or such).

robert
 
S

SpringFlowers AutumnMoon

Robert said:
2007/9/18, SpringFlowers AutumnMoon <[email protected]>:
Maybe your process is IO bound - probably without you being aware of
it (e.g. through paging, network IO, IPC or such).

i can be just running calculations or just the following:

require 'benchmark'

n = 10_000_000
b = 123
c = 456

Benchmark.bm do |x|
x.report { for i in 1..n; a = b + c; end }
x.report { n.times do ; a = b + c; end }
x.report { 1.upto(n) do ; a = b + c; end }
end


If I run the same code on a Mac with single core, the CPU meter will go
to 100%. In the old days when I had a single Intel Windows XP machine,
calculation intensive programs will make it go to 100% too.

if the Ruby VM uses only one core, then why won't one core go to 100%?
 
R

Robert Klemme

2007/9/18 said:
i can be just running calculations or just the following:

require 'benchmark'

n = 10_000_000
b = 123
c = 456

Benchmark.bm do |x|
x.report { for i in 1..n; a = b + c; end }
x.report { n.times do ; a = b + c; end }
x.report { 1.upto(n) do ; a = b + c; end }
end


If I run the same code on a Mac with single core, the CPU meter will go
to 100%. In the old days when I had a single Intel Windows XP machine,
calculation intensive programs will make it go to 100% too.

if the Ruby VM uses only one core, then why won't one core go to 100%?

Probably because the OS moves the process between cores. See whether
you can switch off one core or make the process sticky.

Kind regards

robert
 
P

Phil

-----Original Message-----
From: John Joyce [mailto:[email protected]]
Sent: Tuesday, September 18, 2007 5:03 PM
To: ruby-talk ML
Subject: Re: CPU Usage not near 100% when running code

your cpu is smarter than you.
the people who design them are smarter than most.
it's like most things, you would be hard pressed to actually get 100%
out of it, and if you did, it would probably be bad.
It probably reserves something for the system.
most likely a question for a systems engineer or you might look on
the ars technica site.

Close. It's the OS that usually handles thread scheduling, and it reserves
some power to keep the system responsive. It is actually not that difficult
to get 100% of CPU usage (not recommended on a single-core CPU ;), even
without "badly written software". Video editing or other heavy weight
computational tasks can do that.

This can (and probably is) different for non-x86 implementations (or the
more current variants of x86).

Anyway: that a process doesn't peg out the CPU is a Good Thing in most cases
(in 90% of scenarios, the CPU *time* a thread gets is more meaningful than
the % of cycles).
 
F

forgottenwizard

Probably because the OS moves the process between cores. See whether
you can switch off one core or make the process sticky.

Kind regards

robert

Might be a stupid question, but could it be that there is a latency
somewhere else that could be slowing you down? The OS is the only thing
that should limit your CPU usage, and unless you're using a system quota
(another possiblity), then it should be able to max out your CPU.
 
B

Bill Kelly

From: "Robert Klemme said:
Probably because the OS moves the process between cores. See whether
you can switch off one core or make the process sticky.

Indeed. I don't have a dual-core Windows system at the moment,
but as I recall, the Task Manager provided an extra menu item
for changing the "affinity" of a given process, if you wanted
to force it to run only on a specific core.

Anyway, despite what the graph looks like, one can expect a
non-io-bound loop in Ruby to use 100% of whatever core it's
running on *at the moment*. If you have two cores and your
graph shows more than 50% usage, the portion that's greater
than 50% would be other processes being scheduled in addition
to ruby. (Including the process drawing the graphs.)


Regards,

Bill
 
J

Jano Svitok

Indeed. I don't have a dual-core Windows system at the moment,
but as I recall, the Task Manager provided an extra menu item
for changing the "affinity" of a given process, if you wanted
to force it to run only on a specific core.

Anyway, despite what the graph looks like, one can expect a
non-io-bound loop in Ruby to use 100% of whatever core it's
running on *at the moment*. If you have two cores and your
graph shows more than 50% usage, the portion that's greater
than 50% would be other processes being scheduled in addition
to ruby. (Including the process drawing the graphs.)

Exactly. I have used Process Explorer for setting affinity, but now
I see it's in the Task Manager too.
 
S

SpringFlowers AutumnMoon

the increase from both cores... such as from 20% to 70% in both cores,
seems to indicate that the increase is 100% total... maybe the OS wants
to increase both core some what but not 100% to one core...

that may make sense as if it only runs the process in one core, then 20%
to 100% is only 80% increase... by increasing 50% on both, the usage is
100% while the other OS and app processes still can run in both cores
with ease.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top