#executor #concurrency #thread

executors

A collection of high-performance task executors

8 releases

✓ Uses Rust 2018 edition

0.4.4 May 14, 2019
0.4.3 Apr 10, 2019
0.4.2 Mar 20, 2019
0.4.1 Jul 12, 2018
0.1.0 Dec 13, 2017

#46 in Concurrency

Download history 46/week @ 2019-03-26 23/week @ 2019-04-02 75/week @ 2019-04-09 17/week @ 2019-04-16 47/week @ 2019-04-23 35/week @ 2019-04-30 44/week @ 2019-05-07 81/week @ 2019-05-14 126/week @ 2019-05-21 45/week @ 2019-05-28 77/week @ 2019-06-04 54/week @ 2019-06-11 99/week @ 2019-06-18 53/week @ 2019-06-25 80/week @ 2019-07-02

216 downloads per month
Used in 2 crates (1 directly)

MIT license

62KB
1.5K SLoC

Executors

A library with high-performace task executors for Rust.

License Cargo Documentation Build Status

Usage

Add this to your Cargo.toml:

[dependencies]
executors = "0.4"

You can use, for example, the crossbeam_workstealing_pool to schedule a number n_jobs over a number n_workers threads, and collect the results via an mpsc::channel.

use executors::*;
use executors::crossbeam_workstealing_pool::ThreadPool;
use std::sync::mpsc::channel;

let n_workers = 4;
let n_jobs = 8;
let pool = ThreadPool::new(n_workers);

let (tx, rx) = channel();
for _ in 0..n_jobs {
    let tx = tx.clone();
    pool.execute(move|| {
        tx.send(1).expect("channel will be there waiting for the pool");
    });
}

assert_eq!(rx.iter().take(n_jobs).fold(0, |a, b| a + b), 8);

Rust Version

Requires at least Rust 1.26, due to crossbeam-channel requirements.

Deciding on an Implementation

To select an Executor implementation, it is best to test the exact requirements on the target hardware. The crate executor-performance provides a performance testing suite for the provided implementations. To use it clone this repository, run cargo build --release, and then check target/release/executor-performance --help to see the available options. There is also a small script to test thread-scaling with some reasonable default options.

In general, crossbeam_workstealing_pool works best for workloads where the tasks on the worker threads spawn more and more tasks. If all tasks a spawned from a single thread that isn't part of the threadpool, then the threadpool_executor tends perform best with single worker and crossbeam_channel_pool performs best for a larger number of workers.

If you don't know what hardware your code is going to run on, use the crossbeam_workstealing_pool. It tends to perform best on all the hardware I have tested (which is pretty much Intel processors like i7 and Xeon).

License

Licensed under the terms of MIT license.

See LICENSE for details.

Dependencies

~1MB