r/programming • u/elfenpiff • 9h ago
Stop paying the network stack tax: zero-copy first, networking when needed
https://ekxide.io/blog/iox2-vision-zero-copy-first/
0
Upvotes
r/programming • u/elfenpiff • 9h ago
4
u/Murky-Relation481 7h ago
Would love to see how they solve memory layout for non homogeneous builds even in the same language. I think anyone who have dealt even with communication between shared objects in C or C++ realize shared memory is not always uniform.
We still use serialization across shared memory when even if it's a well defined API that we control but we do not know the vendor's binary lineage our API is being used with.
28
u/zam0th 7h ago
Psst, psst, do you want some linux IPC? Because looks like you invented Unix sockets and POSIX. https://opensource.com/sites/default/files/gated-content/inter-process_communication_in_linux.pdf
0
u/latkde 1h ago
Mutable shared memory is extremely, extremely tricky to pull off correctly (especially in Rust, as shared memory violates Rust's aliasing assumptions). Correct solutions either use atomic accesses for all reads/writes, or something like a ring buffer or queue where a region can be temporarily treated as constant (protected by a mutex). Either way, this is going to be an unusual programming model. Memory layout compatibility is not at all sufficient. Also, you don't get to use pointers.
For some programs, the last bit of performance is worth all of this complexity. For most, it is not, and traditional IPC where data is copied between memory spaces is the preferable solution. Pipes or Unix sockets can be used for local connections. But if you're already designing a distributed multi-process system, it tends to be preferable to design it to be multi-host capable as well, i.e. to use actual networking. This kind of decoupling with its share-nothing approach has enabled systems to scale to unprecedented levels over the last two decades.
You raise the point that networking also has complexity (e.g. timeouts), but it seems you're already supporting networking so your systems must already deal with this complexity. If you now add mutable shared memory you get a completely different kind of complexity on top, with no unifying abstraction. You now have the worst of both worlds.
For some reason, the blog post only touts advantages, not drawbacks or tradeoffs.
I did skim the linked iceoryx docs a bit. That library seems to mitigate some of the shared-memory insanity by imposing specific communication patterns, e.g. pub-sub or blackboard. The blackboard pattern would run most directly into shared mutability problems. Now imagine my surprise when the Rust API for the blackboard pattern doesn't actually offer zero-copy shared memory! For safety, it actually relies on (atomic) copies. That greatly diminishes the advantages touted by the blog post.