Project

ratomic

0.02
There's a lot of open issues
Mutable data structures for Ractors
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Ratomic

Ratomic provides mutable data structures for use with Ruby's Ractors. This allows Ruby code to scale beyond the infamous GVL.

HELP WANTED!

If you know Rust and Ruby C-extensions, we need your help! This project is brand new and could use your knowledge! If you don't know Rust or C, consider this a challenge to learn and solve. Read through the issues to find work that sounds interesting to you.

How to contribute

Please make sure to understand our Code of Conduct.

After changing code, you can give it a spin with:

rake

This should compile the Rust code and run all tests.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add ratomic

TODO: We have not released a gem yet.

Usage

Ratomic provides several useful Ractor-safe structures. Note the APIs available are frequently very limited compared to Ruby's broad API.

These structures are designed for use as class-level constants so they can be shared by numerous Ractors.

Ratomic::Counter

c = Ratomic::Counter.new
c.read # => 0
c.inc
c.inc(5)
c.dec(1)
c.dec
c.read # => 4

Ratomic::Pool

A Ractor-safe object pool:

POOL = Ratomic::Pool.new(5, 1.0) { Object.new }
POOL.with do |obj|
  # do something with obj
end

Ratomic::Map

A Ractor-safe map/hash structure:

HASH = Ratomic::Map.new
HASH["mike"] = 123
HASH["mike"] # => 123
HASH.fetch_and_modify(key) {|value| v + 1 }
HASH.clear

Ratomic::Queue

A multi-producer, multi-consumer queue.

q = Ratomic::Queue.new
q.push(Object.new)
q.pop # => <Object>

Thanks

Ilya Bylich wrote and documented his original research at Ruby, Ractors, and Lock-free Data Structures/. Thank you for your impressive work, Ilya!

This repo is further research into the usability and limitations of Ractor-friendly structures in Ruby code and gems.

License

MIT License.