[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CPU Usage not near 100% when running code

SpringFlowers AutumnMoon

9/18/2007 2:44:00 PM

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

10 Answers

Marcin Raczkowski

9/18/2007 2:57:00 PM

0

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

John Joyce

9/18/2007 3:03:00 PM

0

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.

Robert Klemme

9/18/2007 3:21:00 PM

0

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.

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

robert

SpringFlowers AutumnMoon

9/18/2007 3:50:00 PM

0

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

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

Robert Klemme

9/18/2007 4:03:00 PM

0

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

Phillip Gawlowski

9/18/2007 4:17:00 PM

0



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

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

--
Phillip Gawlowski


forgottenwizard

9/18/2007 4:39:00 PM

0

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
>

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.


Bill Kelly

9/18/2007 4:49:00 PM

0


From: "Robert Klemme" <shortcutter@googlemail.com>
> 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.

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



Jano Svitok

9/18/2007 8:51:00 PM

0

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

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

SpringFlowers AutumnMoon

9/18/2007 11:46:00 PM

0


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