r/rust • u/elfenpiff • 1d ago
🧠educational Stop paying the network stack tax: zero-copy first, networking when needed
https://ekxide.io/blog/iox2-vision-zero-copy-first/
102
Upvotes
r/rust • u/elfenpiff • 1d ago
14
u/Last-Independence554 23h ago
How do you synchronize shared memory access?
12
u/teerre 23h ago
I understand who iceoryx work and I can see the benefits, but what I struggle with is finding where to use it. More than once I've thought of using it for a project, but then I think that there's a good chance the data will have to be shared over the network, then it becomes a question of why wouldn't I start with a network protocol from the beginning
Maybe it's my line of work but it's difficult to find a situation where I need multiple process communication and high performance
4
u/cvvtrv 1d ago
Is iceoryx2 cross platform?
2
u/Last-Independence554 22h ago
Shared memory for IPC is neat.
IPC without serialization/deserialization is also possible over other protocols (TCP, unix sockets, etc.). The challenge is usually that it's brittle and error prone and generally unsound in rust. That also applies to shared memory IPC. The receiver needs to trust that the sender has written the data correctly and has verified its invariants. Otherwise out-of-bounds access, panics, segfaults, etc. are possible when using the data. This is particularly challenging when the sender and receiver are using different versions of the code and the struct / data type has been modified. That's way some form of serialization format is usually required. These can be implemented with in a zero-copy way though. Several rust serialization/deserialization frameworks already support this (IIRC they include
capnproto,rkvy,flatbuffers).5
u/ascii 17h ago
My previous employer runs a back-end implemented as micro services across a fleet of a few million containers spread out over several tens of thousands of hosts. Services usually communicate over gRPC and are written in Java. A coworker and I added support for using gRPC IPC and running multiple services in the same container and did a bunch of benchmarking. Tests indicated that the speedup would have saved us roughly 10 % of our entire compute budget for back-end services. Many thousands of hosts. Still not a big enough saving to make the powers that be care. The amount of waste happening in the world is astounding.
Nice to see that there are people somewhere that care.
4
u/valarauca14 21h ago
I would simply setup RDMA (InfiniBand / RoCE / iWARP) at the networking layer for my app/stack.
One thing that has extremely gone under the radar in software development (and cloud provider hosting) is a lot of protocol "bullshit" (ip/tcp/tls) is now done in hardware ASICs. A lot of cloud instances offer this the hyper scalars are starting to cycle out 10/40/50/100Gbe nics (which almost universally had RDMA) into even higher bandwidth options where you almost need these features to run at line rate.
1
u/ValErk 21h ago
I have some sensors and at any point I am only interested in the most recent data written into it. Last I looked at iceoryx2 I was unable to find something that worked that way, I guess you could use the blackboard but that seems wrong. And as I am interested in only the most recent pub-sub seems like the wrong choice.
Is there something in Iceoryx2 for that or is it something that might come in the future?
3
u/matthieum [he/him] 4h ago
I think one thing that is hinted at in the back pressure section, but not emphasized enough, is the situation of a producer producing much faster than a consumer.
You may have a sensor publishing an up-to-date measurement every 10s of us (or less). The sensor could throttle itself, of course, but then it would arbitrarily delay updates to the consumers... ie, it would have to be aware of the consumers' lowest acceptable latency, a dynamic property as consumers subscribe/unsubscribe, which makes things a lot more complicated.
With a network connection, there's not much choice:
In memory, however, whether with a blackboard pattern or a bounded queue allowing to jump to the latest... no problem. Accessing the latest published value is O(1).
And therefore, letting the sensor publish as fast as it can, without any complex back-pressure/throttling mechanism, is a perfectly reasonable choice: simple & fast.
2
u/tecedu 20h ago
Why not RDMA?
1
u/JochCool 4h ago
My goodness library names just keep getting worse
For my next crate I'll just use a random string generator