Giter Site home page Giter Site logo

ipmpsc's Introduction

ipmpsc

Inter-Process Multiple Producer, Single Consumer Channels for Rust

Crates.io Build Status MIT licensed

Summary

This library provides a type-safe, high-performance inter-process channel implementation based on a shared memory ring buffer. It uses bincode for (de)serialization, including zero-copy deserialization, making it ideal for messages with large &str or &[u8] fields. And it has a name that rolls right off the tongue.

Examples

The examples directory contains a sender and receiver pair, which you can run in separate terminals like so:

cargo run --example ipmpsc-receive -- --zero-copy /tmp/ipmpsc
cargo run --example ipmpsc-send -- /tmp/ipmpsc

Type some lines of text into the sender and observe that they are printed by the receiver. You can also run additional senders from other terminals -- the receiver will receive messages from any of them.

Performance

ipmpsc::Receiver::zero_copy_context, used in combination with serde_bytes, is capable of supporting very high bandwidth, low latency transfers (e.g. uncompressed video frames).

See the ipc-benchmarks subcrate for a few simple benchmarks that compare ipmpsc to ipc_channel's high- and low-level interfaces. Here are the results from my Ubuntu laptop:

test tests::bench_ipc_channel       ... bench:  16,013,621 ns/iter (+/- 932,033)
test tests::bench_ipc_channel_bytes ... bench:   4,777,240 ns/iter (+/- 242,369)
test tests::bench_ipmpsc            ... bench:   1,380,406 ns/iter (+/- 62,038)

Security and Safety

The ring buffer is backed by a shared memory-mapped file, which means any process with access to that file can read from or write to it depending on its privileges. This may or may not be acceptable depending on the security needs of your application and the environment in which it runs.

Note that zero-copy deserialization can provide shared references to the mapped file, and internally ipmpsc uses both shared and unique references to segments of the file while reading from and writing to the ring buffer. These references are only safe if all processes which access the file obey Rust's memory safety rules (which normally only have meaning within a single process). ipmpsc itself should follow the rules (please report a bug if not), but safety cannot be guaranteed if any process fails to do so.

Platform Support

This library currently works on Linux, Android, and Windows. It does not work reliably on MacOS, unfortunately. See dicej#4 for details. PRs to fix that are welcome!

Similar Projects

ipc-channel - mature and robust IPC channels. Does not yet support Android, Windows, multiple simultaneous senders, or zero-copy deserialization.

shared_memory - low-level, cross-platform shared memory support. May be used as the basis for a ring-buffer based channel, but does not yet support Android.

ipmpsc's People

Contributors

blasrodri avatar dicej avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.