Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLib's GAsyncQueue vs. POSIX message_queue

Does anyone have any idea of the relative performance of GLib's GAsyncQueue vs. POSIX message_queue for inter-thread communication? I will have many small messages (both one way and request-response types), to be implemented in C on top of Linux (for now; may be ported to Windows later). I am trying to decide which one to use.

What I have found out is that using GLib is better for portability purposes, but POSIX mq's have the advantage of being able to select or poll on them.

However, I have not found any information on whose performance is better.

like image 708
dbikash Avatar asked Feb 10 '12 12:02

dbikash


People also ask

What is a POSIX Message Queue?

POSIX message queues are a means by which processes exchange data in the form of messages to accomplish their tasks. They enable processes to synchronise their reads and writes to speed up processes. POSIX message queues are distinct from System V messages.

What is Dev Mqueue?

The /dev/mqueue directory doesn't appear until you actually create a queue. The traditional POSIX message queue manager is a resource manager that uses messages to communicate with its clients. You can access it locally or remotely, allowing for network-wide message queues.

Which system call is used to get process ID of last process which sends last message on message queue?

System calls used for message queues: ftok(): is use to generate a unique key. msgget(): either returns the message queue identifier for a newly created message queue or returns the identifiers for a queue which exists with the same key value.

Where are message queues stored in Linux?

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.


1 Answers

Since there were no responses to my question, I decided to run some performance tests myself. The main idea was taken from http://cybertiggyr.com/throughput/throughput.html. The test idea was:

  • Create two threads (pthreads / gthreads).
  • One thread produced data and wrote to the IPC in chunks till 1024 MB data was sent.
  • The other thread consumed data from the IPC. I tested with chunk sizes of 4, 64, 256, 512 and 1024 bytes. I tested with GAsyncQueue (with gthreads), POSIX message queue and UNIX domain sockets (with pthreads).

Here is the result obtained:

enter image description here

To summarize, perf(GAsyncQueue) > perf(mq) > perf(UNIX socket), though the performances of GAsyncQueue and POSIX message queue are comparable in most cases - the difference occurs only with small message sizes.

I was wondering how GAsyncQueue is implemented to give comparable of even better performance than Linux's native message queue implementation. It is a pity that it cannot be used for inter process communication, like the other two can.

like image 55
dbikash Avatar answered Sep 22 '22 16:09

dbikash