简体   繁体   English

UNIX套接字与共享内存消息更快

[英]unix socket vs shared memory message which is faster

I am looking at a linux server program which, for each client, creates some shared memory and uses message queues (a C++ class called from the code) in that shared memory to send messages to and fro. 我正在查看一个Linux服务器程序,该程序为每个客户端创建一些共享内存,并在该共享内存中使用消息队列(从代码中调用的C ++类)来回发送消息。 On the face of it this sounds like the same usage pattern as domain sockets - ie have a server program that sends and recvs payloads from its clients. 从表面上看,这听起来与域套接字使用方式相同-即具有一个服务器程序,该程序从其客户端发送和接收有效载荷。

My question is - what extra work do unix domain sockets do? 我的问题是-Unix域套接字还能做些什么额外的工作? What could conceivably cause shared memory with a message queue to be faster than a socket and vice versa? 可以想象是什么导致消息队列的共享内存比套接字快,反之亦然?

My guess is there is some overhead to calling send and recv, but I'm not exactly sure what. 我的猜测是调用send和recv会有一些开销,但是我不确定是什么。 I might try and benchmark this, just looking for some insight before I do this. 我可能会尝试对此进行基准测试,只是在执行此操作之前先寻求一些见识。

Here is one discussion: UNIX Domain sockets vs Shared Memory (Mapped File) 这里是一个讨论: UNIX域套接字与共享内存(映射文件)

I can add that sockets are very primitive, just a stream of bytes for stream sockets. 我可以补充一点,套接字是非常原始的,只是流套接字的字节流。 This may actually be an advantage - it tends to make messages between different subsystems small and simple, promoting lean interfaces and loose coupling. 这实际上可能是一个优势-它倾向于使不同子系统之间的消息变得既小又简单,从而促进精益接口和松散耦合。 But sometimes, shared memory is really useful. 但是有时候,共享内存确实很有用。 I used shared memory in a C++ Linux back-end to a data-intensive Google Maps application - the database was just huge (+1 Gigabyte) png rasters in shared memory. 我在C ++ Linux后端中将共享内存用于数据密集型Google Maps应用程序-数据库在共享内存中只是巨大的(+1 GB)png栅格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM