IPC performance: Named Pipe vs Socket

后端 未结 10 1573
自闭症患者
自闭症患者 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:14

    For two way communication with named pipes:

    • If you have few processes, you can open two pipes for two directions (processA2ProcessB and processB2ProcessA)
    • If you have many processes, you can open in and out pipes for every process (processAin, processAout, processBin, processBout, processCin, processCout etc)
    • Or you can go hybrid as always :)

    Named pipes are quite easy to implement.

    E.g. I implemented a project in C with named pipes, thanks to standart file input-output based communication (fopen, fprintf, fscanf ...) it was so easy and clean (if that is also a consideration).

    I even coded them with java (I was serializing and sending objects over them!)

    Named pipes has one disadvantage:

    • they do not scale on multiple computers like sockets since they rely on filesystem (assuming shared filesystem is not an option)

提交回复
热议问题