Forum: Ruby process-per-connection with drb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fe6a008c1e3065327d1f1b007d8f1362?d=identicon&s=25 Paul Brannan (cout)
on 2007-01-30 23:07
(Received via mailing list)
Reading through drb.rb, I see that drb uses a thread-per-connection
model.  I have some C++ extensions that I want to provide access to via
a drb server.  Unfortunately, these extensions are not safe to use with
ruby's green threads, and it is impossible to make them thread-safe,
given the mechanism ruby uses to switch thread contexts.

I want to instead use a process-per-connection model and have a pool of
processes waiting to handle requests.  How should I go about
implementing this?

Paul
E0c987f680cd640c14912ebfbf0f0f07?d=identicon&s=25 unknown (Guest)
on 2007-01-31 05:17
(Received via mailing list)
On 1/30/07, Paul Brannan <pbrannan@atdesk.com> wrote:
> Reading through drb.rb, I see that drb uses a thread-per-connection
> model.  I have some C++ extensions that I want to provide access to via
> a drb server.  Unfortunately, these extensions are not safe to use with
> ruby's green threads, and it is impossible to make them thread-safe,
> given the mechanism ruby uses to switch thread contexts.
>
> I want to instead use a process-per-connection model and have a pool of
> processes waiting to handle requests.  How should I go about
> implementing this?

Well, I will make no comment about how you "should" go about this, but I
hacked this together:

See: http://raa.ruby-lang.org/project/slave/

# slaved.rb:
require 'drb'
require 'slave'

class SlaveDaemon
  attr_reader :slave

  def initialize klass
    puts "Initializing a new slave of class #{klass}."
    @slave = Slave::new{ eval "#{klass}.new" }
  end
end

DRb.start_service('druby://localhost:9000', SlaveDaemon)
DRb.thread.join

#client.rb:
require 'drb'

DRb.start_service()
SlaveDaemon = DRbObject.new(nil, 'druby://localhost:9000')

s = SlaveDaemon.new(Array)
a = s.slave.object

a[1] = 1
a[2] = 2
a[4] = 4

a.each do |i|
  p i
end

> ruby slaved.rb
Initializing a new slave of class Array.

> ruby client.rb
nil
1
2
nil
4
918c6daad03c85e51ad1a11f57017947?d=identicon&s=25 Devin Mullins (twifkak)
on 2007-02-01 02:08
(Received via mailing list)
brabuhr@gmail.com wrote:
> On 1/30/07, Paul Brannan <pbrannan@atdesk.com> wrote:
>> I want to instead use a process-per-connection model and have a pool of
>> processes waiting to handle requests.  How should I go about
>> implementing this?
> Well, I will make no comment about how you "should" go about this, but I
> hacked this together:

There's also ara's ruby queues thing.

Devin
This topic is locked and can not be replied to.