|
1 | 1 | # FastQueue (fq) |
2 | | -A fast and simple ring-buffer-based single-producer, single-consumer queue with no dependencies. You can use this to write Rust programs with low-latency message passing. |
| 2 | +A fast and simple ring-buffer-based single-producer, single-consumer queue with no dependencies. You can use |
| 3 | +this to write Rust programs with low-latency message passing. |
3 | 4 |
|
4 | 5 | > [!IMPORTANT] |
5 | 6 | > This crate is highly experimental. |
@@ -33,15 +34,42 @@ sender.join().expect("The sender thread has panicked"); |
33 | 34 | receiver.join().expect("The receiver thread has panicked"); |
34 | 35 | ``` |
35 | 36 |
|
36 | | -## License |
| 37 | +## Examples |
| 38 | +See the [examples](examples) directory for more usage examples. |
| 39 | + |
| 40 | +## How does it work? |
| 41 | +The ring buffer structure allows for a contigous data structure. The idea is that if we are able to get extreme |
| 42 | +cache locality, we can improve performance by reducing cache misses. This is also the reason why if you use |
| 43 | +smart pointers like `Box<T>`, performance *may* degrade since cache locality gets affected. For very large |
| 44 | +`T` types, you are more limited by `memcpy()` performance and less from queue implementations. As such, |
| 45 | +ring buffers can be considered strongly optimized for data of a few word sizes with some non-linear |
| 46 | +degradation for larger sizes. Additional optimizations are provided for CPUs that support `sse` and `prfchw` |
| 47 | +flags. As and when Rust `std` provides more relevant instructions, they will be added. This is simply a |
| 48 | +high-level explanation of some of the techniques employed by this crate, you can read the code to gain a better |
| 49 | +understanding of what's happening under the hood. |
| 50 | + |
| 51 | +## Principles |
| 52 | +* This crate will always prioritize message throughput over memory usage. |
| 53 | +* This crate will always support generic types only. |
| 54 | +* This crate will always provide a wait-free **and** lock-free API. |
| 55 | +* This crate will use unsafe Rust where possible for maximal throughput. |
| 56 | + |
| 57 | +## Benchmarks |
| 58 | +Benchmarks are strictly difficult due to the nature of the program, it's somewhat simple to do a same-CPU |
| 59 | +bench but performance will still be affected based on the core type and cache contention. Benchmarks are |
| 60 | +provided in the [benchmark](benchmark) directory and can be run with `cargo bench`. Contributions via PRs for |
| 61 | +additional benchmarks are welcome. |
37 | 62 |
|
| 63 | +## License |
38 | 64 | Licensed under either of: |
39 | 65 | * MIT license ([LICENSE-MIT](LICENSE-MIT)) |
40 | 66 | * Lesser General Public license v3.0 or later ([LICENSE-LGPL](LICENSE-LGPL)) |
41 | 67 | at your option. |
42 | 68 |
|
43 | 69 | ### Contribution |
44 | | - |
45 | 70 | Unless you explicitly state otherwise, any contribution intentionally submitted |
46 | 71 | for inclusion in the work by you, as defined in the LGPL-3.0 license, shall be dual licensed as above, without any |
47 | 72 | additional terms or conditions. |
| 73 | + |
| 74 | +## Acknowledgements |
| 75 | +Inspired from previous works like [fastqueue2](https://github.com/andersc/fastqueue2), [rigtorp](https://rigtorp.se/ringbuffer) and [rtrb](https://github.com/mgeier/rtrb). |
0 commit comments