While using the POSIX Message queues I noticed there were some files being created on the File system with the name I was creating the queues. My questions :
Q1. Do message queues queue up the messages on the Hard Disk and not RAM ?
Q2. If so, shouldn't this be very slow in implementation as it involves HardDisk ?
Edit:
I read this in the book The Linux Programming Interface :
On Linux, POSIX message queues are implemented as i-nodes in a virtual file system, and message queue descriptors and open message queue descriptions are implemented as file descriptors and open file descriptions, respectively. However, these are implementation details that are not required by SUSv3 and don’t hold true on some other UNIX implementations.
Even if it is VFS, it is still stored on the HardDisk, right ?
With this information in mind, can someone comment on the second question now ? (and / or First one also if there is something more to add)
In a queuing system, messages are stored at intermediate nodes until the system is ready to forward them. At their final destination they are stored in an electronic mailbox until the addressee is ready to read them.
In a message queue, messages are stored in memory and are processed in the order that they are received.
Message queues are stored in the main memory and are available only while the system is running and not preserved across system reboots. A file is a sequence of bytes, and by default, the system does not enforce a structure on those bytes.
The message queue is a buffer that is used in non-shared memory environments, where tasks communicate by passing messages to each other rather than by accessing shared variables.
Below link may give some clarity on first question http://man7.org/linux/man-pages/man7/mq_overview.7.html
Regarding second question, of course the file based queue will be slower than memory based one. But this may not be as slow as some random file access operations since it is optimized and implemented specific for queuing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With