It's more a question of design, than speed (Shared Memory is faster), domain sockets are definitively more UNIX-style, and do a lot less problems. In terms of choice know beforehand:
Domain Sockets advantages
blocking and non-blocking mode and switching between them
you don't have to free them when tasks are completed
Domain sockets disadvantages
must read and write in a linear fashion
Shared Memory advantages
non-linear storage
will never block
multiple programs can access it
Shared Memory disadvantages
need locking implementation
need manual freeing, even if unused by any program
That's all I can think of now. However, I'd go with domain sockets any day -- not to mention that it's a lot easier then to reimplement them to do distributed computing. The speed gain of Shared Memory will be lost because of the need of a safe design. However, if you know exactly what you're doing, and use the proper kernel calls, you can achieve greater speed with Shared Memory.
mmap is only good for constant size shared structures, not for variable communications.
i'm not sure why named pipes would be faster than Unix Domain Sockets but if its true i doubt by much (named pipes go through the VFS layer)
depending on the work being done Unix domain sockets would have the benifit of allowing you to move to normal sockets should you want to "cluster" the application on a network.
转载于:https://blog.51cto.com/mingtangduyao/1783513
本文探讨了域套接字与共享内存这两种进程间通信方式的特点与区别。域套接字更符合UNIX风格,支持阻塞和非阻塞模式,并且在实现分布式计算时更为简便。而共享内存虽然速度更快,但在设计上需要考虑更多的安全性问题。

1145

被折叠的 条评论
为什么被折叠?



