Bill Kelly
9/18/2007 4:49:00 PM
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