#thread #executor #task-queue #task-scheduling

executors

A collection of high-performance task executors

15 releases (8 breaking)

0.9.0 Apr 5, 2021
0.8.0 Oct 28, 2020
0.7.0 Jul 13, 2020
0.6.0 Feb 20, 2020
0.3.0 Dec 19, 2017

#439 in Concurrency

Download history 75/week @ 2024-06-10 83/week @ 2024-06-17 81/week @ 2024-06-24 11/week @ 2024-07-01 48/week @ 2024-07-08 73/week @ 2024-07-15 57/week @ 2024-07-22 70/week @ 2024-07-29 64/week @ 2024-08-05 65/week @ 2024-08-12 60/week @ 2024-08-19 68/week @ 2024-08-26 42/week @ 2024-09-02 50/week @ 2024-09-09 46/week @ 2024-09-16 144/week @ 2024-09-23

290 downloads per month
Used in 7 crates (2 directly)

MIT license

160KB
3.5K SLoC

This crate provides a number of task executors all implementing the Executor trait.

General examples can be found in the Executor trait documentation, and implementation specific examples with each implementation module.

Crate Feature Flags

The following crate feature flags are available. They are configured in your Cargo.toml.

  • threadpool-exec (default)
  • cb-channel-exec (default)
  • workstealing-exec (default)
  • defaults (default)
  • ws-timed-fairness (default)
    • This feature flag determines the fairness mechanism between local and global queues in the crossbeam_workstealing_pool.
    • If the flag is enabled the fairness is time-based. The global queue will be checked every 100ms.
    • If the flags is absent the fairness is count-based. The global queue will be checked every 100 local jobs.
    • Which one you should pick depends on your application.
    • Time-based fairness is a compromise between latency of externally scheduled jobs and overall throughput.
    • Count-based is going to depend heavily on how long your jobs typically are, but counting is cheaper than checking time, so it can lead to higher throughput.
  • ws-no-park
    • Disable thread parking for the crossbeam_workstealing_pool.
    • This is generally detrimental to performance, as idle threads will unnecessarily hang on to CPU resources.
    • However, for very latency sensitive interactions with external resources (e.g., I/O), this can reduce overall job latency.
  • thread-pinning
    • Allows pool threads to be pinned to specific cores.
    • This can reduce cache invalidation overhead when threads sleep and then are woken up later.
    • However, if your cores are needed by other processes, it can also introduce additional scheduling delay, if the pinned core isn't available immediately at wake time.
    • Use with care.
  • numa-aware
    • Make memory architecture aware decisions.
    • Concretely this setting currently only affects crossbeam_workstealing_pool.
    • When it is enabled, work-stealing will happen by memory proximity.
    • That is threads with too little work will try to steal work from memory-close other threads first, before trying further away threads.
  • produce-metrics
    • Every executor provided in this crate can produce metrics using the metrics crate.
    • The metrics are executors.jobs_executed ("How many jobs were executed in total?") and executors.jobs_queued ("How many jobs are currently waiting to be executed?").
    • Not all executors produce all metrics.
    • WARNING: Collecting these metrics typically has a serious performance impact. You should only consider using this in production if your jobs are fairly large anyway (say in the millisecond range).

Dependencies

~1.4–2.5MB
~52K SLoC