Are message queues outdated on Linux?

I played with message queues (System V, but POSIX should also be fine) on Linux recently, and they seem to be ideal for my application, but after reading the Unix programming program, I'm not sure if they really are a good choice.

http://www.faqs.org/docs/artu/ch07s02.html#id2922148

The System V IPC messaging top layer is largely unused. The lower level, consisting of shared memory and semaphores, still has significant applications in situations where it is necessary to block mutual exclusion and some general data exchange between processes running on the same computer. These System V shared memory tools have evolved into the POSIX shared memory API, supported on Linux, BSD, MacOS X and Windows, but not on classic MacOS.

http://www.faqs.org/docs/artu/ch07s03.html#id2923376

System V IPC objects are present on Linux and other modern Unix. However, since they are an inherited function, they are not performed very often. Apparently, the version of Linux as of mid-2003 has errors. Nobody seems to care about fixing them.

Are System V message queues still not working on later versions of Linux? I'm not sure if the author means that POSIX message queues should be okay?

Sockets seem to be the preferred IPC for almost anyone (?), But I don't see how it would be very simple to implement message queues with sockets or something else. Or am I thinking too much?

I do not know if this is due to the fact that I work with embedded Linux?

+50
linux posix sockets message-queue ipc
Jun 08 '09 at 22:26
source share
4 answers

Personally, I really love message queues and I think that they are probably the most underutilized IPC in the unix world. They are fast and easy to use.

A few thoughts:

  • Some of them are just fashion. Old things become new again. Add a sparkling doter to the message queue and they may be the newest and hottest things next year. Take a look at Google Chrome using separate processes instead of threads for your tabs. Suddenly, people are delighted that when one tab is locked, it does not knock down the entire browser.

  • In common memory there is something like a halo. You are not a β€œreal” programmer if you are not compressing the last cycle from the machine, and MQ is slightly less efficient. For many, if not most applications, this is complete nonsense, but it is sometimes difficult to break the mind as soon as it holds.

  • MQ is really not suitable for applications with unlimited data. Streaming mechanisms such as pipes or sockets are easier to use.

  • System V options really did not like. Typically, you can use the POSIX version of IPC.

+55
Jun 09 '09 at 0:02
source share

I actually did not use POSIX message queues because I always want to leave the opportunity to distribute my messages over the network. With that in mind, you can take a look at a more robust messaging interface like zeromq or something that implements AMQP .

One of the nice things about 0mq is that when using a process from the same space in a multi-threaded application, it uses a zero-free locking mechanism, which is pretty fast. However, you can use the same interface to send messages over the network.

+10
Jun 08 '09 at 22:45
source share

Yes, I think message queues are suitable for some applications. POSIX message queues provide a more convenient interface, in particular, you can provide queue names rather than identifiers, which is very useful for troubleshooting (it makes it easier to see what is).

Linux allows you to mount posix message queues as a file system and see them with "ls", delete them with "rm", which is also very convenient (System V depends on the awkward command "ipcs" and "ipcrm")

+10
Jun 09 '09 at 7:02
source share

The biggest disadvantages of the POSIX message queue are:

  • The POSIX message queue does not make it a select() compatible requirement . (It works with select() on Linux, but not on a Qnx system)
  • He has surprises.

The Unix Datagram socket performs the same task in the POSIX message queue. And the Unix Datagram socket works in the socket layer. It can be used with select() / poll() or other I / O wait methods. Using select() / poll() has the advantage of developing an event-based system. In this way, a busy cycle can be avoided.

There is a surprise in the message queue. Think about mq_notify() . It is used to receive event-reception. It looks like we can tell something about the message queue. But it actually registers for notification, but notifies nothing.

More surprise about mq_notify() is that it should be called after every mq_receive() , which can cause a race condition (when some other call to the process / thread mq_send() between the call to mq_receive() and mq_notify() >).

And it has a whole set of mq_open, mq_send(), mq_receive() and mq_close() with its own definition, which is redundant and in some cases incompatible with the specification of the socket open(),send(),recv() and close() method.

I do not think the message queue should be used for synchronization. eventfd and signalfd .

But he has some real-time support. It has priority features.

 Messages are placed on the queue in decreasing order of priority, with newer messages of the same priority being placed after older messages with the same priority. 

But this priority is also available for the socket as out-of-band data!

Finally, for me, the POSIX message queue is an outdated API. I always prefer the Unix Datagram socket over the POSIX message queue.

0
Jun 08 '17 at 19:27
source share



All Articles