IPC performance: Named Pipe vs Socket

后端 未结 10 1541
自闭症患者
自闭症患者 2020-11-28 01:39

Everyone seems to say named pipes are faster than sockets IPC. How much faster are they? I would prefer to use sockets because they can do two-way communication and are very

10条回答
  •  抹茶落季
    2020-11-28 02:05

    One problem with sockets is that they do not have a way to flush the buffer. There is something called the Nagle algorithm which collects all data and flushes it after 40ms. So if it is responsiveness and not bandwidth you might be better off with a pipe.

    You can disable the Nagle with the socket option TCP_NODELAY but then the reading end will never receive two short messages in one single read call.

    So test it, i ended up with none of this and implemented memory mapped based queues with pthread mutex and semaphore in shared memory, avoiding a lot of kernel system calls (but today they aren't very slow anymore).

提交回复
热议问题