Unix socket vs shared memory message which is faster

I am looking at a linux server program that for each client creates some shared memory and uses message queues (C ++ class called from code) in this shared memory to send messages back and forth. At first glance, this looks like the same usage pattern as domain sockets — that is, there is a server program that sends and returns a payload from its clients.

My question is: what additional work does unix domain sockets do? What can lead to the fact that the shared memory with the message queue will be faster than the socket, and vice versa?

I assume there is some overhead for calling send and recv, but I'm not quite sure what. I could try and compare this, just looking for some ideas before I do this.

+5
source share
1 answer

Here is one discussion: UNIX domain sockets versus shared memory (Mapped File)

I can add that sockets are very primitive, just a stream of bytes for streaming sockets. In fact, this can be an advantage - it tends to make messages between different subsystems small and simple, promoting unreliable interfaces and free communication. But sometimes shared memory is really useful. I used shared memory in a C ++ Linux server for an application with lots of Google Maps data - the database was just huge (+1 gigabytes) png rasters in shared memory.

+5
source

Source: https://habr.com/ru/post/1202490/


All Articles