kino 0.7.1 → 0.8.0

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.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -0
  3. data/CHANGELOG.md +286 -0
  4. data/Cargo.lock +209 -132
  5. data/README.md +269 -438
  6. data/doc/README.md +27 -2
  7. data/doc/architecture.md +862 -43
  8. data/doc/benchmarks.md +444 -214
  9. data/doc/configuration.md +215 -0
  10. data/doc/operations.md +258 -0
  11. data/doc/rails-on-ractors.md +161 -49
  12. data/doc/streaming.md +52 -0
  13. data/doc/websockets.md +469 -0
  14. data/doc/why-kino.md +6 -6
  15. data/doc/worker-loop.md +462 -0
  16. data/ext/kino/Cargo.toml +19 -3
  17. data/ext/kino/build.rs +32 -1
  18. data/ext/kino/clippy.toml +10 -0
  19. data/ext/kino/src/access_log.rs +70 -92
  20. data/ext/kino/src/control.rs +26 -685
  21. data/ext/kino/src/counters.rs +132 -0
  22. data/ext/kino/src/cpus.rs +1 -18
  23. data/ext/kino/src/dispatch/tests.rs +731 -0
  24. data/ext/kino/src/dispatch.rs +276 -0
  25. data/ext/kino/src/doorbell.rs +108 -0
  26. data/ext/kino/src/env_strings.rs +26 -30
  27. data/ext/kino/src/framing.rs +110 -0
  28. data/ext/kino/src/gvl.rs +292 -66
  29. data/ext/kino/src/hijack/tests.rs +416 -0
  30. data/ext/kino/src/hijack.rs +471 -0
  31. data/ext/kino/src/inline/answer.rs +488 -0
  32. data/ext/kino/src/inline/conn.rs +1124 -0
  33. data/ext/kino/src/inline/deadline.rs +421 -0
  34. data/ext/kino/src/inline/encode.rs +119 -0
  35. data/ext/kino/src/inline/io.rs +487 -0
  36. data/ext/kino/src/inline/mod.rs +766 -0
  37. data/ext/kino/src/inline/parity.rs +862 -0
  38. data/ext/kino/src/inline/parse.rs +131 -0
  39. data/ext/kino/src/inline/spin.rs +428 -0
  40. data/ext/kino/src/inline/testing.rs +628 -0
  41. data/ext/kino/src/io_shards.rs +240 -192
  42. data/ext/kino/src/lane_room.rs +99 -0
  43. data/ext/kino/src/lib.rs +139 -77
  44. data/ext/kino/src/listen.rs +180 -12
  45. data/ext/kino/src/log.rs +12 -47
  46. data/ext/kino/src/logsink.rs +3 -9
  47. data/ext/kino/src/mono.rs +12 -17
  48. data/ext/kino/src/pin.rs +3 -3
  49. data/ext/kino/src/queue/mod.rs +54 -0
  50. data/ext/kino/src/queue/take.rs +503 -0
  51. data/ext/kino/src/queue/testing.rs +107 -0
  52. data/ext/kino/src/queue/tests.rs +581 -0
  53. data/ext/kino/src/queue/worker.rs +501 -0
  54. data/ext/kino/src/registry.rs +168 -379
  55. data/ext/kino/src/request.rs +834 -235
  56. data/ext/kino/src/response.rs +532 -94
  57. data/ext/kino/src/server/accept.rs +322 -0
  58. data/ext/kino/src/server/config.rs +138 -0
  59. data/ext/kino/src/server/handle.rs +247 -0
  60. data/ext/kino/src/server/intake.rs +217 -0
  61. data/ext/kino/src/server/mod.rs +157 -0
  62. data/ext/kino/src/server/natives.rs +223 -0
  63. data/ext/kino/src/server/serve/intake_tests.rs +458 -0
  64. data/ext/kino/src/server/serve.rs +436 -0
  65. data/ext/kino/src/server/tests.rs +532 -0
  66. data/ext/kino/src/shared_gvl.rs +50 -0
  67. data/ext/kino/src/slot/lane.rs +138 -0
  68. data/ext/kino/src/slot/life.rs +111 -0
  69. data/ext/kino/src/slot/load.rs +193 -0
  70. data/ext/kino/src/slot/mod.rs +494 -0
  71. data/ext/kino/src/slot/park.rs +82 -0
  72. data/ext/kino/src/stats.rs +936 -0
  73. data/ext/kino/src/symbols.rs +66 -0
  74. data/ext/kino/src/test_support.rs +24 -14
  75. data/ext/kino/src/testing.rs +409 -0
  76. data/ext/kino/src/ticker.rs +87 -0
  77. data/ext/kino/src/timer.rs +4 -7
  78. data/ext/kino/src/tls.rs +101 -131
  79. data/ext/kino/src/typed_data.rs +131 -0
  80. data/ext/kino/src/upgrade.rs +77 -0
  81. data/ext/kino/src/ws/codec.rs +470 -0
  82. data/ext/kino/src/ws/drive.rs +600 -0
  83. data/ext/kino/src/ws/handshake.rs +267 -0
  84. data/ext/kino/src/ws/mod.rs +317 -0
  85. data/ext/kino/src/ws/server_tests.rs +759 -0
  86. data/ext/kino/src/ws/socket.rs +279 -0
  87. data/ext/kino/src/ws/stats.rs +88 -0
  88. data/ext/kino/src/ws/testing.rs +156 -0
  89. data/ext/kino/src/ws/topics.rs +550 -0
  90. data/lib/kino/cli.rb +100 -9
  91. data/lib/kino/configuration.rb +32 -10
  92. data/lib/kino/crash_backoff.rb +56 -0
  93. data/lib/kino/input.rb +36 -17
  94. data/lib/kino/log.rb +8 -1
  95. data/lib/kino/monitor.rb +1 -1
  96. data/lib/kino/pool.rb +169 -0
  97. data/lib/kino/pool_scaler.rb +12 -13
  98. data/lib/kino/quarantine_monitor.rb +3 -3
  99. data/lib/kino/ractor_supervisor.rb +201 -161
  100. data/lib/kino/server.rb +291 -185
  101. data/lib/kino/slot_bank.rb +21 -9
  102. data/lib/kino/stream.rb +2 -2
  103. data/lib/kino/teardown.rb +33 -0
  104. data/lib/kino/templates/kino.rb.tt +41 -6
  105. data/lib/kino/threaded_pool.rb +87 -102
  106. data/lib/kino/version.rb +1 -1
  107. data/lib/kino/web_socket.rb +125 -0
  108. data/lib/kino/worker/loop.rb +319 -0
  109. data/lib/kino/worker.rb +345 -79
  110. data/lib/kino/worker_hooks.rb +7 -1
  111. data/lib/kino/worker_row.rb +15 -0
  112. data/lib/kino.rb +27 -3
  113. data/lib/rackup/handler/kino.rb +1 -1
  114. data/sig/kino.rbs +93 -10
  115. metadata +66 -3
  116. data/ext/kino/src/queue.rs +0 -333
  117. data/ext/kino/src/server.rs +0 -1785
data/doc/benchmarks.md CHANGED
@@ -13,43 +13,69 @@ the deployment most apps run today.
13
13
 
14
14
  ## Methodology
15
15
 
16
- - Primary hardware: AWS **c7a.2xlarge**—8 dedicated cores of AMD EPYC
17
- 9R14 (Genoa), 16 GB RAM, Amazon Linux 2023, kernel 6.18. A realistic
16
+ Every table in the README, and every figure here that is not marked
17
+ with an older date, comes from one **2026-11 re-measurement**:
18
+
19
+ - Hardware: AWS **c8a.2xlarge**—8 cores of AMD EPYC 9R45 (one thread
20
+ per core), 16 GB RAM, Amazon Linux 2023, kernel 6.18. A realistic
18
21
  app-server size, deliberately: nobody provisions a 32-core box per
19
22
  app process.
20
- - Toolchain built on the box via mise: Ruby 4.0.6 (**YJIT enabled**,
21
- `RUBY_YJIT_ENABLE=1` for every server), Rust stable, Kino compiled in
22
- the release profile.
23
- - **2026-09 full re-measurement** (a fresh c7a.2xlarge): every number in
24
- this document and the README was re-run on Ruby 4.0.6 / kernel 6.18 /
25
- Puma 8.0.2, adding the sharded-I/O and HTTP/2 studies. Kino's numbers
26
- reproduced within 1-3% across the board—including the /io slot
27
- ceiling and the arena balloon, both intact. The one real shift: Puma
28
- 8.0.2 is faster than 7.x (142k plaintext, 61k /cpu), narrowing
29
- ractor mode's /cpu lead to +25% (was +34%). Reversed-boot-order
30
- re-runs reproduced within ~1%. A methodology trap worth recording:
31
- a 5-second single-endpoint warmup understates memory badly (81 MB
32
- where the full battery shows 137 MB) and hides the arena balloon
33
- entirely—memory is only comparable after the full endpoint battery,
34
- and /io numbers are only comparable at equal slot counts.
35
- - Load generator: wrk 4.2 on the same host, 8-second windows, 64
36
- connections (`bench/run.sh 8 64`). Same-host load generation costs
37
- both sides CPU equally; we verified the generator was not the
38
- bottleneck by A/B-ing against single-threaded ab, which capped Kino's
39
- plaintext 26-37% lower while leaving Puma's number unchanged.
23
+ - Ruby: **4.0.9** (the released Ruby, and the primary number
24
+ everywhere), and a development build of **Ruby 4.1** (`4.1.0dev`,
25
+ master f2d62c677e of 2026-11-21), whose figures are kept apart in
26
+ [their own section](#ruby-41-development-build). **YJIT enabled**
27
+ (`RUBY_YJIT_ENABLE=1`) for every server. Kino is compiled in the
28
+ release profile against each Ruby.
29
+ - Versions: Kino 0.7.2 plus the unreleased changes in the changelog,
30
+ Puma 8.0.2, Falcon 0.57.0, rack 3.2.7, wrk 4.2.0, h2load from nghttp2
31
+ 1.59.0, nginx 1.30.7. The Ruby 4.0.9 runs used a Kino build one
32
+ revision behind the Ruby 4.1 runs; the two differ in how the build
33
+ detects Ruby 4.1 and in comments, not in the request path.
40
34
  - Identical app for every server (`bench/bench_app.rb`), Ractor-shareable
41
35
  so Kino's `:ractor` mode can run it unmodified.
42
- - Topology: each server at its shipped defaults—Puma 8 forked workers
43
- × 3 threads (24 slots) vs Kino 8 workers in one process (× 1 thread
44
- in ractor modes, the default since 0.1.1; × 3 threads in threaded
45
- mode). Equal-topology numbers (Kino at 8×3) are in the studies below.
46
- - The headline tables also carry an io-tuned column (`workers 32,
47
- threads 1`)—not a default, labeled as such—because the /io rows are
48
- a slot-count story (see below).
49
- - The dataset spans four identical c7a.2xlarge boxes: the original
50
- measurements, a re-measure at the 0.1.1 defaults, the headline sweep,
51
- and a final full re-validation (every table re-run from scratch).
52
- Equal-config throughput reproduced across boxes within ~1-2%.
36
+ - Topology: **every server at 8 workers**. Puma forks 8 workers × 3
37
+ threads (24 slots); Kino runs 8 workers in one process (× 1 thread in
38
+ ractor modes, the default since 0.1.1; × 3 threads in threaded mode).
39
+ The main table also carries an io-tuned column (`workers 32, threads
40
+ 1`)—not a default, labeled as such—because the /io rows are a
41
+ slot-count story (see below).
42
+ - Load generator: wrk on the same host, 8 threads, 64 connections,
43
+ 8-second windows (`wrk -d 8s -c 64 -t 8`), with a 2-second pause
44
+ between endpoints. **No CPU pinning**: the server and wrk share all 8
45
+ cores, and wrk took about 1.4 of them at 410k req/s.
46
+ - **Three boots, medians.** A pass boots each server once, runs its
47
+ endpoints in a fixed order (/plaintext, /10k, /cpu, /io, /io_native)
48
+ and stops it; the next server starts only when the port is free.
49
+ Three passes run, with the server order rotated by one place each
50
+ time, and every figure is the median of the three. No run reported
51
+ here had a non-2xx response or a socket error.
52
+ - The commands, on the 8-core box:
53
+
54
+ ```sh
55
+ # the main table
56
+ bundle exec ruby bench/kino_server.rb ractor 9293 8 1 # Kino :ractor
57
+ bundle exec ruby bench/kino_server.rb ractor-lanes 9293 8 1 # + lanes
58
+ bundle exec ruby bench/kino_server.rb ractor 9293 32 1 # workers 32
59
+ bundle exec ruby bench/kino_server.rb threaded 9293 8 3 # Kino :threaded
60
+ bundle exec puma -q -w 8 -t 3:3 -p 9293 bench/config.ru # Puma cluster
61
+ wrk -d 8s -c 64 -t 8 http://127.0.0.1:9293/plaintext # and the other endpoints
62
+
63
+ # the ractor-wrapper table
64
+ bundle exec ruby bench/kino_server.rb ractor 9293 8 3
65
+ RACTOR_POOL=8 bundle exec puma -q -t 10:10 -p 9293 bench/wrapped.ru
66
+ RACTOR_POOL=1 bundle exec falcon serve --bind http://127.0.0.1:9293 --count 8 --config bench/wrapped.ru
67
+
68
+ # the memory table's threaded row
69
+ MALLOC_ARENA_MAX=2 bundle exec ruby bench/kino_server.rb threaded 9293 8 3
70
+
71
+ # HTTP/2: 5 s per lane, 8 connections x 8 streams
72
+ bench/h2.sh 5 8 8
73
+ ```
74
+
75
+ `bench/run.sh 8 64` runs the same endpoints and servers in one go,
76
+ but boots every Kino variant at 3 threads; the main table's Kino
77
+ columns are the commands above. The Rails commands are in
78
+ [Rails](#rails).
53
79
  - **Memory is reported as PSS (proportional set size), not RSS.** A Puma
54
80
  cluster forks N workers that share the Ruby VM and gem code
55
81
  copy-on-write; summing each worker's RSS counts those shared pages up
@@ -57,17 +83,28 @@ the deployment most apps run today.
57
83
  every shared page across the processes mapping it, so it reflects the
58
84
  unique physical memory the cluster occupies—the only fair basis for
59
85
  comparing one process against a fork-per-core cluster. We read it from
60
- `/proc/<pid>/smaps_rollup` over the whole process tree, cross-checked
61
- against `ps` (RSS) and `smem` (PSS). Kino serves from one process, so
62
- its RSS ≈ PSS; the correction only moves Puma. (`bench/studies.sh`
63
- reports both columns.)
64
- - Follow-up studies (`bench/studies.sh`): CPU tuning, topology sweep,
65
- /io worker scaling, logging costs, and memory—run in the same session
66
- as the headline tables.
86
+ `/proc/<pid>/smaps_rollup`, summed over the whole process tree, with
87
+ RSS from `ps` beside it. Kino serves from one process, so its
88
+ RSS ≈ PSS; the correction only moves Puma.
89
+ - Memory is sampled after the endpoint battery (/plaintext, /10k, /cpu,
90
+ /io, 8 s each), on boots of its own for the memory table. A
91
+ methodology trap worth recording: a single-endpoint warmup understates
92
+ memory badly (ractor mode reads 100 MB after /plaintext alone and
93
+ 158 MB after the battery)—memory is only comparable after the full
94
+ battery, and /io numbers are only comparable at equal slot counts.
67
95
  - The harness waits for the port to be genuinely free between targets.
68
96
  This matters: falcon binds with `SO_REUSEPORT`, so a leftover instance
69
97
  silently splits traffic with the next server and poisons every number
70
98
  after it (we learned this the hard way).
99
+ - **Older figures.** The 2026-09 tables (a c7a.2xlarge, Ruby 4.0.6) are
100
+ replaced. Absolute numbers are now about twice those for every server,
101
+ Puma included (291,409 against 142,094 on /plaintext): the instance
102
+ type, the Ruby and Kino all changed, so compare columns within one
103
+ run, never across dates. A few studies were not re-run in 2026-11 and
104
+ keep their earlier figures, each marked where it stands: the
105
+ `tokio_threads` half of the CPU recipe, the per-core execution probe,
106
+ the topology sweep, sharded I/O, logging costs, header interning, the
107
+ allocator shoot-out and the macOS table.
71
108
  - Secondary data point: macOS (MacBook Pro, M1 10-core), where every
72
109
  server converges near the loopback ceiling (~42-49k plaintext) and
73
110
  differences compress; its table is at the end of this document.
@@ -78,54 +115,63 @@ the deployment most apps run today.
78
115
  ## Reading the headline tables
79
116
 
80
117
  These tables all run the **tiny synthetic Ractor-shareable app**. The real
81
- Rails app is not Ractor-shareable and runs only in threaded fallback—a
82
- separate story with separate numbers, in [its own section](#rails).
83
-
84
- - **Plaintext/10k**: Kino's tokio front-end clears the fork cluster by
85
- 1.5-2.1× (lanes plaintext 250,222 vs Puma 118,176 = 2.12×; the
86
- smallest margin is threaded /10k at 1.50×). At the old 3-thread
87
- topology the cross-ractor handoff showed up as ractor trailing
88
- threaded on trivial handlers; the 1-thread default reverses that
89
- (ractor 230k vs threaded 217k) and lanes widen it (250k).
118
+ Rails app's numbers were measured in threaded mode, before Rails could
119
+ run on Ractors—a separate story, in [its own section](#rails).
120
+
121
+ - **Plaintext/10k**: ractor mode clears the fork cluster by 1.5-1.6×
122
+ (465,055 vs Puma's 291,409 on /plaintext = 1.60×; 375,470 vs 251,357
123
+ on /10k = 1.49×), and lanes by 1.6-1.8× (525,155 = 1.80×; 409,085 =
124
+ 1.63×). Threaded mode is ahead by less: 1.35× on /plaintext, 1.13×
125
+ on /10k. Ractor mode leads threaded on these trivial handlers
126
+ (465k vs 394k), and lanes widen it (525k).
90
127
  - **CPU (recursive fib)**: ractor mode does **5.8× its own GVL-bound
91
- threaded mode** (77,999 vs 13,429)—that's the entire point of
92
- ractors—and beats the fork cluster outright: +34% with stock
93
- defaults (+22% with lanes, 70,885 vs 58,006). Even the io-tuned
94
- `workers 32` topology stays ahead of the cluster on CPU (66,100).
128
+ threaded mode** (118,095 vs 20,187)—that's the entire point of
129
+ ractors—and beats the fork cluster: +14% with stock defaults (+8%
130
+ with lanes, 111,751 vs 103,653). The io-tuned `workers 32` topology
131
+ does not, on Ruby 4.0.9: 83,713, 19% behind the cluster.
95
132
  - **Memory (PSS)**: after the full endpoint battery, the tiny app costs
96
- Kino **148 MB** in ractor mode (107 MB threaded) against the 8-worker
97
- cluster's **1,068 MB**—~7-10× lighter, because a trivial app is almost
98
- all private per-worker heap that copy-on-write can't share. The real
99
- Rails app narrows this to ~4× (its framework *is* shared CoW); both are
100
- in [Memory under load](#memory-under-load-and-the-glibc-arena-footgun).
101
- - **I/O (5 ms wait)**: all dispatch models tie within ~4% at equal slot
102
- counts, so the default columns show the ractor modes behind on /io
103
- (8 slots vs the cluster's 24), and the `workers 32` column shows the
104
- same engine winning (+25%, +34% via `Kino.sleep`) once it has more
105
- slots than the cluster. The lever is slot count, and Kino slots are
106
- cheap: see [below](#why-io-lags-in-ractor-mode-on-linux).
133
+ Kino **167 MB** in ractor mode (110 MB threaded, arena-capped)
134
+ against the 8-worker cluster's **1,171 MB**—~7-11× lighter, because
135
+ a trivial app is almost all private per-worker heap that
136
+ copy-on-write can't share. The Rails hello app comes to ~6.7×; both
137
+ are in [Memory under load](#memory-under-load-and-the-glibc-arena-footgun).
138
+ - **I/O (5 ms wait)**: the dispatch models tie within ~2-3% at equal slot
139
+ counts (24 slots: threaded 4,738, Puma 4,729, ractor 8×3 4,629), so
140
+ the default columns show the ractor modes behind on /io (8 slots vs
141
+ the cluster's 24), and the `workers 32` column shows the same engine
142
+ winning (+21%, +32% via `Kino.sleep`) once it has more slots than the
143
+ cluster. The lever is slot count, and Kino slots are cheap: see
144
+ [below](#why-io-lags-in-ractor-mode-on-linux).
145
+ - **Spread between boots**: most cells' three boots sit within 4% of
146
+ each other. The exceptions on Ruby 4.0.9 are `workers 32` on the
147
+ light rows (/plaintext 238,040-290,583, /10k 202,415-241,150, one
148
+ boot of three well above the other two) and /cpu in the ractor
149
+ columns (117,391-125,831 at the default, 105,994-113,008 with
150
+ lanes).
107
151
 
108
152
  ## CPU-bound tuning
109
153
 
110
154
  On real hardware, Kino's stock defaults lead the cluster on pure
111
- CPU—and the old tuning recipe is now obsolete. Same-session studies
112
- run:
155
+ CPU—and the old tuning recipe is obsolete:
113
156
 
114
157
  | config | /cpu req/s |
115
158
  |---|---:|
116
- | Puma cluster (reference) | 58,189 |
117
- | Kino `workers 8, threads 3` (the default before 0.1.1) | 67,394 |
118
- | Kino `workers 8, threads 1, tokio_threads 1` (the old recipe) | 68,600 |
119
- | Kino `workers 8, threads 1`, tokio auto (**the default**) | **77,999** |
120
-
121
- The `threads 1` half of the old recipe became the default; the
122
- `tokio_threads 1` half now *costs* −12% on /cpu (and still costs
123
- plaintext: 108,523 vs 230k). Don't pin tokio threads. **The recipe's
124
- history is an environment story**: in the earlier Docker-on-Mac runs it
125
- was worth +12%, because tokio threads and wake churn competed for
126
- oversubscribed virtualized cores; on dedicated cores the same pin
127
- starves the I/O front-end instead. If you deploy into a
128
- constrained/virtualized environment, measure there.
159
+ | Puma cluster (reference) | 103,653 |
160
+ | Kino `workers 8, threads 3` (the default before 0.1.1) | 108,063 |
161
+ | Kino `workers 8, threads 1`, tokio auto (**the default**) | **118,095** |
162
+
163
+ (The 8×3 row is from the ractor-wrapper run, the other two from the
164
+ main table's: the same box and build, separate runs.)
165
+
166
+ The `threads 1` half of the old recipe became the default. Its
167
+ `tokio_threads 1` half was last measured in 2026-09 (c7a.2xlarge, Ruby
168
+ 4.0.6) and not re-run since: there it *cost* −12% on /cpu (68,600 vs
169
+ 77,999 at the default) and more on plaintext (108,523 vs 230k). Don't
170
+ pin tokio threads. **The recipe's history is an environment story**: in
171
+ the earlier Docker-on-Mac runs it was worth +12%, because tokio threads
172
+ and wake churn competed for oversubscribed virtualized cores; on
173
+ dedicated cores the same pin starves the I/O front-end instead. If you
174
+ deploy into a constrained/virtualized environment, measure there.
129
175
 
130
176
  Two findings that survived the environment change:
131
177
 
@@ -133,19 +179,20 @@ Two findings that survived the environment change:
133
179
  briefly believed parallel ractors paid a ~24% execution tax; that probe
134
180
  compared 8 busy ractors against a *single* busy thread, which also
135
181
  compares all-core clocks against single-core boost. The controlled probe
136
- (8 forked processes vs 8 ractors, same all-core clock): forks 8,973
137
- fib/s/core, ractors 8,918—identical. `GC.disable` changes nothing (fib
138
- barely allocates). The VM is innocent. Never compare parallel against
139
- single-threaded baselines without controlling for clocks.
140
-
141
- **The GVL ceiling is absolute.** Threaded mode posts the same ~13k /cpu
142
- whatever the topology—24 threads in one process serialize on one lock.
182
+ (8 forked processes vs 8 ractors, same all-core clock, on the earlier
183
+ c7a.2xlarge box): forks 8,973 fib/s/core, ractors 8,918—identical.
184
+ `GC.disable` changes nothing (fib barely allocates). The VM is
185
+ innocent. Never compare parallel against single-threaded baselines
186
+ without controlling for clocks.
187
+
188
+ **The GVL ceiling is absolute.** Threaded mode posts ~20k /cpu (20,187
189
+ at 8×3)—24 threads in one process serialize on one lock.
143
190
  Parallelism for CPU-bound Ruby comes from ractors or forks, nothing else.
144
191
 
145
192
  ## Why /io lags in ractor mode on Linux
146
193
 
147
- On bare metal the gap is small at equal slot counts: ractor /io 4,530
148
- vs threaded 4,709 (−4%, both at 8×3). In Docker it was −18%, and a
194
+ On bare metal the gap is small at equal slot counts: ractor /io 4,629
195
+ vs threaded 4,738 (−2%, both at 8×3). In Docker it was −18%, and a
149
196
  pure-Ruby probe there measured
150
197
  `sleep(0.005)` waking +2.3-2.8 ms late inside ractors vs +1.8 ms on the
151
198
  main ractor—non-main-ractor timer wakeups are coarser in Ruby 4.0, but
@@ -155,20 +202,24 @@ A follow-up probe showed `IO.select`-style waits are tighter than
155
202
 
156
203
  **Mitigation 1—`Kino.sleep`:** releases the GVL and waits on the OS
157
204
  clock directly (chunked, so `Thread#kill`/shutdown stay responsive). The
158
- `/io_native` endpoint (same 5 ms wait via `Kino.sleep` when available)
159
- erases the remaining ractor gap on this box: 4,721 vs 4,530 plain sleep.
205
+ `/io_native` endpoint is the same 5 ms wait via `Kino.sleep` when
206
+ available. On this box it is worth +2% at the 8×1 default (1,578 vs
207
+ 1,553 with plain sleep) and +9% at `workers 32` (6,264 vs 5,721).
160
208
 
161
209
  **Mitigation 2—add workers; they're nearly free.** The headline tables
162
- show default ractor-mode /io at 1,552: that's 8 slots (the 1-thread
210
+ show default ractor-mode /io at 1,553: that's 8 slots (the 1-thread
163
211
  default) against the cluster's 24, because wait-bound throughput is
164
212
  simply `slots ÷ effective wait`. Kino's slots cost ~a thread each, not
165
- a forked process: the `workers 32, threads 1` column measured **5,888
166
- /io (+25% over the 24-thread cluster's 4,693) and 6,274 /io_native
167
- (+34%)**, still one small process, and still +14% ahead of the cluster
168
- on pure CPU. Its cost is the CPU-light rows (183k plaintext vs 230k at
169
- 8×1: 32 ractors oversubscribe 8 cores). A fork cluster buying the same
170
- 32 slots pays for them in full copies of the app; Kino pays in
171
- scheduler churn only where the cores are already saturated.
213
+ a forked process: the `workers 32, threads 1` column measured **5,721
214
+ /io (+21% over the 24-thread cluster's 4,729) and 6,264 /io_native
215
+ (+32%)**, still one small process (79 MB PSS after the battery). On
216
+ Ruby 4.0.9 it pays on the other rows: 245,612 plaintext against 465,055
217
+ at 8×1, and 83,713 /cpu against 118,095, which puts it 16-19% behind
218
+ the cluster on /plaintext, /10k and /cpu. On the Ruby 4.1 development
219
+ build most of that cost is gone (463,223 plaintext against 512,945 at
220
+ 8×1, /cpu level with 8×1, and ahead of the cluster on every row); see
221
+ [Ruby 4.1](#ruby-41-development-build). A fork cluster buying the same
222
+ 32 slots pays for them in full copies of the app.
172
223
 
173
224
  ## The ractor-pool-wrapper comparison
174
225
 
@@ -176,13 +227,13 @@ A reasonable first experiment for anyone curious about ractors is a Rack
176
227
  wrapper that ships each request to a ractor pool on whatever server they
177
228
  already run. `bench/ractor_wrapper.rb` is that experiment, benchmarked on
178
229
  Puma and Falcon—not as a comparison of those servers, but to measure
179
- what the Rack-level hop itself costs (c7a.2xlarge, same session):
230
+ what the Rack-level hop itself costs (same box, Ruby 4.0.9):
180
231
 
181
232
  | endpoint | Kino :ractor (8×3) | Puma + wrapper | Falcon + wrapper |
182
233
  |------------|-------------------:|---------------:|-----------------:|
183
- | /plaintext | 193,826 | 19,480 | 99,776 |
184
- | /cpu (fib) | 68,061 | 17,755 | 48,721 |
185
- | /io (5 ms) | 4,530 | 1,454 | 1,549 |
234
+ | /plaintext | 412,687 | 40,675 | 241,390 |
235
+ | /cpu (fib) | 108,063 | 33,322 | 94,417 |
236
+ | /io (5 ms) | 4,629 | 1,509 | 1,564 |
186
237
 
187
238
  Inside the Rack contract, the wrapper must reduce the env to a shareable
188
239
  subset, copy it to the worker ractor, copy the response back, and hold a
@@ -197,29 +248,54 @@ the Rack contract—which is the experiment this gem exists to run.
197
248
 
198
249
  ## Rails
199
250
 
200
- Rails is **not Ractor-shareable**, so Kino can only serve it in
201
- `:threaded` fallback—this whole section is one GVL-bound Kino process,
202
- never ractor mode. The example app (`examples/rails-hello`, edge Rails,
203
- production mode, 8 workers × 5 threads) on the same box:
251
+ These are `:threaded` measurements from before Rails could run on
252
+ Ractors, so this whole section is one GVL-bound Kino process; ractor-mode
253
+ Rails is not benchmarked yet. The app is the controller-only Rails hello
254
+ app, kept as the bench subject in `bench/rails_hello.ru` (edge Rails,
255
+ production mode, 8 workers × 5 threads), on the same box, Ruby 4.0.9:
204
256
 
205
257
  | | req/s | RSS | PSS |
206
258
  |---|---:|---:|---:|
207
- | Kino `:threaded` (one process) | 2,637 | 97 MB | **92 MB** |
208
- | Puma cluster (8 workers) | 12,138 | 794 MB | **389 MB** |
259
+ | Kino `:threaded` (one process) | 7,660 | 102 MB | **96 MB** |
260
+ | Puma cluster (8 workers, preload) | 34,688 | 971 MB | **640 MB** |
261
+ | Puma cluster (8 workers, no preload) | 35,048 | 963 MB | **784 MB** |
209
262
 
210
263
  This is the honest version of the Rails story. In threaded mode Kino is
211
- one GVL-bound process, so the fork cluster outruns it ~4.6× by using all
212
- 8 cores—at ~4× the memory by PSS. The metric matters here: Puma's RSS
213
- (794 MB) counts the shared Rails framework once per worker; PSS (389 MB)
214
- counts it once, and that is the fair figure (the README's headline used
215
- to read 8× off RSS). Preloading barely moves it—389 MB with
216
- `preload_app!` vs 400 MB without—because Ruby's GC dirties most heap
217
- pages, breaking copy-on-write, so even a preloaded cluster keeps a
218
- private heap per worker. Rails-on-Ractors is interesting precisely
219
- because it would close the throughput gap at the one-process memory
220
- cost; the upstream blockers are documented in
264
+ one GVL-bound process, so the fork cluster outruns it ~4.5× by using all
265
+ 8 cores—at ~6.7× the memory by PSS. The metric matters here: Puma's RSS
266
+ (971 MB) counts the shared Rails framework once per worker; PSS (640 MB)
267
+ counts it once, and that is the fair figure. Preloading saves 144 MB
268
+ (640 MB with `preload_app!`, 784 MB without) at the same throughput
269
+ (the boots' ranges overlap); the rest stays private, as the
270
+ [memory section](#rails-threaded-fallback) shows. Rails-on-Ractors is
271
+ interesting precisely because it could close the throughput gap at the
272
+ one-process memory cost; what runs today is documented in
221
273
  [rails-on-ractors.md](rails-on-ractors.md).
222
274
 
275
+ How it was run, from `examples/rails-hello` (its bundle), with
276
+ `RAILS_ENV=production RACK_ENV=production WORKERS=8`: Kino through
277
+ `Kino::Server.run` on `bench/rails_hello.ru` with `workers: 8, threads:
278
+ 5, mode: :threaded`; Puma as `puma -q -w 8 -t 5:5 --preload
279
+ bench/rails_hello.ru`, and with `-C bench/puma_no_preload.rb` in place
280
+ of `--preload`. wrk as above on `/` for 8 seconds, then RSS and PSS;
281
+ three rotated boots, medians. `bench/rails_mem.sh`, which loads with
282
+ `ab` for 5 seconds instead, reads the same memory: 99 MB for Kino and
283
+ 646 MB for the preloaded cluster.
284
+
285
+ Two things to know before comparing or reproducing:
286
+
287
+ - **The bundle moved since 2026-09**, so these figures are not
288
+ like-for-like with the earlier ones (2,731 and 15,422 req/s, 95 MB
289
+ and 405 MB PSS). The hello app now bundles edge Rails at ff00282
290
+ (8.2.0.alpha), rack from its main branch, and an i18n fork with
291
+ Ractor support.
292
+ - **Ruby 4.1 needs a re-resolved lockfile.** The lockfile in the repo
293
+ does not install on the Ruby 4.1 development build as it is; a
294
+ re-resolved one adds source gems for sqlite3, nokogiri and herb (and
295
+ mini_portile2 to build them), with no version changes. The Ruby 4.1
296
+ Rails figures [below](#ruby-41-development-build) were measured with
297
+ that lockfile, the 4.0.9 ones with the repo's.
298
+
223
299
  ## YJIT × Ractors gotcha (found the hard way)
224
300
 
225
301
  Plain `def` methods get the full YJIT speedup inside worker ractors
@@ -251,43 +327,61 @@ more reason to prefer mimalloc in dlopen'd extensions.
251
327
 
252
328
  ## Memory under load (and the glibc arena footgun)
253
329
 
254
- All figures are **PSS** (see [Methodology](#methodology)) after the full
255
- endpoint battery (8 s each of /plaintext, /10k, /cpu, /io—a "warmed
256
- production process", not a fresh boot, which measures ~26 MB for every
257
- Kino mode). RSS is shown alongside so the copy-on-write correction is
258
- visible.
330
+ All figures are **PSS** in MB (see [Methodology](#methodology)) after
331
+ the full endpoint battery (8 s each of /plaintext, /10k, /cpu, /io—a
332
+ "warmed production process", not a fresh boot). RSS is shown alongside
333
+ so the copy-on-write correction is visible. Ruby 4.0.9; the Ruby 4.1
334
+ figures are [further down](#ruby-41-development-build).
259
335
 
260
336
  ### The tiny synthetic app
261
337
 
262
338
  | config | RSS | PSS |
263
339
  |---|---:|---:|
264
- | Kino :ractor 8×1 (default) | 137 | **135** |
265
- | Kino lanes 8×1 | 128 | **126** |
266
- | Kino :ractor 8×3 | 170 | **168** |
267
- | Kino :threaded 8×3 (`MALLOC_ARENA_MAX=2`) | 109 | **107** |
268
- | Kino :threaded 8×3 (no arena cap) | 672 | **670**¹ |
269
- | Puma cluster 8×3 | 1,216 | **1,072** |
270
-
271
- (2026-09 re-measure; the 2026-06 numbers reproduced within a few MB on
272
- every row—the arena-capped threaded row to the megabyte.)
273
-
274
- The tiny app is ~8× lighter than the cluster in ractor mode, ~10× in
340
+ | Kino :ractor 8×1 (default) | 170 | **167** |
341
+ | Kino lanes 8×1² | 171 | **169** |
342
+ | Kino :ractor 32×1² | 81 | **79** |
343
+ | Kino :threaded 8×3 (`MALLOC_ARENA_MAX=2`) | 113 | **110** |
344
+ | Kino :threaded 8×3 (no arena cap) | 147 | **144**¹ |
345
+ | Puma cluster 8×3 | 1,324 | **1,171** |
346
+
347
+ The tiny app is ~7× lighter than the cluster in ractor mode, ~11× in
275
348
  arena-capped threaded mode. RSS ≈ PSS for every Kino row (one process,
276
- nothing to share) and within ~12% for Puma here: a trivial app has almost
277
- no shared state, so Puma's footprint is ~1,051 MB of *private* per-worker
278
- heap plus only ~18 MB shared (which RSS counts 8×). This is the case where
279
- copy-on-write does **not** rescue the cluster—there is nothing to
280
- share—so the RSS and PSS numbers nearly agree. (The old "80 MB / 15×"
281
- figure was a lighter, plaintext-only load; the honest full-battery ractor
282
- figure is ~148 MB, i.e. ~7×.)
283
-
284
- ¹ Not a leak: glibc malloc arena bloat. One 8-second /10k round takes
285
- threaded mode from ~70 MB to ~670 MB and it never returns—24 threads
286
- churning 10 KB strings through one process heap is the textbook glibc
287
- arena-fragmentation case (the reason Rails ops set `MALLOC_ARENA_MAX=2`;
288
- Heroku ships that default). With the cap the same battery ends at 107 MB
289
- PSS, throughput unchanged. Ractor mode sidesteps the worst of it without
290
- any env tweak—objects live in per-ractor heaps.
349
+ nothing to share) and within ~13% for Puma here: a trivial app has
350
+ almost no shared state. This is the case where copy-on-write does
351
+ **not** rescue the cluster—there is little to share—so the RSS and PSS
352
+ numbers nearly agree.
353
+
354
+ ¹ **The arena balloon is gone.** Through 2026-09 this row was the
355
+ textbook glibc arena-fragmentation case (the reason Rails ops set
356
+ `MALLOC_ARENA_MAX=2`; Heroku ships that default): one 8-second /10k
357
+ round took uncapped threaded mode from ~70 MB to ~670 MB and it never
358
+ returned. A 2026-11 A/B on this box, three boots per arm, shows where
359
+ it went:
360
+
361
+ | :threaded 8×3, no arena cap, PSS after | /plaintext | /10k | /cpu | /io | of which glibc arenas |
362
+ |---|---:|---:|---:|---:|---:|
363
+ | Kino's main branch before these changes | 86 | 737 | 724 | **724** | 645 |
364
+ | Kino now | 86 | 171 | 147 | **144** | 75 |
365
+
366
+ The older tree still balloons on /10k (566-738 MB across its boots);
367
+ the current one does not (142-158 MB). What changed between the two is
368
+ that a threaded worker now lets the threads waiting for the GVL run
369
+ between two requests once it has held it for a millisecond (see the
370
+ changelog). A second A/B isolates it: the same current build with only
371
+ that pass switched off balloons again (761 MB [732-763] after /io,
372
+ 673 MB of it in glibc arenas), and with the pass on it ends at 155 MB
373
+ [148-165]. The likely reading, not tested further: without the pass a
374
+ worker holds the GVL for Ruby's whole 100 ms slices and grows its own
375
+ malloc arena by about one GC cycle's garbage, which glibc keeps; with
376
+ it, the same garbage spreads thinly over every thread. The cap still helps: with `MALLOC_ARENA_MAX=2` the same
377
+ run ends at 112 MB, about 30 MB less, and the older tree at 134 MB.
378
+ Throughput with the cap moves a few percent either way (/10k 285,724
379
+ vs 270,283, /cpu 18,402 vs 19,842). Ractor mode reads the same on both
380
+ trees (158 and 156 MB).
381
+
382
+ ² Sampled in the main table's passes rather than the memory table's:
383
+ the same battery and sampling point, other boots. Those passes read 164
384
+ MB for the default ractor row and 1,137 MB for Puma.
291
385
 
292
386
  ### Rails (threaded fallback)
293
387
 
@@ -295,22 +389,26 @@ Here copy-on-write **does** matter, which is exactly why PSS is mandatory:
295
389
 
296
390
  | config | RSS | PSS |
297
391
  |---|---:|---:|
298
- | Kino :threaded (one process) | 97 | **95** |
299
- | Puma cluster 8×5 (preload) | 813 | **405** |
300
- | Puma cluster 8×5 (no preload) | 824 | **646** |
392
+ | Kino :threaded (one process) | 102 | **96** |
393
+ | Puma cluster 8×5 (preload) | 971 | **640** |
394
+ | Puma cluster 8×5 (no preload) | 963 | **784** |
301
395
 
302
396
  Puma serves the same Rails framework from 8 forks that share it
303
- copy-on-write; RSS counts that shared framework once per worker (813 MB),
304
- PSS counts it once (405 MB). The fair ratio is **~4×**, not the ~8× a
305
- naive RSS sum reports—this is the correction that prompted the whole
306
- re-measure. The 2026-09 run also split out preload: it now saves a
307
- third (405 vs 646 MB PSS)—worth turning on—but even preloaded, Ruby's
308
- GC dirties heap pages and breaks copy-on-write, so each worker keeps a
309
- large private heap. That is why "CoW should make a fork cluster nearly
310
- free" is only half true—it shares the code, not the live object heap.
397
+ copy-on-write; RSS counts that shared framework once per worker (971 MB),
398
+ PSS counts it once (640 MB). The fair ratio is **~6.7×**, not the ~9.5×
399
+ a naive RSS sum reports. Preload saves 144 MB of PSS (640 vs 784
400
+ MB)—worth turning on—but it shares the code, not the live object heap:
401
+ of the preloaded cluster's pages about 370 MB are shared and about
402
+ 600 MB are private to one worker or another (it boots at about 124 MB
403
+ PSS and grows under load). That is why "CoW should make a fork cluster
404
+ nearly free" is only half true.
311
405
 
312
406
  ## Run-to-run variance (a.k.a. "is this a regression?")
313
407
 
408
+ The 2026-11 tables answer this with three rotated boots per server and
409
+ medians (see [Methodology](#methodology)); what follows is the
410
+ experience behind that, from the 2026-06 and 2026-09 c7a.2xlarge runs.
411
+
314
412
  Rule of thumb from chasing this twice: never compare numbers from
315
413
  different sessions; interleave A/B rounds in one session instead. The
316
414
  Docker-on-Mac environment swung ±10% on /cpu between sessions with the
@@ -327,7 +425,8 @@ back at 217k). Suspect cells get re-measured, not published.
327
425
 
328
426
  ## Topology notes
329
427
 
330
- Measured on c7a.2xlarge, plaintext, ractor mode, same session (three
428
+ Measured in 2026-09 on c7a.2xlarge (Ruby 4.0.6; the sweep was not
429
+ re-run in 2026-11), plaintext, ractor mode, same session (three
331
430
  interleaved rounds, medians): `8×3` (workers×threads) = 198,478, `8×1`
332
431
  = **229,966 (+16%)**, `16×1` = 214,391. Threads inside one ractor share
333
432
  its lock, so every request handled by a 3-thread ractor pays a lock
@@ -340,7 +439,10 @@ the same way: 77,999 vs 67,394). The trade-off is /io at low worker
340
439
  counts: 1,552 at 8×1 vs 4,530 at 8×3—threads-per-ractor exist for
341
440
  handlers that block on I/O. If yours wait a lot, raise `workers`
342
441
  instead (32×1 beats even the 24-slot cluster, see above); slots are
343
- cheap. (16×1 being worse than 8×1 on plaintext also says the shared
442
+ cheap. The 2026-11 figures for the two ends, from separate runs on the
443
+ c8a.2xlarge (Ruby 4.0.9), keep the shape: plaintext 412,687 at 8×3 and
444
+ 465,055 at 8×1 (+13%), /cpu 108,063 and 118,095 (+9%), /io 4,629 and
445
+ 1,553. (16×1 being worse than 8×1 on plaintext also says the shared
344
446
  MPMC queue is *not* the bottleneck—8 extra parked consumers just add
345
447
  scheduler churn.)
346
448
 
@@ -365,27 +467,29 @@ depth, which is also why it's a config knob and not a hardcoded win).
365
467
  The shared-queue design pays a futex wake per request at saturation
366
468
  (every worker parks on an empty queue between requests). Lane mode gives
367
469
  each worker a small private queue; the dispatcher prefers *awake* lanes—so
368
- a hot worker keeps taking without ever being woken—with two
369
- safeguards: lane depth is capped at 4, and workers steal from siblings
370
- before parking (plus on every park tick), so a slow request can't strand
371
- its lane's backlog.
470
+ a hot worker keeps taking without ever being woken (the rules are in
471
+ [architecture](architecture.md#lane-dispatch)).
372
472
 
373
- Same-session A/B on c7a.2xlarge, ractor mode at the default topology
374
- (8×1):
473
+ The main table's two ractor columns are the A/B: ractor mode at the
474
+ default topology (8×1), the same passes on the c8a.2xlarge, Ruby 4.0.9:
375
475
 
376
476
  | endpoint | shared queue | lanes | delta |
377
477
  |----------|-------------:|------:|------:|
378
- | /plaintext | 229,534 | **250,222** | **+9%** |
379
- | /10k | 178,083 | 189,862 | +7% |
380
- | /cpu | **77,999** | 70,885 | −9% |
381
- | /io | 1,552 | 1,551 | flat |
478
+ | /plaintext | 465,055 | **525,155** | **+13%** |
479
+ | /10k | 375,470 | **409,085** | +9% |
480
+ | /cpu | **118,095** | 111,751 | −5% |
481
+ | /io | 1,553 | 1,566 | flat |
382
482
 
383
- Lanes' margin shrank with the move to 1-thread workers (at the old 8×3
384
- it was +21% plaintext: 240,193 vs 199,032 in the same session)—most of
483
+ On the Ruby 4.1 development build the same A/B reads +19% on
484
+ /plaintext (608,283 vs 512,945), +15% on /10k (515,785 vs 447,144) and
485
+ −12% on /cpu (112,276 vs 128,097).
486
+
487
+ At the old 8×3 topology the margin was wider (+21% plaintext, 240,193
488
+ vs 199,032, in an earlier same-session A/B on a c7a.2xlarge)—much of
385
489
  the futex pain lanes were built to avoid came from thread handoffs
386
- inside each ractor, and the new default removes those for everyone. At
387
- the default, lanes still post the fastest plaintext/10k of any Kino
388
- configuration, but plain shared-queue now takes /cpu. It stays opt-in because overload semantics differ from the
490
+ inside each ractor, and the 1-thread default removes those for everyone. At
491
+ the default, lanes post the fastest plaintext/10k of any Kino
492
+ configuration, but plain shared-queue takes /cpu. It stays opt-in because overload semantics differ from the
389
493
  shared queue (`queue_depth` doesn't apply; capacity is lanes × 4 with
390
494
  brief dispatcher retries up to `queue_timeout` before the 503), and
391
495
  crash semantics, stealing fairness, and drain behavior have spec
@@ -394,7 +498,8 @@ lose a few percent instead; see the secondary table below.)
394
498
 
395
499
  ## Sharded I/O (`io_shards true`)
396
500
 
397
- `bench/studies.sh 8 64 shards`, ractor 8×3, 2026-09 reference box:
501
+ `bench/studies.sh 8 64 shards`, ractor 8×3, on the 2026-09 c7a.2xlarge
502
+ box (Ruby 4.0.6; not re-measured in 2026-11):
398
503
 
399
504
  | case (/plaintext) | req/s |
400
505
  |---|---:|
@@ -414,7 +519,8 @@ more cores and connections, and measure on your own core count.
414
519
 
415
520
  Measured at full plaintext saturation (one log line per request—rates
416
521
  that no real deployment logs at; treat these as worst-case ceilings, not
417
- typical costs):
522
+ typical costs). These are the 2026-09 c7a.2xlarge figures (Ruby 4.0.6),
523
+ not re-measured in 2026-11:
418
524
 
419
525
  | case (8×3, same session, 2026-09) | req/s |
420
526
  |---|---:|
@@ -445,56 +551,74 @@ the default, `-v/--log-requests` enables it)—Kino's default-off
445
551
 
446
552
  ## HTTP/2
447
553
 
448
- `bench/h2.sh`, Linux only (on macOS run it under Docker; the 2026-09
449
- numbers below are from the c7a.2xlarge reference box). Every lane is
554
+ `bench/h2.sh`, Linux only (on macOS run it under Docker; the numbers
555
+ below are from the c8a.2xlarge box, Ruby 4.0.9). Every lane is
450
556
  measured with h2load so the generator is identical everywhere: h2
451
557
  lanes run 8 connections × 8 concurrent streams, h1 lanes 64
452
558
  connections—the same total in-flight. Servers without native h2 get
453
559
  the standard pattern instead: nginx terminating h2 and proxying
454
- HTTP/1.1 upstream over keep-alive. One labeled run (kino ractor 8×3,
455
- falcon `--count 8`, puma `-w 8 -t 3:3`, 5 s/lane); re-run the whole
456
- script for close calls, per the variance section.
560
+ HTTP/1.1 upstream over keep-alive. Kino ractor 8×3, falcon `--count 8`,
561
+ puma `-w 8 -t 3:3`, 5 s per lane; the script ran three times
562
+ (`bench/h2.sh 5 8 8`) and each cell is the median.
457
563
 
458
564
  | target (h2 unless noted) | /plaintext | /10k | /big-cookie | /upload (64 KB) |
459
565
  |---|---:|---:|---:|---:|
460
- | kino h2c | 207,461 | 150,105 | 195,093 | 26,304 |
461
- | kino h1 cleartext (same boot) | 116,082 | 97,634 | 110,614 | 24,338 |
462
- | kino h2 TLS | 164,044 | 116,617 | 154,301 | 19,226 |
463
- | kino h1 TLS (same boot) | 80,789 | 69,942 | 76,654 | 17,210 |
464
- | falcon TLS (native h2) | 55,637 | 37,541 | 49,151 | 18,838 |
465
- | nginx h2 → puma h1 | 81,234 | 57,891 | 51,332 | 1,247 |
466
- | nginx h2 → kino h1 | 109,219 | 66,634 | 54,996 | 1,217 |
566
+ | kino h2c | 424,717 | 288,231 | 378,434 | 71,106 |
567
+ | kino h1 cleartext (same boot) | 300,667 | 252,243 | 249,953 | 72,902 |
568
+ | kino h2 TLS | 355,281 | 217,269 | 324,092 | 52,635 |
569
+ | kino h1 TLS (same boot) | 225,264 | 164,538 | 196,416 | 47,940 |
570
+ | falcon TLS (native h2) | 100,399 | 123,305 | 112,884 | 49,162 |
571
+ | nginx h2 → puma h1 | 185,917 | 148,375 | 150,235 | 1,199 |
572
+ | nginx h2 → kino h1 | 245,741 | 162,915 | 121,263 | 1,224 |
467
573
 
468
574
  What the numbers say:
469
575
 
470
- - **Native h2 beats h1 on the same server by +79% cleartext and +103%
576
+ - **Native h2 beats h1 on the same server by +41% cleartext and +58%
471
577
  over TLS** on /plaintext: the same 64 in-flight requests ride 8
472
578
  connections instead of 64, so frames batch into fewer, larger
473
- syscalls—and TLS amplifies it, since h1's 64 connections each pay
474
- crypto per record. The `/big-cookie` lane (a ~2 KB cookie per
475
- request) shows HPACK on top: the cookie crosses the wire once per
476
- connection, not once per request, and holds 94% of bare-plaintext
477
- throughput where h1 loses 5%.
478
- - **Native h2 beats proxied h2 by +50%** with the *same backend*: the
579
+ syscalls. The `/big-cookie` lane (a ~2 KB cookie per request) shows
580
+ HPACK on top: the cookie crosses the wire once per connection, not
581
+ once per request, and h2 holds 89-91% of its bare-plaintext
582
+ throughput where h1 holds 83-87%.
583
+ - **Native h2 beats proxied h2 by +45%** with the *same backend*: the
479
584
  nginx→kino-h1 lane is the proxy-cost control, and the extra hop,
480
- re-parse, and re-serialize cost ~55k req/s on /plaintext.
481
- - **Uploads run at h1 parity**—but only after a fix this lane
482
- caught: h2 delivers bodies as 16 KB DATA frames, and `read_body`
483
- originally crossed the GVL once per chunk, halving upload
484
- throughput. It now drains every queued chunk per crossing
485
- (doc/architecture.md), and a knob sweep over hyper's h2 codec
486
- (frame size, adaptive/bigger windows) moved nothing afterwards.
487
- nginx's h2 upload collapse (~1.5k) is its default-config
488
- request-body flow control; tune `http2_body_preread_size`/buffering
489
- before drawing conclusions there.
490
- - falcon lands at roughly a third of kino-h2-TLS on fast handlers and
491
- slightly behind on uploads. Single-run caveat: the nginx lanes
492
- showed ±20% swings between runs in the Docker environment; on the
493
- reference box the kino-vs-kino and kino-vs-proxy ratios reproduced
494
- across runs, the nginx lanes remain the noisiest.
585
+ re-parse, and re-serialize cost ~110k req/s on /plaintext.
586
+ - **Uploads run ahead of h1 over TLS (+10%) and 2% behind it in
587
+ cleartext**—after a fix this lane caught: h2 delivers bodies as
588
+ 16 KB DATA frames, and `read_body` originally crossed the GVL once
589
+ per chunk, halving upload throughput. It now drains every queued
590
+ chunk per crossing (doc/architecture.md), and a knob sweep over
591
+ hyper's h2 codec (frame size, adaptive/bigger windows) moved nothing
592
+ afterwards.
593
+ - **nginx's upload collapse (~1.2k) is not HTTP/2 flow control.** It
594
+ is nginx spooling the request body to a temporary file: the 64 KB
595
+ upload is larger than the default `client_body_buffer_size`, so
596
+ every request logs "a client request body is buffered to a temporary
597
+ file". A diagnostic on the nginx→kino-h1 lane, with `bench/h2.sh`'s
598
+ nginx config plus one change per row:
599
+
600
+ | nginx config | /upload req/s | bodies spooled |
601
+ |---|---:|---|
602
+ | as in `bench/h2.sh` | 1,219 | all |
603
+ | the same, HTTP/1.1 clients (64 connections) | 1,215 | all |
604
+ | `http2_body_preread_size 1m` | 1,224 | all |
605
+ | `client_body_buffer_size 1m` | 52,131 | none |
606
+ | `proxy_request_buffering off` | 50,828 | none |
607
+
608
+ An HTTP/1.1 client collapses the same way, and the h2 preread knob
609
+ changes nothing, so h2 is not the cause. **The fix** is either to
610
+ hold the body in memory (`client_body_buffer_size` at least as large
611
+ as your uploads) or not to buffer it at all (`proxy_request_buffering
612
+ off`); both bring the lane to 51-52k, level with Kino's own h2 TLS
613
+ uploads. Moving the temp path to tmpfs did not help (1,226), and
614
+ `sendfile on` did while still spooling every body (45,269).
615
+ - falcon lands at 28-57% of kino-h2-TLS on the fast handlers (28% on
616
+ /plaintext) and 7% behind on uploads. Its lanes are the noisiest
617
+ here: its three /10k runs spread from 86,705 to 125,634.
495
618
  - **Header-value interning** (user-agent, accept-*, sec-ch-*: one
496
619
  frozen string instead of a fresh allocation per request) was
497
- measured with a realistic 11-header browser set on /plaintext,
620
+ measured in 2026-09, when it landed, with a realistic 11-header
621
+ browser set on /plaintext,
498
622
  using the within-boot header cost (bare vs with-headers) as the
499
623
  drift-resistant metric: over h2 that cost fell from ~16% to ~12-13%
500
624
  (~+3-5% throughput on the headers lane); h1's smaller header cost
@@ -502,6 +626,112 @@ What the numbers say:
502
626
  string allocations per request is GC pressure a real app feels more
503
627
  than this one does.
504
628
 
629
+ ## Ruby 4.1 (development build)
630
+
631
+ Ruby 4.0.9 is the released Ruby and the primary number in every
632
+ section above. This section is the same measurement on a **development
633
+ build** of Ruby 4.1 (`4.1.0dev`, master f2d62c677e of 2026-11-21, YJIT
634
+ on): the same box, harness, passes and medians, with Kino built against
635
+ that Ruby. Ruby 4.1 is not released; treat these as a preview that can
636
+ move.
637
+
638
+ ### What changes
639
+
640
+ - **Every ractor column rises.** Ruby 4.1 collects garbage per Ractor.
641
+ On the light rows (/plaintext, /10k) the default ractor column gains
642
+ +10% and +19%, lanes +16% and +26%. On /cpu the default column's
643
+ median is +8% and lanes' is flat, and both overlap the range of the
644
+ 4.0.9 boots.
645
+ - **`workers 32` gains about 90% on the light rows** (+89% on
646
+ /plaintext, +91% on /10k) and +53% on /cpu, where it now equals the
647
+ 8×1 default. On 4.0.9 the io-tuned topology cost 16-19% against the
648
+ cluster everywhere but /io; on 4.1 it is ahead of the cluster on
649
+ every row.
650
+ - **`:ractor` PSS falls to 52 MB** (from 167 MB), **14× lighter than
651
+ the cluster**, whose own PSS falls from 1,171 to 746 MB. Threaded
652
+ mode goes the other way: 110 to 150 MB arena-capped, 155 to 227 MB
653
+ uncapped.
654
+ - **`:threaded` and Puma lose 2-13%** on /plaintext, /10k and /cpu
655
+ (threaded −4%, −3%, −2%; Puma −7%, −13%, −4%). The wait-bound rows
656
+ do not move.
657
+
658
+ These are measurements, not attributions: nothing here isolates why
659
+ threaded mode and Puma slow down, or why their memory moves.
660
+
661
+ ### Main table on Ruby 4.1
662
+
663
+ | endpoint | Kino :ractor | + lanes | :ractor, `workers 32` | Kino :threaded | Puma (cluster) |
664
+ |-------------|-------------:|--------:|----------------------:|---------------:|---------------:|
665
+ | /plaintext | 512,945 | **608,283** | 463,223 | 378,380 | 269,662 |
666
+ | /10k | 447,144 | **515,785** | 388,306 | 275,927 | 218,884 |
667
+ | /cpu (fib) | 128,097 | 112,276 | **128,109** | 19,739 | 99,379 |
668
+ | /io (5 ms) | 1,558 | 1,542 | **6,102** | 4,702 | 4,728 |
669
+ | /io_native | 1,576 | 1,581 | **6,314** | 4,738 | 4,730 |
670
+
671
+ Against the cluster on Ruby 4.1: ractor mode is 1.9-2.0× ahead on
672
+ /plaintext and /10k (lanes 2.3-2.4×, threaded 1.3-1.4×) and +29% on
673
+ /cpu (+13% with lanes), 6.5× its own threaded mode. `workers 32` is
674
+ +29% on /io and +33% on /io_native.
675
+
676
+ ### Memory on Ruby 4.1 (PSS, MB, tiny app)
677
+
678
+ | config | RSS | PSS | 4.0.9 PSS |
679
+ |---|---:|---:|---:|
680
+ | Kino :ractor 8×1 (default) | 54 | **52** | 167 |
681
+ | Kino lanes 8×1² | 54 | **51** | 169 |
682
+ | Kino :ractor 32×1² | 110 | **108** | 79 |
683
+ | Kino :threaded 8×3 (`MALLOC_ARENA_MAX=2`) | 152 | **150** | 110 |
684
+ | Kino :threaded 8×3 (no arena cap)² | 229 | **227** | 155 |
685
+ | Puma cluster 8×3 | 879 | **746** | 1,171 |
686
+
687
+ ² From the main table's passes, on both Rubies (so the 4.0.9 uncapped
688
+ threaded figure here is that run's 155 MB, not the 144 MB of the arena
689
+ A/B above).
690
+
691
+ The ratio to the cluster is ~14× in ractor mode and ~5× in arena-capped
692
+ threaded mode.
693
+
694
+ ### Ractor-pool wrapper on Ruby 4.1
695
+
696
+ | endpoint | Kino :ractor (8×3) | Puma + wrapper | Falcon + wrapper |
697
+ |------------|-------------------:|---------------:|-----------------:|
698
+ | /plaintext | 445,252 | 38,198 | 201,168 |
699
+ | /cpu (fib) | 118,739 | 36,701 | 88,088 |
700
+ | /io (5 ms) | 4,656 | 1,526 | 1,563 |
701
+
702
+ Kino at 8×3 gains +8% and +10% on /plaintext and /cpu. The Puma
703
+ wrapper moves −6% and +10%, the Falcon wrapper −17% and −7%.
704
+
705
+ ### HTTP/2 on Ruby 4.1
706
+
707
+ | target (h2 unless noted) | /plaintext | /10k | /big-cookie | /upload (64 KB) |
708
+ |---|---:|---:|---:|---:|
709
+ | kino h2c | 485,189 | 376,586 | 467,071 | 81,048 |
710
+ | kino h1 cleartext (same boot) | 333,545 | 287,251 | 308,467 | 77,958 |
711
+ | kino h2 TLS | 368,885 | 275,102 | 355,013 | 54,234 |
712
+ | kino h1 TLS (same boot) | 231,119 | 191,489 | 214,085 | 47,107 |
713
+ | falcon TLS (native h2) | 116,003 | 118,664 | 120,601 | 50,876 |
714
+ | nginx h2 → puma h1 | 175,436 | 130,576 | 137,531 | 1,259 |
715
+ | nginx h2 → kino h1 | 249,922 | 181,448 | 185,498 | 1,195 |
716
+
717
+ Native h2 over h1 on /plaintext is +45% cleartext and +60% over TLS,
718
+ and +48% over the nginx hop. Uploads are +15% over h1 with TLS and +4%
719
+ in cleartext. The nginx upload diagnostic reproduces: 1,232 req/s as
720
+ configured, 53,665 with `client_body_buffer_size 1m`, 54,259 with
721
+ `proxy_request_buffering off`.
722
+
723
+ ### Rails on Ruby 4.1
724
+
725
+ | | req/s | RSS | PSS |
726
+ |---|---:|---:|---:|
727
+ | Kino `:threaded` (one process) | 7,903 | 109 MB | **104 MB** |
728
+ | Puma cluster (8 workers, preload) | 35,060 | 1,113 MB | **835 MB** |
729
+ | Puma cluster (8 workers, no preload) | 34,288 | 1,112 MB | **958 MB** |
730
+
731
+ The cluster serves ~4.4× the throughput at ~8.0× the memory by PSS.
732
+ Measured with the re-resolved lockfile described under
733
+ [Rails](#rails).
734
+
505
735
  ## Hot-path notes
506
736
 
507
737
  For the curious, the dispatch-path work behind the numbers: a try-pop