Sewi has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

apologies for asking a not-strictly Perl-related question: I'm looking for a message system for a multi-server, multi-process system.

Running processes need to send messages to others for various reasons like "stop this work" or "here is my result".

We have two major scenarios:

  1. A running task needs to receive a signal, something which could be done using Linux signals (like HUP, USR1, USR2) and kill() in a single-server environment. The receiving task may connect to the message server at startup and disconnect on exit. Messages may be checked by the process or delivered via callback but the process may not enter a "main loop" of another module because it's doing it's work in his own source.
  2. We also have jobs running on a gearman cluster with a web-user waiting for results. The web-scripts usually poll the state of the gearman jobid and deliver the results once the worker is done. Each request is one status check and either result delivery or "no results" message to the client, the script exists once this is done and the browser issues a new request for the next check. Those check scripts can't stay connected and wait for messages but might "look for new messages" once per run.

I though about using our Memcached for message distribution but it's a cache and I don't like the idea that messages might get lost as a design specification (even if it's unlikely). Database is no option because it's way to slow, already heavy-loaded and I don't think that messages have to stay on various hard disks on a whole cluster because most of them won't life for more than a second.

Is there any reliable piece of software I'm missing? It doesn't need to be written in Perl but it must have a Perl-usable API (which should be no problem for network-based services).

Thanks,
Sewi

Replies are listed 'Best First'.
Re: Message transport via network
by Corion (Patriarch) on Jun 18, 2012 at 08:42 UTC

    You will need to think hard about what kinds persistence you need. If you only need a message protocol for sending status updates, with a limited delivery guarantee, then something lightweight like ZeroMQ might be enough and "conveniently" testable as it is a serverless infrastructure. On the opposite end of delivery/consistency of messages, a database provides that, but has much slower throughput and creates a harder single point of failure.

    Consider where messages are allowed to get lost - a missing completion message will leave the task in need to be restarted. If the only side effect of this is wasted time, that may or may not be sufficient for you. How important is a crash of the queue server? Can all messages stored in the queue server get lost, or should they be as available as possible?

      Thank you,
      loosing the complete message store because of a hardware or software failure would be ok. Web users won't get status reports for completed jobs (but the final report is saved permanently anyway, they could look it up at any time) or "cancel this"-messages won't be processed and users would have to re-issue the cancel-request. Users might also not get search results but a error message instead - perfectly fine if something is broken (and also current procedure in case of database problems).
      Messages shouldn't get lost as a planned design feature (or problem).

      I'll take a look at both suggested solutions.

Re: Message transport via network
by opitzs (Sexton) on Jun 18, 2012 at 09:11 UTC
    We use TibRv with tibcache for your scenario (www.tibco.com). An open source alternative would be the spread toolkit (www.spread.org), but I have never really used it, so I can't say, if it works as expected.
Re: Message transport via network
by pklausner (Scribe) on Jun 18, 2012 at 14:53 UTC
    Update: ZeroMQ already mentioned above, sorry

    ØMQ \zeromq\ looks like it could fit your bill. From their blurb at: zeromq.org:
     Ø  A socket library that acts as a concurrency framework.
     Ø  Faster than TCP, for clustered products and supercomputing.
     Ø  Carries messages across inproc, IPC, TCP, and multicast.
     Ø  Connect N-to-N via fanout, pubsub, pipeline, request-reply.
     Ø  Asynch I/O for scalable multicore message-passing apps.
     Ø  Large and active open source community.
     Ø  30+ languages including C, C++, Java, .NET, Python.
     Ø  Most OSes including Linux, Windows, OS X.
     Ø  LGPL free software with full commercial support from iMatix.

    Note though, that they deliberately do not give 100% delivery guarantees. See their documentation why they choose this design and the ways your application can deal with it.