Git Product home page Git Product logo

devigned / concurrent-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ruby-concurrency/concurrent-ruby

0.0 3.0 0.0 9.14 MB

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.

Home Page: http://www.concurrent-ruby.com

License: Other

Ruby 70.78% Java 28.25% C 0.77% CSS 0.15% HTML 0.05%

concurrent-ruby's Introduction

Concurrent Ruby

Gem Version Build Status Build status Code Climate Inline docs Dependency Status License Gitter chat

Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and classic concurrency patterns.

The design goals of this gem are:

  • Be an 'unopinionated' toolbox that provides useful utilities without debating which is better or why
  • Remain free of external gem dependencies
  • Stay true to the spirit of the languages providing inspiration
  • But implement in a way that makes sense for Ruby
  • Keep the semantics as idiomatic Ruby as possible
  • Support features that make sense in Ruby
  • Exclude features that don't make sense in Ruby
  • Be small, lean, and loosely coupled

Supported Ruby versions

MRI 1.9.3, 2.0, 2.1, 2.2, JRuby (1.9 mode), and Rubinius 2.x are supported. This gem should be fully compatible with any interpreter that is compliant with Ruby 1.9.3 or newer. Java 8 is preferred for JRuby but every Java version on which JRuby 9000 runs will be supported.

Features & Documentation

We have a roadmap guiding our work toward the v1.0.0 release.

The primary site for documentation is the automatically generated API documentation

We also have a mailing list and IRC (gitter).

This library contains a variety of concurrency abstractions at high and low levels. One of the high-level abstractions is likely to meet most common needs.

General-purpose Concurrency Abstractions

  • Async: A mixin module that provides simple asynchronous behavior to any standard class/object or object.
  • Future: An asynchronous operation that produces a value.
    • Dataflow: Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
  • Promise: Similar to Futures, with more features.
  • ScheduledTask: Like a Future scheduled for a specific future time.
  • TimerTask: A Thread that periodically wakes up to perform work at regular intervals.

Thread-safe Value Objects, Structures, and Collections

Collection classes that were originally part of the (deprecated) thread_safe gem:

  • Array A thread-safe subclass of Ruby's standard Array.
  • Hash A thread-safe subclass of Ruby's standard Hash.
  • Map A hash-like object that should have much better performance characteristics, especially under high concurrency, than Concurrent::Hash.
  • Tuple A fixed size array with volatile (synchronized, thread safe) getters/setters.

Value objects inspired by other languages:

  • Atom: A way to manage shared, synchronous, independent state.
  • Maybe A thread-safe, immutable object representing an optional value, based on Haskell Data.Maybe.
  • Delay Lazy evaluation of a block yielding an immutable result. Based on Clojure's delay.

Structure classes derived from Ruby's Struct:

  • ImmutableStruct Immutable struct where values are set at construction and cannot be changed later.
  • MutableStruct Synchronized, mutable struct where values can be safely changed at any time.
  • SettableStruct Synchronized, write-once struct where values can be set at most once, either at construction or any time thereafter.

Thread-safe variables:

Java-inspired ThreadPools and Other Executors

  • See the thread pool overview, which also contains a list of other Executors available.

Thread Synchronization Classes and Algorithms

  • CountdownLatch A synchronization object that allows one thread to wait on multiple other threads.
  • CyclicBarrier A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.
  • Event Old school kernel-style event.
  • Exchanger
  • I-Structure (IVar) Similar to a "future" but can be manually assigned once, after which it becomes immutable.
  • M-Structure (MVar) A synchronized single element container.
  • ReadWriteLock A lock that supports multiple readers but only one writer.
  • ReentrantReadWriteLock A read/write lock with reentrant and upgrade features.
  • Semaphore A counting-based locking mechanism that uses permits.
  • Software transactional memory (TVar) A transactional variable - a single-element container that is used as part of a transaction.

Edge Features

These are available in the concurrent-ruby-edge companion gem.

These features are under active development and may change frequently. They are expected not to keep backward compatibility (there may also lack tests and documentation). Semantic versions will be obeyed though. Features developed in concurrent-ruby-edge are expected to move to concurrent-ruby when final.

  • Actor: Implements the Actor Model, where concurrent actors exchange messages.
  • new Future Framework - new unified implementation of Futures and Promises which combines Features of previous Future, Promise, IVar, Event, Probe, dataflow, Delay, TimerTask into single framework. It uses extensively new synchronization layer to make all the features non-blocking and lock-free with exception of obviously blocking operations like #wait, #value. It also offers better performance.
  • Agent: A single atomic value that represents an identity.
  • Channel: Communicating Sequential Processes (CSP).
  • LazyRegister
  • AtomicMarkableReference
  • LockFreeLinkedSet
  • LockFreeStack

Statuses:

Why are these not in core?

  • Actor - Partial documentation and tests; stability is good.
  • Future/Promise Framework - API changes; partial documentation and tests; stability good.
  • Agent - Incomplete behaviour compared to Clojure's models; stability good.
  • Channel - Missing documentation; limted features; stability good.
  • LazyRegister - Missing documentation and tests.
  • AtomicMarkableReference, LockFreeLinkedSet, LockFreeStack - Needs real world battle testing

Usage

Everything within this gem can be loaded simply by requiring it:

require 'concurrent'

To use the tools in the Edge gem it must be required separately:

require 'concurrent-edge'

If the library does not behave as expected, Concurrent.use_stdlib_logger(Logger::DEBUG) could help to reveal the problem.

Installation

gem install concurrent-ruby

or add the following line to Gemfile:

gem 'concurrent-ruby'

and run bundle install from your shell.

Edge Gem Installation

The Edge gem must be installed separately from the core gem:

gem install concurrent-ruby-edge

or add the following line to Gemfile:

gem 'concurrent-ruby-edge'

and run bundle install from your shell.

C Extensions for MRI

Potential performance improvements may be achieved under MRI by installing optional C extensions. To minimize installation errors the C extensions are available in the concurrent-ruby-ext extension gem. concurrent-ruby and concurrent-ruby-ext are always released together with same version. Simply install the extension gem too:

gem install concurrent-ruby-ext

or add the following line to Gemfile:

gem 'concurrent-ruby-ext'

and run bundle install from your shell.

In code it is only necessary to

require 'concurrent'

The concurrent-ruby gem will automatically detect the presence of the concurrent-ruby-ext gem and load the appropriate C extensions.

Note For gem developers

No gems should depend on concurrent-ruby-ext. Doing so will force C extensions on your users. The best practice is to depend on concurrent-ruby and let users to decide if they want C extensions.

Building

All published versions of this gem (core, extension, and several platform-specific packages) are compiled, packaged, tested, and published using an open, automated process. This process can also be used to create pre-compiled binaries of the extension gem for virtually any platform. Documentation is forthcoming...

*MRI only*
bundle exec rake build:native       # Build concurrent-ruby-ext-<version>-<platform>.gem into the pkg dir
bundle exec rake compile:extension  # Compile extension

*JRuby only*
bundle exec rake build              # Build JRuby-specific core gem (alias for `build:core`)
bundle exec rake build:core         # Build concurrent-ruby-<version>-java.gem into the pkg directory

*All except JRuby*
bundle exec rake build:core         # Build concurrent-ruby-<version>.gem into the pkg directory
bundle exec rake build:ext          # Build concurrent-ruby-ext-<version>.gem into the pkg directory

*When Docker IS installed*
bundle exec rake build:windows      # Build the windows binary <version> gems per rake-compiler-dock
bundle exec rake build              # Build core, extension, and edge gems, including Windows binaries

*When Docker is NOT installed*
bundle exec rake build              # Build core, extension, and edge gems (excluding Windows binaries)

*All*
bundle exec rake clean              # Remove any temporary products
bundle exec rake clobber            # Remove any generated file
bundle exec rake compile            # Compile all the extensions

Maintainers

Special Thanks

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License and Copyright

Concurrent Ruby is free software released under the MIT License.

The Concurrent Ruby logo was designed by David Jones. It is Copyright © 2014 Jerry D'Antonio. All Rights Reserved.

concurrent-ruby's People

Contributors

jdantonio avatar pitr-ch avatar mighe avatar chrisseaton avatar ianks avatar rkday avatar obrok avatar lucasallan avatar adamruzicka avatar alexdowad avatar inecas avatar billdueber avatar mastfish avatar larskanis avatar tenderlove avatar rrrene avatar rranelli avatar amutake avatar quinnwilton avatar larrylv avatar jrochkind avatar brixen avatar ferdinandrosario avatar dueckes avatar zph avatar sschepens avatar sebastianedwards avatar sheaney avatar repinel avatar krishan avatar

Watchers

David Justice avatar James Cloos avatar  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.