Multithread in DRb

Suppose I want to create 6 threads in client side
following: http://segment7.net/projects/ruby/drb/introduction.html

which one is better at cleint side?

require ‘drb’

DRb.start_service
remote_array = DRbObject.new nil, ARGV.shift

for i in 1…6
children[i]=Thread.New do
remote_array << 1
----do other things
end

–rest of the program

OR

require ‘drb’

for i in 1…6
children[i]=Thread.New do
DRb.start_service
remote_array = DRbObject.new nil, ARGV.shift
remote_array << 1
----do other things
end

–rest of the program

To point out whats in my mind, in the later program I am getting a new
instance of the remote object, so it will not have any resource
conflict.

What do you feel? 1st one or second one is better? AND WHY?

ajay paswan wrote in post #1078978:

Suppose I want to create 6 threads in client side
following: http://segment7.net/projects/ruby/drb/introduction.html

which one is better at cleint side?

The second appears to be broken:

  1. It calls DRb.start_service 6 times
  2. It calls ARGV.shift 6 times - unless your intention is to have 6
    different DRB URLs, so that you are talking to six diffferent remote
    arrays, and push one item onto each? Then that’s something completely
    different.

To point out whats in my mind, in the later program I am getting a new
instance of the remote object, so it will not have any resource
conflict.

DRb gives absolutely zero locking. If two clients make concurrent
accesses to the same remote object, then they will cause concurrent
method calls to execute at the server side. Tthat is, your server object
must be thread-safe.

It does not matter if you make one local proxy object and invoke it from
six threads, or six separate proxy objects onto the same remote object
invoked from six threads.

DRb is effectively transparent to all this. If your program works
correctly with six local threads accessing a single local object
concurrently, then it will be fine with six threads accessing a single
remote object over DRb.

ajay paswan wrote in post #1078981:

Then that’s something completely
different.
why? and how?

The second code you put consumes 6 elements from ARGV. You might be
passing the same URL 6 times, or you might be passing 6 different URLs
pointing to 6 different remote objects.

One array is different to 6 separate arrays.

please see my post: http://www.ruby-forum.com/topic/4406522#new

and how does that relate to DRb?

I am in a problem where a thread becomes locked, all other threads are
working fine which does not have to create a new browser, else it
stucks.

It seems you are talking to a Watir object; I have no idea if one of
those is thread-safe or not.

Then that’s something completely
different.
why? and how?

please see my post: http://www.ruby-forum.com/topic/4406522#new

I am in a problem where a thread becomes locked, all other threads are
working fine which does not have to create a new browser, else it
stucks.

I have no clue how to solve this issue.
Kindly help.

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