CPU Usage not near 100% when running code

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.

···

--
Posted via http://www.ruby-forum.com/.

SpringFlowers AutumnMoon wrote:

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

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.

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

robert

···

2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

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.

Robert Klemme wrote:

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%?

···

2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

--
Posted via http://www.ruby-forum.com/\.

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).

···

-----Original Message-----
From: John Joyce [mailto:dangerwillrobinsondanger@gmail.com]
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.

--
Phillip Gawlowski

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

···

2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

Robert Klemme wrote:
> 2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

> 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%?

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.

···

On 01:03 Wed 19 Sep , Robert Klemme wrote:

2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:
> Robert Klemme wrote:
> > 2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:
>
> > 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%?

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

Robert Klemme wrote:

> 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%?

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

···

From: "Robert Klemme" <shortcutter@googlemail.com>

2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

> 2007/9/18, SpringFlowers AutumnMoon <summercoolness@gmail.com>:

For anyone who wants to give it a try, you can set core / CPU affinity on
non Windows platform too from Ruby:

http://snippets.dzone.com/posts/show/3865

Cheers,
Peter Cooper
http://www.rubyinside.com/

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

···

On 9/18/07, Bill Kelly <billk@cts.com> wrote:

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.)

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.

···

--
Posted via http://www.ruby-forum.com/.