What is Ruby Concurrent?

Overview of a Ruby gem designed as a set of concurrency tools
01 September 2017   4945

Concurrency is a form of computing in which several computations are executed during overlapping time periods—concurrently—instead of sequentially (one completing before the next starts). This is a property of a system—this may be an individual program, a computer, or a network—and there is a separate execution point or "thread of control" for each computation ("process"). A concurrent system is one where a computation can advance without waiting for all other computations to complete.

Modern concurrency tools include agents, futures, promises, thread pools actors, supervisors etc.Concurrent Ruby makes the strongest thread safety guarantees of any Ruby concurrency library. Every abstraction in this library is thread safe. Similarly, all are deadlock free and many are fully lock free.

Concurrent Ruby is a set of 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

Concurrency Abstractions

  • Async (Concurrent::Async): A mixin module that provides simple asynchronous behavior to a class, turning it into a simple actor.
  • Future (Concurrent::Future): An asynchronous operation that produces a value. It represents a promise to complete an action at some time in the future.
    • Dataflow: Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
  • Promise (Concurrent::Promise): Similar to Futures, with more features. It represents the eventual value returned from the single completion of an operation.
  • ScheduledTask (Concurrent::ScheduledTask): Like a Future scheduled for a specific future time.
  • TimerTask (Concurrent::TimerTask): A Thread that periodically wakes up to perform work at regular intervals.

Installation

gem install concurrent-ruby

or add the following line to Gemfile:

gem 'concurrent-ruby', require: 'concurrent'

and run bundle install from your shell

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'

See GitHub for more info.

Ruby/RoR News Digest 18 - 24.01

Matz' interview from Ruby Russia 2019, JIT compiler by Red Hat, Reverse Coverage tool guide and many other interesting things
24 January 2020   71

Greetings! I hope your week went great! Here's new Ruby news digest.

Learn about the modern Ruby serializers, how to speed up your Rails apps and how to migrate to strong parameters.

Articles

  • Yukihiro Matsumoto: "Ruby is designed for humans, not machines"

Creator of the Ruby language once again visited largest Russian Ruby event and his interview is finally available

  • Modern Ruby Serializers 

Check the history of various serializers, all the way to the introduction of SimpleAMS, a new serialization library, created by the author of the post and check how it compares to other options

  • MIR: A lightweight JIT compiler project

Red Hat's light JIT compiler development had begun

Guides

  • Rails is Fast: Optimize Your View Performance

Learn how to speed uo your Rails app

  • Reverse Coverage: Find which tests execute which lines of code

Guide on ReverseCoverage tool that can show which tests execute which lines of code

  • URI.escape is obsolete. Percent-encoding your query string

Rails and non-Rails approaches to properly encoding your query strings now, because the URI.escape is quite an old method

  • From Single drop-down to Multiple check-boxes

Learn how to move from a belongs_to/has_many to has_and_belongs_to_many association in a live Rails app.

  • Ruby 2.7 allows placing of comment lines between fluent dots

Tiny, but handy new feature may not know about

  • The Complete Guide to Migrate to Strong Parameters

Rails 4.0 had added strong parameters so, if you’re still using protected attributes anywhere though, you may benefit from this tutorial.

Video

  • How to use AWS Cloud9 for Ruby on Rails development