2

I am trying to do IPC between 2 processes on the same Linux box in Ruby, and I need to optimize the solution as far as practicable.

I had begun with a TCPSocket but I see that using UNIXSocket is probably faster, and perhaps does not copy data to kernel buffers.

I have been reading SO threads, and looks like mmap might be interesting to look at. But for mmap I need to a) install mmap gem and b) provide locking since multiple client processes would likely try connect with the server process (both running on same box).

My questions:

  1. What other options would you recommend?
  2. How do you recommend locking the memory with ruby mmap?
  3. How do the numbers, if there's any available, stack up for UNIXSocket versus mmap?
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
Fanatic23
  • 3,378
  • 2
  • 28
  • 51
  • You could also use AMQP for sending messages between processes. There is the [bunny gem](https://github.com/celldee/bunny). I found RabbitMQ to be good for my use so far. I've heard good things about ZeroMQ too. Another alternative is using Redis, instead of mmap to share data between processes. Both are highly scalable and extremely fast options, as you can choose to run the either the AMQP or Redis processes on separate servers. Thirdly there are RPC options like Thrift. – jcsherin Feb 05 '12 at 11:04
  • Why are pipes and named pipes not an option? Those seem to the the general way of IPC on UNIXes. – Linuxios Feb 05 '12 at 15:10
  • Linuxios: Normal Pipes require that one process be a descendant (usually a child) of the other. Named pipes can be used by unrelated processes, but locking or some form of co-ordination must still be used to avoid attempts at concurrent access. There must be one writer and one reader for each pipe. (Bi-directional IPC with pipes requires pairs of pipes). It's notoriously easy to get into a deadlock when using pipes with the default blocking I/O. – Jim Dennis Nov 08 '12 at 02:18

0 Answers0