Choosing a IPC solution for an event-driven application
I am currently working on a rather large single-threaded, event-based, application designed around epoll under Linux and comparable technologies under other platforms. Currently, whenever we wish two instances to communicate, they typically do it through socke开发者_StackOverflow中文版ts, whether they are running on the same machine or not. For performance reason, I'm envisioning the use of some form of IPC to speed-up same machine communication. Now, I need to decide of which IPC mechanism to use.
The following factors are important to me:
- event-driven, without complete redesign -- if the IPC mechanism doesn't fit well with epoll, that's months of work lost for me
- fast -- if this mechanism is not faster than sockets, it's not worth the time implementing it
- flexible and (re)configurable during execution -- I believe that this rules out MPI & al
- no multi-threading required.
I'm willing to use different mechanisms for different platforms, as long as they all use the same paradigm. I'm also willing to get as deep as needed into C / C++ / Obj-C for platform-specific bindings.
Any suggestion?
Thanks.
Unix sockets. Named pipes. FIFOs.
These all offer the same basic functionality - same machine cross-process communications. The implementations offer slightly different behaviours though.
They all use file descriptors, so you can literally just plug them in where your socket used to be.
indeed, as skwllsp mentioned, the AF_INET sockets are optimized for data transmission on local host and the speed and complexity is comparable (almost the same?) with fifos,pipes,unix sockets ( a lot of skbuff processing is skipped if the destination is the same host). my 2 cents is to use sockets. this way not only that you keep the same interface for your IPC mechanism but you successfully reuse your code for both remote and local scenarios.
Try out Unix SysV IPC. It supports:-
- Message queues
- Semaphore
- Shared memory
which might help you.
This link might help more: http://www.ibm.com/developerworks/aix/library/au-ipc/index.html
精彩评论