Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster for IPC sharing of objects -ZeroMQ or Boost::interprocess?

I am contemplating inter-process sharing of custom objects. My current implementation uses ZeroMQ where the objects are packed into a message and sent from process A to process B.

I am wondering whether it would be faster instead to have a concurrent container implemented using boost::interprocess (where process A will insert into the container and process B will retrieve from it). Not sure if this will be faster than having to serialise the object in process A and then de-serialising it in process B.

Just wondering if anyone has done benchmarking? Is it conceptually right to compare the two?

like image 726
L.Koh Avatar asked Aug 23 '18 08:08

L.Koh


People also ask

Is Shared Memory important for IPC?

However, why do we need to share memory or some other means of communication? To reiterate, each process has its own address space, if any process wants to communicate with some information from its own address space to other processes, then it is only possible with IPC (inter process communication) techniques.

Which one is the shared memory technique used in IPC?

Two functions shmget() and shmat() are used for IPC using shared memory. shmget() function is used to create the shared memory segment, while the shmat() function is used to attach the shared segment with the process's address space.

What is boost interprocess?

Interprocess simplifies the use of common interprocess communication and synchronization mechanisms and offers a wide range of them: Shared memory. Memory-mapped files. Semaphores, mutexes, condition variables and upgradable mutex types to place them in shared memory and memory mapped files.

Is boost interprocess header only?

Boost Interprocess is a header-only library, so all you need to do is include the appropriate header in your sources and make the compiler aware of the include path.


1 Answers

In principle, ZeroMq should be slower, because the metaphor it's using is the passing of messages. These kinds of libraries are not intended for sharing regions of memory, in place, and for different processes to be able to modify them concurrently.

Specifically, you mentioned "packing". When sharing memory regions, you can - ideally - avoid any packing and just work on data as-is (of course, with the care necessary in concurrent use of the same data structures, using offsets instead of pointers etc.)

Also note that even when sharing is a one-directional back-and-forth (i.e. only one process at a time accesses any of the data), ZeroMq can only match the use of IPC shared memory if it supports zero-copying all the way down. This is not clear to me from the FAQ page on zero-copying (but may be the case anyway).

like image 155
einpoklum Avatar answered Oct 19 '22 16:10

einpoklum