Problems with Benchmark on ruby 1.8.4 (rhe 5.3)

Yes I know the version is ancient – I’m stuck with it for various
boring reasons we need not go into here.

I have a ruby program that processes logs on an hourly basis for lots
(hundreds) of machines. I want to find out which machines are taking
all the time so I reached for benchmark:

if  $options['time-hosts']
    $log_store.traverse do | dir_name, mach|
       t = Benchmark.measure(mach) { process_host( dir_name, mach )

}
puts " >>>#{t}<<<"
end
end

the puts never gets executed.

I also did a version with bm() do |x|
immediately after the first if and x.report(mach) {}

produced machinename1: machine2: …

I have managed to get measure to behave in simple irb trial. Is there
anything that I must not do in the code that is being benchmarked?

Thanks, Russell

On Mon, Sep 26, 2011 at 6:32 AM, Russell F. [email protected]
wrote:

}

I have managed to get measure to behave in simple irb trial. Is there
anything that I must not do in the code that is being benchmarked?

Dunno. You could try to find out where it hangs with

set_trace_func lambda {|*a| $stderr.puts a.inspect}

But if you don’t find a solution to your problem you can just use
Time.now, e.g.

t0 = Time.now

work

t1 = Time.now
duration = t1 - t0 # Float

You can even wrap that in a simple method

def time
t0 = Time.now
yield
t1 = Time.now
t1 - t0 # Float
end

dur = time { sleep 1.3 }

Kind regards

robert

Thanks for your response Robert!

Robert K. wrote in post #1023772:

Dunno. You could try to find out where it hangs with

set_trace_func lambda {|*a| $stderr.puts a.inspect}

I’ve just realised that my description was a bit misleading – the code
does not hang – process_host executes normally but the puts never gets
executed – weird.

I think this is an old bug – I have had some other odd problems with
this version. I think I’ll quietly install a local version of 1.8.7 and
use that.

I just wanted to be sure that I was not missing something obvious (it
would not be the first time;)

Russell

On Mon, Sep 26, 2011 at 9:49 PM, Russell F. [email protected]
wrote:

I’ve just realised that my description was a bit misleading – the code
does not hang – process_host executes normally but the puts never gets
executed – weird.

I think this is an old bug – I have had some other odd problems with
this version. I think I’ll quietly install a local version of 1.8.7 and
use that.

I just wanted to be sure that I was not missing something obvious (it
would not be the first time;)

Since we don’t know what happens in process_host we can only
speculate. A typical error is to use IO.popen with “w” and to forget
to close the input. The usually Unix processes like cat do not
terminate because there is no EOF on stdin but since you’re not
sending more input you’re in a deadlock situation.

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs