Code Monkey home page Code Monkey logo

elimination-backoff-stack's Introduction

Work in progress

Before you consider using this ask yourself the following questions:

  • Is my workload running on a machine > 8 cores?

    If not you likely won't see enough contention that an elimination back-off stack outperforms a classic Treiber stack or even an Arc<Mutex<Vec<T>>>.

  • Do I trust the author's use of atomics?

    If yes, take a look at all grep -r -E "compare_and_set" anyways.

  • Do I need a single coordination point through a stack to solve my problem?

    Think about how you could solve your problem in a parallel fashion requiring less coordination.

Lock-free elimination back-off stack

A normal lock-free Treiber stack [1] linearizes concurrent access through a single atomic head pointer on which push and pop operations loop trying to compare-and-swap it. Usually one uses exponential backoff to circumvent contention. This results in a single sequential bottleneck and a lot of cache coherence traffic.

A lock-free elimination back-off stack wraps such a lock-free Treiber stack, but instead of simply exponentially backing off on compare-and-swap failures, it uses something called an EliminationArray. Each slot within such an EliminationArray enables a thread executing a push operation to hand its item over to a thread executing a pop operation. On contention a thread tries to exchange on a randomly chosen slot within the EliminationArray. On failure of such an exchange it loops to the beginning retrying on the stack again.

The result is a lock-free stack that is both linearizable and parallel.

Silly Benchmark

Criterion test comparing:

  • Arc<Mutex<Vec<_>>>

  • TreiberStack

  • EliminationBackoffStack - Simply switching back and forth between stack and elimination array.

  • EliminationBackoffStack - Exponentially backing off from the stack to the elimination array both in space and time.

X-Axis: Number of competing threads.

Y-Axis: Average time it took all threads to push and pop 1000 items each.

Performance

[1] Treiber, R. Kent. Systems programming: Coping with parallelism. New York: International Business Machines Incorporated, Thomas J. Watson Research Center, 1986.

elimination-backoff-stack's People

Contributors

mxinden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

icodein

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.