https://github.com/diwic/shmem-ipc
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.
https://github.com/diwic/shmem-ipc
communication linux rust
Last synced: 12 months ago
JSON representation
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.
- Host: GitHub
- URL: https://github.com/diwic/shmem-ipc
- Owner: diwic
- Created: 2021-02-08T04:52:10.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T10:30:45.000Z (over 3 years ago)
- Last Synced: 2025-03-31T14:13:31.391Z (12 months ago)
- Topics: communication, linux, rust
- Language: Rust
- Homepage:
- Size: 56.6 KB
- Stars: 144
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://crates.io/crates/shmem-ipc)
[](https://docs.rs/shmem-ipc)
[](https://crates.io/crates/shmem-ipc)
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.
When is this Rust crate useful?
--------------------------
* Performance or latency is crucial, and
* you run Linux.
A typical use case could be audio/video streaming.
Don't need maximum performance and minimum latency, and want a higher level protocol
with serialization and lots of bells and whistles built-in? Try [D-Bus](https://docs.rs/dbus/).
Also, a [unix socket](https://doc.rust-lang.org/std/os/unix/net/struct.UnixStream.html)
is easier to set up and is not that much slower (see benchmark below).
As for Linux, this crate uses memfd sealing to ensure safety between untrusted processes,
and ringbuffer signaling is done using eventfd for best performance.
These two features are Linux only.
Getting started
---------------
You probably want to start in the `sharedring` module, which sets up a ringbuffer
between untrusted processes (it's a wait-free/lock-free, bounded, SPSC queue).
Another useful function is `mem::write_once` for a scenario where
you write data once and make it available for reading afterwards. The `mem` and `ringbuf`
modules contain building blocks that might be useful in other use cases.
The downside of using memfd based shared memory is that you need to set it up
by transferring file descriptors, using some other way of communication.
Using [D-Bus](https://docs.rs/dbus/) would be the standard way of doing that -
it's also possible using [unix sockets](https://crates.io/crates/uds).
There is also a client/server example in the `examples` directory that can help you get started.
Enjoy!
Benchmark
---------
[](https://github.com/diwic/shmem-ipc/blob/master/lines.svg)
Notice the log scale: for a 64K packet, sharedring is a three times faster than unix sockets,
and 60 times faster than D-Bus. (D-Bus is a higher level protocol, so that comparison
is to some degree comparing apples and oranges.)
License
-------
The code is Apache 2.0 / MIT dual licensed. Any code submitted in Pull Requests, discussions or
issues is assumed to have this license, unless explicitly stated otherwise.