Open siyuz opened 8 years ago
Ooh thanks for this insight!
Came here to report the same observation, your test for af_unix is incorrect doing half of the system calls compared to e.g., eventfd, you should consider fixing your blog.
Contrary to suggestion by @siyuz, you don't really need two socket pairs as sockets are bidirectional. Just fix the test such that client both reads and writes fd = pair[0], and server both reads and writes fd = pair[1].
Your af_unix implementation is actually doing both the reading and writing in the same thread, hence the absurdly small latency. You actually need 2 sets of socketpairs (parent->child & child->parent), which should give similar performance to pipes.
If you strace the binary you will see the child process blocks on the first read while the parent process does all the work.