[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Inter-Process Messaging

Daniel DeLorme

10/10/2007 7:11:00 AM

What are the possibilities in ruby for passing information from one
process to another? Specifically, I'm thinking of messaging between a
parent process and its forked child.

Right now I can think of some messaging primitives:
- TCPServer/TCPSocket
- UNIXServer/UNIXSocket (unstable?)
- IO.pipe (doesn't need port#)
- Process.kill (impossible to send data)

And some messaging libraries:
- DRb (standard)
- eventmachine (efficient?)

...what else? And, if anyone has the experience, what are the
advantages/disadvantages of each in terms of speed, reliability, system
resources?

Thanks,
Daniel

26 Answers

Markus Schirp

10/10/2007 9:07:00 AM

0

Am Wed, 10 Oct 2007 16:11:15 +0900
schrieb Daniel DeLorme <dan-ml@dan42.com>:

> What are the possibilities in ruby for passing information from one
> process to another? Specifically, I'm thinking of messaging between a
> parent process and its forked child.
>
> Right now I can think of some messaging primitives:
> - TCPServer/TCPSocket
> - UNIXServer/UNIXSocket (unstable?)
> - IO.pipe (doesn't need port#)
> - Process.kill (impossible to send data)
>
> And some messaging libraries:
> - DRb (standard)
> - eventmachine (efficient?)
>
> ...what else? And, if anyone has the experience, what are the
> advantages/disadvantages of each in terms of speed, reliability,
> system resources?
>
> Thanks,
> Daniel
>

shared memory?

I don't expect UNIXSocket to be unstable. I'm running over 2 years
with using ruby's socket library without problems. Dont forget to
remove the created socket if your process ends :)

M. Edward (Ed) Borasky

10/10/2007 2:39:00 PM

0

Francis Cianfrocca wrote:
> On 10/10/07, Daniel DeLorme <dan-ml@dan42.com> wrote:
>> What are the possibilities in ruby for passing information from one
>> process to another? Specifically, I'm thinking of messaging between a
>> parent process and its forked child.
>>
>> Right now I can think of some messaging primitives:
>> - TCPServer/TCPSocket
>> - UNIXServer/UNIXSocket (unstable?)
>> - IO.pipe (doesn't need port#)
>> - Process.kill (impossible to send data)
>>
>> And some messaging libraries:
>> - DRb (standard)
>> - eventmachine (efficient?)
>>
>> ...what else? And, if anyone has the experience, what are the
>> advantages/disadvantages of each in terms of speed, reliability, system
>> resources?
>
>
>
> Intramachine messaging with any of the technologies you mentioned will be
> pretty lightweight. The usual thing one tries to do with related processes
> is to open a pipe or a socketpair in the parent. Then after the fork, just
> send data over the sockets.
>

There's also a Ruby MPI binding, but I'm not sure how well maintained it
is. I had trouble tracking it down on the web. So I'd go with
EventMachine, because that *is* well maintained.



Daniel DeLorme

10/10/2007 2:42:00 PM

0

Markus Schirp wrote:
>> What are the possibilities in ruby for passing information from one
>> process to another? Specifically, I'm thinking of messaging between a
>> parent process and its forked child.
>
> shared memory?

Is there a ruby lib to handle shared memory? Also, I can see how it can
be used for "passing information", but for messaging between processes
wouldn't it require constant polling to check if a message is waiting in
the shared memory?

> I don't expect UNIXSocket to be unstable. I'm running over 2 years
> with using ruby's socket library without problems. Dont forget to
> remove the created socket if your process ends :)

I just vaguely remember reading in some mailing list or blog something
along the lines that "unix domain sockets are flaky". I might have
misunderstood.

Daniel

James Gray

10/10/2007 2:45:00 PM

0

On Oct 10, 2007, at 9:39 AM, M. Edward (Ed) Borasky wrote:

> So I'd go with EventMachine, because that *is* well maintained.

I would go with a pipe, because it's easy and sounds like it's all
that's needed here. I'm an EventMachine fan, but don't underestimate
the trivial approach.

James Edward Gray II

M. Edward (Ed) Borasky

10/10/2007 3:05:00 PM

0

James Edward Gray II wrote:
> On Oct 10, 2007, at 9:39 AM, M. Edward (Ed) Borasky wrote:
>
>> So I'd go with EventMachine, because that *is* well maintained.
>
> I would go with a pipe, because it's easy and sounds like it's all
> that's needed here. I'm an EventMachine fan, but don't underestimate
> the trivial approach.
>
> James Edward Gray II
>
>

Well, if the architecture is *always* going to be "parent-forked child
message passing on a single machine", sure. But what if the task grows
beyond the capabilities of that architecture? Remember, I'm one of those
people who's in *favor* of "premature" optimization. :)

But seriously, Ruby has so many user-friendly ways to do concurrency
both inside a single machine and across machines that I wouldn't limit
myself to parent-forked child message passing on a single machine. I'd
use EventMachine because it's more flexible. And to the person who
suggested "shared memory", I'd say simply, "Bah!" :)

Jay Levitt

10/10/2007 4:10:00 PM

0

On Wed, 10 Oct 2007 16:11:15 +0900, Daniel DeLorme wrote:

> What are the possibilities in ruby for passing information from one
> process to another? Specifically, I'm thinking of messaging between a
> parent process and its forked child.

It may be a bit heavyweight for what you want, but there's ActiveMessaging:

http://www.infoq.com/articles/intro-active-messa...


--
Jay Levitt |
Boston, MA | My character doesn't like it when they
Faster: jay at jay dot fm | cry or shout or hit.
http://... | - Kristoffer

ara.t.howard

10/10/2007 4:14:00 PM

0


On Oct 10, 2007, at 1:11 AM, Daniel DeLorme wrote:

> What are the possibilities in ruby for passing information from one
> process to another? Specifically, I'm thinking of messaging between
> a parent process and its forked child.
>
> Right now I can think of some messaging primitives:
> - TCPServer/TCPSocket
> - UNIXServer/UNIXSocket (unstable?)
> - IO.pipe (doesn't need port#)
> - Process.kill (impossible to send data)
>
> And some messaging libraries:
> - DRb (standard)
> - eventmachine (efficient?)
>
> ...what else? And, if anyone has the experience, what are the
> advantages/disadvantages of each in terms of speed, reliability,
> system resources?
>
> Thanks,
> Daniel

this is, by far, the easiest approach - it addresses exactly your
problem by sticking a drb server in a forked child. the child has
arrangements made such that it can *never* outlive it's parent:

cfp:~ > cat a.rb
require 'slave' ### gem install slave

class Child
def pid
Process.pid
end
def foobar
42
end
end

slave = Slave.new{ Child.new }
child = slave.object

p Process.pid
p child.pid
p child.foobar


cfp:~ > ruby a.rb
20309
20310
42


also, if your arch changes it short work to rework such that the drb
objects are not in a child process but, rather, are distributed
across machines.

this code is used *heavily* in many of our production systems.

kind regards.

* http://codeforp...lib/ruby/slave/slave-1....


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Eric Hodel

10/10/2007 4:40:00 PM

0

On Oct 10, 2007, at 24:11 , Daniel DeLorme wrote:
> What are the possibilities in ruby for passing information from one
> process to another? Specifically, I'm thinking of messaging between
> a parent process and its forked child.
>
> Right now I can think of some messaging primitives:
> - TCPServer/TCPSocket
> - UNIXServer/UNIXSocket (unstable?)
> - IO.pipe (doesn't need port#)
> - Process.kill (impossible to send data)
>
> And some messaging libraries:
> - DRb (standard)
> - eventmachine (efficient?)
>
> ...what else? And, if anyone has the experience, what are the
> advantages/disadvantages of each in terms of speed, reliability,
> system resources?

DRb will cause you to do the least amount of work. You only need to
speak ruby, you don't need to do any serializing of data because it
all gets handled for you.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars



Joel VanderWerf

10/10/2007 7:55:00 PM

0

Markus Schirp wrote:
...
> I don't expect UNIXSocket to be unstable. I'm running over 2 years
> with using ruby's socket library without problems. Dont forget to
> remove the created socket if your process ends :)

Ditto. I've been using DRb over UNIX sockets extensively for about 2
years, and no problems here. Data volume and rate tend to be small in my
case, though.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Joel VanderWerf

10/10/2007 8:09:00 PM

0

Daniel DeLorme wrote:
> Right now I can think of some messaging primitives:
> - TCPServer/TCPSocket
> - UNIXServer/UNIXSocket (unstable?)
> - IO.pipe (doesn't need port#)
> - Process.kill (impossible to send data)

For completeness:

- named pipes (man fifo)

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407