Coder Social home page Coder Social logo

lagoon's Introduction

Lagoon

Crates.io version docs.rs

Lagoon is a thread pool crate that aims to address many of the problems with existing thread pool crates.

Example

Lagoon's scoped jobs can be used for simple rayon-like data parallelism.

// A vector of the numbers 0 to 99
let mut data = (0..100).collect::<Vec<u32>>();

lagoon::ThreadPool::default().scoped(|s| {
    // For each element in the vector...
    for x in data.iter_mut() {
        // ...spawn a job that squares that element
        s.run(move || *x *= *x);
    }
});

// Demonstrate that the elements have indeed been squared
assert!((0..100)
    .map(|x| x * x)
    .zip(data.into_iter())
    .all(|(x, y)| x == y));

Features

  • Scoped jobs: Safely spawn jobs that have access to their parent scope!
  • Job handles: Receive the result of a job when it finishes, or wait on it to finish!
  • Global pool: A pay-for-what-you-use global thread pool that avoids dependencies fighting over resources!
  • Customise thread attributes: Specify thread name, stack size, etc.

Planned Features

  • Async support for job waiting: Use the thread pool in an async context!

Performance

Lagoon has very competitive performance. Below are timings required for each thread pool crate to spawn a new pool, execute 100,000 trivial jobs, and then finish executing (i.e: smaller is better) compared to common alternative crates.

Benchmark, demonstrating Lagoon's performance compared to other thread pool crates

Spawning 100000 trivial tasks/lagoon     time:   [15.124 ms 16.437 ms 17.871 ms]
Spawning 100000 trivial tasks/threadpool time:   [59.108 ms 59.549 ms 59.989 ms]
Spawning 100000 trivial tasks/uvth       time:   [11.494 ms 12.598 ms 13.750 ms]
Spawning 100000 trivial tasks/rusty_pool time:   [40.203 ms 44.778 ms 49.612 ms]

Benchmarks were run on an AMD Ryzen 7 3700x with 16 threads.

License

Lagoon is licensed under the MIT license (see LICENSE) in the main repository.

lagoon's People

Contributors

zesterer 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.