ractor-rails-shim 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f462e8a604fac024cc13b3f1667ec9e9c79207cb675a473e7f2f536e7ac4c8d
4
- data.tar.gz: 76652b85a06f3c7e6cc50b7619f4b28c52da420f6f946f09518f01b5143c4094
3
+ metadata.gz: 515076a823c0767ce28d1bf35545a6ced10f2ef1f628f8e263cde654b58fb899
4
+ data.tar.gz: df743b8da60645f80569b646301d7d0fd5c197756ffb928921144f7fac161c5e
5
5
  SHA512:
6
- metadata.gz: 83964fbfa3a113e70ca8bdfd5f6f69ea3598cf028207bb43971a9b6ed135e28f4b2f2a5b1d0bbcdf574a9a12313ff9ab6664182d22b8a3e00ab959105bdb72ce
7
- data.tar.gz: be2ef63949ea84ac7f3dfa72a65d57f2687b2b1dc53de6f85a8709d42b84fcec5588f429e298beb8aa76e682b593ebfeb49dd292191cc620bd847b9b84e78c78
6
+ metadata.gz: c4c6fc83fc7fc61a0fecf603e26e2031d2876f20222c29717cc267fc99acfd7ed4e3e05cd98995099a62807bc37e37f34635c676c334caf2c99cc8d4acc50c0d
7
+ data.tar.gz: 53bb7cf546753b3bc7c6dc7313dc9b0bbf86b616f1e8f7fc1f0f45d0428988efeee0308bf93c7cf127e9219ebcd747f76340a86b750853a5fad81eaae5da4a0e
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+ - Improved the published gem summary and description (gemspec). Metadata-only
12
+ release — no code changes.
13
+
10
14
  ### Added — ActiveRecord query-path ractor-safety (Blocker 1 deep work)
11
15
  - `RactorRailsShim.worker_ar_init(app)` — a shareable Rack middleware that
12
16
  calls `init_worker_ar_connections!` on each worker's first request. Kino's
data/README.md CHANGED
@@ -35,6 +35,19 @@ run a Rails app in Ractor mode is
35
35
  developed and tested against a real Rails 8.1 app **served by kino**; that is
36
36
  the configuration it is verified against.
37
37
 
38
+ **Patched kino:** the shim was validated against a kino build carrying a
39
+ per-ractor env-string cache fix that removes a cross-ractor SIGBUS during
40
+ sustained writes. The patch is published at
41
+ [DDKatch/kino](https://github.com/DDKatch/kino) on the
42
+ `ractor-per-ractor-env-cache` branch. Use that fork (rather than upstream
43
+ `yaroslav/kino`) if you hit write-path crashes. To build it: clone the fork,
44
+ check out that branch, then `asdf local rust 1.85.0 && cargo build --release`
45
+ (the native extension is compiled by the Rails app's `bundle install`).
46
+
47
+ **Benchmarks:** throughput/latency/memory of this shim + the test app under
48
+ kino `:ractor` vs Puma vs Falcon are documented in
49
+ [ractor-rails-shim-test-app/BENCHMARKS.md](https://github.com/DDKatch/ractor-rails-shim-test-app/blob/main/BENCHMARKS.md).
50
+
38
51
  ## Why
39
52
 
40
53
  Rails stores global state in class-level instance variables:
@@ -15,6 +15,16 @@ module RactorRailsShim
15
15
  Finding = Data.define(:owner, :ivar, :value_class, :shareable, :source, :kind)
16
16
 
17
17
  class << self
18
+ # Safely derive a value's class name. BasicObject (and its subclasses)
19
+ # don't define `.class`, so calling it raises NoMethodError — fall back
20
+ # to "BasicObject" in that case.
21
+ def safe_class(val)
22
+ val.class.name || val.class.to_s
23
+ rescue NoMethodError
24
+ "BasicObject"
25
+ end
26
+ private :safe_class
27
+
18
28
  # Scan all loaded classes/modules and report class ivars AND class
19
29
  # variables holding unshareable values. Returns an array of Finding.
20
30
  def scan
@@ -49,7 +59,7 @@ module RactorRailsShim
49
59
  findings << Finding.new(
50
60
  owner: mod.name,
51
61
  ivar: ivar.to_s,
52
- value_class: val.class.name || val.class.to_s,
62
+ value_class: safe_class(val),
53
63
  shareable: shareable,
54
64
  source: source,
55
65
  kind: :ivar
@@ -82,7 +92,7 @@ module RactorRailsShim
82
92
  findings << Finding.new(
83
93
  owner: mod.name,
84
94
  ivar: cvar.to_s,
85
- value_class: val.class.name || val.class.to_s,
95
+ value_class: safe_class(val),
86
96
  shareable: shareable,
87
97
  source: source,
88
98
  kind: :cvar
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RactorRailsShim
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ractor-rails-shim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dev
@@ -24,15 +24,23 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: '7.0'
26
26
  description: |
27
- Rails stores global state (Rails.application, Rails.cache, Rails.logger,
28
- config set via mattr_accessor) in class-level instance variables, which
29
- are illegal to read or write from non-main Ractors. This shim reroutes
30
- those accessors through ActiveSupport::IsolatedExecutionState (which is
31
- already Ractor-safe, being thread-local with per-ractor threads) or
32
- Ractor.store_if_absent, so a Rails app can run in Ractor mode.
27
+ ractor-rails-shim makes a Rails application Ractor-safe, so it can run in
28
+ Ractor mode serving requests from worker Ractors that share one frozen
29
+ app graph, instead of forking N separate processes.
33
30
 
34
- This is a stopgap: the goal is for Rails to do this upstream, at which
35
- point the shim becomes a no-op and can be removed.
31
+ Rails keeps global state (Rails.application, Rails.cache, Rails.logger,
32
+ and every config value set via mattr_accessor / class_attribute) in
33
+ class-level instance variables, which Ruby forbids reading or writing from
34
+ a non-main Ractor. The shim reroutes those accessors through Ractor-safe
35
+ storage (ActiveSupport::IsolatedExecutionState, or Ractor.store_if_absent)
36
+ and patches the handful of raw class-ivar accessors Rails reads
37
+ per-request.
38
+
39
+ It is verified against a real Rails 8.1 app (Devise, Propshaft, Kaminari,
40
+ PostgreSQL) served by the kino web server in `kino -m ractor` mode.
41
+
42
+ This is a stopgap: once Rails supports Ractor mode upstream, this gem
43
+ becomes a no-op and can be removed.
36
44
  email:
37
45
  - kachur.daniil@gmail.com
38
46
  executables:
@@ -100,5 +108,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
108
  requirements: []
101
109
  rubygems_version: 4.0.10
102
110
  specification_version: 4
103
- summary: Monkey-patch Rails class-level globals to be Ractor-safe
111
+ summary: Make Rails apps Ractor-safe so they can run in Ractor mode (e.g. under the
112
+ kino web server).
104
113
  test_files: []