From: Robert Klemme Date: 2010-01-10T23:04:31+09:00 Subject: Re: Non-blocking communication between Ruby processes 2010/1/9 Iñaki Baz Castillo : > El Jueves, 7 de Enero de 2010, Robert Klemme escribió: > >> I'd personally prefer to use the DRb approach because then you can >> actually send typed messages, i.e. whatever information you need.  Also, >> it was fun to play around with those small test programs. ;-)  And you >> can have the reader run on any machine in the network. > > Hi Robert, I'd like to thank you the help you gave me in this and other > threads. Finally I've decided to use posix message queue [*] under Ruby. You're welcome! > The reason is that it allows safely multiple processes or threads using the > same mqueue to write message (atomic strings) and also having multiple > processes reading from the same mqueue which means load-balancing out of the > box :) > > The queue size is configurable and the writer/reader can write/read in the > mqueue in a blocking or non blocking way. > > Also, mqueues allow setting a priority to the messages so those messages with > higher priority are fetched first when reading the mqueue. > > Posix message queues are just 20-40% slower than pipes in my benchmarks (but > pipes are no multiprocess/thread safe). That sounds good! I have never worked with POSIX MQ so I definitively learned something new as well. > I would like to share a working example: Thank you for the summary and the code! That way other readers will benefit as well. > I also tested your suggested solution with DRb with is really nice, but I > don't need all the features DRb provides (I just need to pass a simple string > to other process(es) from multiple workers). Well, you don't have to use them. :-) But POSIX MQ looks equally simple to use. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/