Ruby、Ractor和无锁数据结构
Ruby, Ractors, and lock-free data structures

原始链接: https://iliabylich.github.io/ruby-ractors-and-lock-free-data-structures/

这个故事讲述的是 Ruby 中的并发数据结构。目标是展示如何在存在全局可变状态的情况下实现真正的并行性(在撰写本文时,Ruby 内置原语不支持)。熟悉 Ruby、Rust、C(以及一些其他工具)当然更好,但并非强制要求。代码示例的仓库可在 GitHub 上找到,运行它需要一个比较新的 Ruby 版本(如果可以本地编译,master 分支可能是最佳选择),以及 Rust 和 C 编译器。

Hacker News 上的一篇文章重点介绍了 Mike Perham(Sidekiq 的创建者)使用 Ruby 的 Ractors 来扩展使用 Redis 集群的 Sidekiq 的实验。Ractors 的目的是允许 Ruby 代码绕过全局虚拟机锁 (GVL),从而实现并发。Perham 使用了他的“Ratomic”库,该库为 Ractors 提供了可变的数据结构。然而,他发现 Ractors 难以编程,并指出了诸如缺乏词法作用域和闭包变量访问之类的限制。他将这种体验比作最初学习 Go 语言中的 goroutines 和 channels,这表明有效采用 Ractors 需要克服相当大的学习曲线。尽管面临挑战,但他的努力表明了利用 Ractors 来扩展 Ruby 应用程序(尤其是在 Sidekiq 的上下文中)的趋势。
相关文章
  • (评论) 2023-11-10
  • (评论) 2024-04-27
  • (评论) 2025-03-16
  • (评论) 2025-03-17
  • (评论) 2024-01-06

  • 原文

    This story is about concurrent data structures in the context of Ruby. The goal here is to demonstrate how true parallelism can be achieved with global mutable state (which at the time of writing, is not supported by built-in Ruby primitives).

    Familiarity with Ruby, Rust, C, (and a bit of other tooling) is nice to have, but hopefully not mandatory.

    The repository with code examples can be found on GitHub, to run it you need a relatively new version of Ruby (master branch is probably the best option if you can compile it locally), Rust and C compilers.

    联系我们 contact @ memedata.com