Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
Merge pull request #41 from stjepang/select-macro
Browse files Browse the repository at this point in the history
New selection macro
  • Loading branch information
Stjepan Glavina authored Jun 11, 2018
2 parents 8b9b720 + 0708aea commit 5050c89
Show file tree
Hide file tree
Showing 69 changed files with 11,932 additions and 8,220 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
target/
Cargo.lock
/benchmarks/*.txt
/benchmarks/*.png
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ rust:
- stable
- beta
- nightly
- 1.26.0

script:
- export RUSTFLAGS="-D warnings"
- cargo build
- cargo build --release
- cargo test
- cargo test --release
- cargo test -- --test-threads=1
- cargo test --release -- --test-threads=1
- |
if [ $TRAVIS_RUST_VERSION == nightly ]; then
cargo test --features nightly
cargo test --features nightly --release
if [[ $TRAVIS_RUST_VERSION == nightly ]]; then
cd benchmarks
cargo build --bins
cargo build --bins --release
fi
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ description = "Multi-producer multi-consumer channels for message passing"
keywords = ["channel", "mpmc", "select", "golang", "message"]
categories = ["algorithms", "concurrency", "data-structures"]

[features]
nightly = []

[dependencies]
crossbeam-epoch = "0.4.0"
crossbeam-utils = "0.3.0"
crossbeam-utils = "0.4.0"
libc = "0.2.42"
parking_lot = "0.5"
smallvec = "0.6.1"

[dev-dependencies]
crossbeam = "0.3.0"
Expand Down
35 changes: 5 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,29 @@
[![Cargo](https://img.shields.io/crates/v/crossbeam-channel.svg)](https://crates.io/crates/crossbeam-channel)
[![Documentation](https://docs.rs/crossbeam-channel/badge.svg)](https://docs.rs/crossbeam-channel)

Channels are concurrent FIFO queues used for passing messages between threads.

Crossbeam's channels are an alternative to the [`std::sync::mpsc`] channels
provided by the standard library. They are an improvement in pretty much all
aspects: ergonomics, flexibility, features, performance.
provided by the standard library. They are an improvement in terms of
performance, ergonomics, and features.

[`std::sync::mpsc`]: https://doc.rust-lang.org/std/sync/mpsc/index.html

Read the original [RFC](https://github.com/crossbeam-rs/rfcs/pull/22) that introduced these
channels for more information on their design and implementation.

## Usage

Add this to your `Cargo.toml`:

```toml
[dependencies]
crossbeam-channel = "0.1"
crossbeam-channel = "0.2"
```

Next, add this to your crate:

```rust
#[macro_use]
extern crate crossbeam_channel;
```

## Comparison with `std::sync::mpsc`

| | `std::sync::mpsc` | `crossbeam-channel` |
|----------------------------------|------------------------------------|---------------------------------------------------|
| Unbounded channel constructor | `channel()` | `unbounded()` |
| Bounded channel constructor | `sync_channel(cap)` | `bounded(cap)` |
| Sender types | `Sender` and `SyncSender` | `Sender` |
| Receiver types | `Receiver` | `Receiver` |
| Sender implements `Sync`? | No | Yes |
| Receiver implements `Sync`? | No | Yes |
| Sender implements `Clone`? | Yes | Yes |
| Receiver implements `Clone`? | No | Yes |
| Sender operations | `try_send`, `send` | `try_send`, `send`, `send_timeout` |
| Receiver operations | `try_recv`, `recv`, `recv_timeout` | `try_recv`, `recv`, `recv_timeout` |
| Additional sender methods | | `is_empty`, `len`, `capacity` |
| Additional receiver methods | `iter`, `try_iter` | `iter`, `try_iter`, `is_empty`, `len`, `capacity` |
| Selection macro | `select!` | `select_loop!` |
| Select interface | `std::sync::mpsc::Select` | `crossbeam_channel::Select` |
| Select has a safe interface? | No | Yes |
| Select supports send operations? | No | Yes |
| Select can have a timeout? | No | Yes |
| Select can be non-blocking? | No | Yes |
The minimum required Rust version is 1.26.

## License

Expand Down
45 changes: 26 additions & 19 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,53 @@ name = "benchmark"
version = "0.1.0"

[dependencies]
atomicring = "0.5.3"
bus = "2.0.0"
chan = "0.1.19"
crossbeam = "0.3.0"
atomicring = "0.5.3"
crossbeam-channel = { path = ".." }
futures = "0.2.1"
mpmc = "0.1.5"
crossbeam-channel = { path = "..", features = ["nightly"] }

[features]
yield = []
medium_size=[]
large_size=[]
[[bin]]
name = "atomicring"
path = "atomicring.rs"

[[bin]]
name = "crossbeam-channel"
path = "crossbeam-channel.rs"
name = "atomicringqueue"
path = "atomicringqueue.rs"

[[bin]]
name = "bus"
path = "bus.rs"

[[bin]]
name = "chan"
path = "chan.rs"

[[bin]]
name = "mpsc"
path = "mpsc.rs"
name = "crossbeam-channel"
path = "crossbeam-channel.rs"

[[bin]]
name = "ms_queue"
path = "ms_queue.rs"
name = "futures-channel"
path = "futures-channel.rs"

[[bin]]
name = "seg_queue"
path = "seg_queue.rs"

name = "mpsc"
path = "mpsc.rs"

[[bin]]
name = "atomicring"
path = "atomicring.rs"
name = "mpsc-wrapper"
path = "mpsc-wrapper.rs"

[[bin]]
name = "atomicringqueue"
path = "atomicringqueue.rs"
name = "msqueue"
path = "msqueue.rs"

[[bin]]
name = "segqueue"
path = "segqueue.rs"

[[bin]]
name = "mpmc"
Expand Down
58 changes: 17 additions & 41 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,29 @@
* `select_rx`: `T` threads send `N / T` messages each into a separate channel. Another thread receives `N` messages by selecting over the `T` channels.
* `select_both`: `T` threads send `N / T` messages each by selecting over `T` channels. `T` other threads receive `N / T` messages each by selecting over the `T` channels.

### Running
Default configuration:

```
cargo run --release --bin chan | tee small_chan.txt
cargo run --release --bin mpsc | tee small_mpsc.txt
cargo run --release --bin crossbeam-channel | tee small_crossbeam-channel.txt
cargo run --release --bin ms_queue | tee small_ms_queue.txt
cargo run --release --bin seg_queue | tee small_seg_queue.txt
cargo run --release --bin mpmc | tee small_mpmc.txt
cargo run --release --bin atomicring | tee small_atomicring.txt
cargo run --release --bin atomicringqueue | tee small_atomicringqueue.txt
go run main.go | tee small_go.txt
./plot.py small_*.txt
mv plot.png plot_small.png
cargo run --features medium_size --release --bin chan | tee medium_chan.txt
cargo run --features medium_size --release --bin mpsc | tee medium_mpsc.txt
cargo run --features medium_size --release --bin crossbeam-channel | tee medium_crossbeam-channel.txt
cargo run --features medium_size --release --bin ms_queue | tee medium_ms_queue.txt
cargo run --features medium_size --release --bin seg_queue | tee medium_seg_queue.txt
cargo run --features medium_size --release --bin mpmc | tee medium_mpmc.txt
cargo run --features medium_size --release --bin atomicring | tee medium_atomicring.txt
cargo run --features medium_size --release --bin atomicringqueue | tee medium_atomicringqueue.txt
./plot.py medium_*.txt
mv plot.png plot_medium.png
cargo run --features large_size --release --bin chan | tee large_chan.txt
cargo run --features large_size --release --bin mpsc | tee large_mpsc.txt
cargo run --features large_size --release --bin crossbeam-channel | tee large_crossbeam-channel.txt
cargo run --features large_size --release --bin ms_queue | tee large_ms_queue.txt
cargo run --features large_size --release --bin seg_queue | tee large_seg_queue.txt
cargo run --features large_size --release --bin mpmc | tee large_mpmc.txt
cargo run --features large_size --release --bin atomicring | tee large_atomicring.txt
cargo run --features large_size --release --bin atomicringqueue | tee large_atomicringqueue.txt
./plot.py large_*.txt
mv plot.png plot_large.png
- `N = 5000000`
- `T = 4`

```
### Running

Runs benchmarks, stores results into `*.txt` files, and generates `plot.png`:

you might need to install go and python matplotlib
```
easy_install matplotlib
./run_all.sh
```

Dependencies:

- Rust compiler
- Go compiler
- Bash
- Python 2
- Matplotlib

### Results

Benchmarked on 2017-11-09:
Benchmarked on 2018-06-11:

![Benchmark results](https://i.imgur.com/W0cSEVd.png)
![Benchmark results](https://i.imgur.com/tRI4HMO.png)
Loading

0 comments on commit 5050c89

Please sign in to comment.