kino 0.7.2 → 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.
- checksums.yaml +4 -4
- data/.yardopts +5 -0
- data/CHANGELOG.md +281 -0
- data/Cargo.lock +164 -95
- data/README.md +269 -438
- data/doc/README.md +27 -2
- data/doc/architecture.md +862 -43
- data/doc/benchmarks.md +444 -214
- data/doc/configuration.md +215 -0
- data/doc/operations.md +258 -0
- data/doc/rails-on-ractors.md +161 -49
- data/doc/streaming.md +52 -0
- data/doc/websockets.md +469 -0
- data/doc/why-kino.md +6 -6
- data/doc/worker-loop.md +462 -0
- data/ext/kino/Cargo.toml +17 -1
- data/ext/kino/build.rs +32 -1
- data/ext/kino/clippy.toml +10 -0
- data/ext/kino/src/access_log.rs +70 -92
- data/ext/kino/src/control.rs +26 -685
- data/ext/kino/src/counters.rs +132 -0
- data/ext/kino/src/cpus.rs +1 -18
- data/ext/kino/src/dispatch/tests.rs +731 -0
- data/ext/kino/src/dispatch.rs +276 -0
- data/ext/kino/src/doorbell.rs +108 -0
- data/ext/kino/src/env_strings.rs +26 -30
- data/ext/kino/src/framing.rs +110 -0
- data/ext/kino/src/gvl.rs +292 -66
- data/ext/kino/src/hijack/tests.rs +416 -0
- data/ext/kino/src/hijack.rs +471 -0
- data/ext/kino/src/inline/answer.rs +488 -0
- data/ext/kino/src/inline/conn.rs +1124 -0
- data/ext/kino/src/inline/deadline.rs +421 -0
- data/ext/kino/src/inline/encode.rs +119 -0
- data/ext/kino/src/inline/io.rs +487 -0
- data/ext/kino/src/inline/mod.rs +766 -0
- data/ext/kino/src/inline/parity.rs +862 -0
- data/ext/kino/src/inline/parse.rs +131 -0
- data/ext/kino/src/inline/spin.rs +428 -0
- data/ext/kino/src/inline/testing.rs +628 -0
- data/ext/kino/src/io_shards.rs +240 -192
- data/ext/kino/src/lane_room.rs +99 -0
- data/ext/kino/src/lib.rs +139 -77
- data/ext/kino/src/listen.rs +180 -12
- data/ext/kino/src/log.rs +12 -47
- data/ext/kino/src/logsink.rs +3 -9
- data/ext/kino/src/mono.rs +12 -17
- data/ext/kino/src/pin.rs +3 -3
- data/ext/kino/src/queue/mod.rs +54 -0
- data/ext/kino/src/queue/take.rs +503 -0
- data/ext/kino/src/queue/testing.rs +107 -0
- data/ext/kino/src/queue/tests.rs +581 -0
- data/ext/kino/src/queue/worker.rs +501 -0
- data/ext/kino/src/registry.rs +168 -379
- data/ext/kino/src/request.rs +834 -235
- data/ext/kino/src/response.rs +532 -94
- data/ext/kino/src/server/accept.rs +322 -0
- data/ext/kino/src/server/config.rs +138 -0
- data/ext/kino/src/server/handle.rs +247 -0
- data/ext/kino/src/server/intake.rs +217 -0
- data/ext/kino/src/server/mod.rs +157 -0
- data/ext/kino/src/server/natives.rs +223 -0
- data/ext/kino/src/server/serve/intake_tests.rs +458 -0
- data/ext/kino/src/server/serve.rs +436 -0
- data/ext/kino/src/server/tests.rs +532 -0
- data/ext/kino/src/shared_gvl.rs +50 -0
- data/ext/kino/src/slot/lane.rs +138 -0
- data/ext/kino/src/slot/life.rs +111 -0
- data/ext/kino/src/slot/load.rs +193 -0
- data/ext/kino/src/slot/mod.rs +494 -0
- data/ext/kino/src/slot/park.rs +82 -0
- data/ext/kino/src/stats.rs +936 -0
- data/ext/kino/src/symbols.rs +66 -0
- data/ext/kino/src/test_support.rs +24 -14
- data/ext/kino/src/testing.rs +409 -0
- data/ext/kino/src/ticker.rs +87 -0
- data/ext/kino/src/timer.rs +4 -7
- data/ext/kino/src/tls.rs +101 -131
- data/ext/kino/src/typed_data.rs +131 -0
- data/ext/kino/src/upgrade.rs +77 -0
- data/ext/kino/src/ws/codec.rs +470 -0
- data/ext/kino/src/ws/drive.rs +600 -0
- data/ext/kino/src/ws/handshake.rs +267 -0
- data/ext/kino/src/ws/mod.rs +317 -0
- data/ext/kino/src/ws/server_tests.rs +759 -0
- data/ext/kino/src/ws/socket.rs +279 -0
- data/ext/kino/src/ws/stats.rs +88 -0
- data/ext/kino/src/ws/testing.rs +156 -0
- data/ext/kino/src/ws/topics.rs +550 -0
- data/lib/kino/cli.rb +100 -9
- data/lib/kino/configuration.rb +32 -10
- data/lib/kino/crash_backoff.rb +56 -0
- data/lib/kino/input.rb +36 -17
- data/lib/kino/log.rb +8 -1
- data/lib/kino/monitor.rb +1 -1
- data/lib/kino/pool.rb +169 -0
- data/lib/kino/pool_scaler.rb +12 -13
- data/lib/kino/quarantine_monitor.rb +3 -3
- data/lib/kino/ractor_supervisor.rb +201 -161
- data/lib/kino/server.rb +291 -185
- data/lib/kino/slot_bank.rb +21 -9
- data/lib/kino/stream.rb +2 -2
- data/lib/kino/teardown.rb +33 -0
- data/lib/kino/templates/kino.rb.tt +41 -6
- data/lib/kino/threaded_pool.rb +87 -102
- data/lib/kino/version.rb +1 -1
- data/lib/kino/web_socket.rb +125 -0
- data/lib/kino/worker/loop.rb +319 -0
- data/lib/kino/worker.rb +345 -79
- data/lib/kino/worker_hooks.rb +7 -1
- data/lib/kino/worker_row.rb +15 -0
- data/lib/kino.rb +27 -3
- data/lib/rackup/handler/kino.rb +1 -1
- data/sig/kino.rbs +93 -10
- metadata +66 -3
- data/ext/kino/src/queue.rs +0 -333
- data/ext/kino/src/server.rs +0 -1785
data/ext/kino/src/access_log.rs
CHANGED
|
@@ -20,6 +20,7 @@ use std::fmt::Write as _;
|
|
|
20
20
|
use std::net::IpAddr;
|
|
21
21
|
use std::time::Duration;
|
|
22
22
|
|
|
23
|
+
use crate::logsink::Sink;
|
|
23
24
|
use crate::style::{self, Stream};
|
|
24
25
|
|
|
25
26
|
/// Per-request timing, measured on the way through and riding the
|
|
@@ -36,6 +37,45 @@ pub struct Timing {
|
|
|
36
37
|
pub gc: Option<(Duration, u64)>,
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/// A request's two records in the access log, whichever way it is served: made as its arrival
|
|
41
|
+
/// line is queued, spent on its completion line.
|
|
42
|
+
pub struct Logged {
|
|
43
|
+
method: String,
|
|
44
|
+
target: String,
|
|
45
|
+
start: std::time::Instant,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl Logged {
|
|
49
|
+
/// Queues the arrival line on `log` now, before the app sees the request, so a hang shows
|
|
50
|
+
/// as an arrow with no answer.
|
|
51
|
+
pub fn arrival(log: &Sink, method: &http::Method, uri: &http::Uri, from: IpAddr) -> Logged {
|
|
52
|
+
let target = match uri.query() {
|
|
53
|
+
Some(query) => format!("{}?{query}", uri.path()),
|
|
54
|
+
None => uri.path().to_string(),
|
|
55
|
+
};
|
|
56
|
+
let method = method.to_string();
|
|
57
|
+
log.write_line(arrival(&method, &target, from));
|
|
58
|
+
Logged {
|
|
59
|
+
method,
|
|
60
|
+
target,
|
|
61
|
+
start: std::time::Instant::now(),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Since its arrival: its total, once its answer begins.
|
|
66
|
+
pub fn elapsed(&self) -> Duration {
|
|
67
|
+
self.start.elapsed()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// Queues the completion line, with the breakdown where a worker measured `timing`.
|
|
71
|
+
/// A thread-safe free may run it (an inline give-up's 500), so it keeps typed_data.rs's
|
|
72
|
+
/// promise: it formats and queues, no more.
|
|
73
|
+
pub fn completion(self, log: &Sink, status: u16, total: Duration, timing: Option<Timing>) {
|
|
74
|
+
let line = completion(status, &self.method, &self.target, total, timing);
|
|
75
|
+
log.write_line(line);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
39
79
|
/// The arrival record, stamped and styled for stdout.
|
|
40
80
|
pub fn arrival(method: &str, target: &str, ip: IpAddr) -> String {
|
|
41
81
|
let color = style::enabled(Stream::Stdout);
|
|
@@ -141,105 +181,43 @@ fn write_count(out: &mut String, n: u64) {
|
|
|
141
181
|
|
|
142
182
|
#[cfg(test)]
|
|
143
183
|
mod tests {
|
|
144
|
-
use super::{arrival_line, completion_line, now_stamp, write_breakdown, write_count, Timing};
|
|
145
|
-
use std::net::{IpAddr, Ipv4Addr};
|
|
146
184
|
use std::time::Duration;
|
|
147
185
|
|
|
148
|
-
|
|
149
|
-
let mut out = String::new();
|
|
150
|
-
write_breakdown(&mut out, total, timing);
|
|
151
|
-
out
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
fn count(n: u64) -> String {
|
|
155
|
-
let mut out = String::new();
|
|
156
|
-
write_count(&mut out, n);
|
|
157
|
-
out
|
|
158
|
-
}
|
|
186
|
+
use super::{write_breakdown, write_count, Timing};
|
|
159
187
|
|
|
188
|
+
// The records' shape, their stamp and the blank line after a completion:
|
|
189
|
+
// spec/logging_spec.rb. What the breakdown's numbers are is checked here.
|
|
160
190
|
#[test]
|
|
161
|
-
fn
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
// kino = total - ruby - wait = 45.2 - 41.0 - 0.1 = 4.1ms.
|
|
185
|
-
assert_eq!(
|
|
186
|
-
breakdown(Duration::from_micros(45_200), &timing),
|
|
187
|
-
"(ruby 41.0ms [gc 9.7ms; 52k obj]; kino 4.1ms; wait 0.1ms)"
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
#[test]
|
|
192
|
-
fn breakdown_leaves_out_the_gc_bracket_when_not_measured() {
|
|
193
|
-
let timing = Timing {
|
|
194
|
-
wait: Duration::from_millis(1),
|
|
195
|
-
ruby: Duration::from_millis(2),
|
|
196
|
-
gc: None,
|
|
197
|
-
};
|
|
198
|
-
assert_eq!(
|
|
199
|
-
breakdown(Duration::from_millis(4), &timing),
|
|
200
|
-
"(ruby 2.0ms; kino 1.0ms; wait 1.0ms)"
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
#[test]
|
|
205
|
-
fn breakdown_floors_kino_at_zero() {
|
|
206
|
-
let timing = Timing {
|
|
207
|
-
wait: Duration::from_millis(1),
|
|
208
|
-
ruby: Duration::from_millis(40),
|
|
209
|
-
gc: Some((Duration::ZERO, 10)),
|
|
210
|
-
};
|
|
211
|
-
assert_eq!(
|
|
212
|
-
breakdown(Duration::from_millis(40), &timing),
|
|
213
|
-
"(ruby 40.0ms [gc 0.0ms; 10 obj]; kino 0.0ms; wait 1.0ms)"
|
|
214
|
-
);
|
|
191
|
+
fn a_breakdown_splits_the_total_into_ruby_kino_and_wait_with_the_gc_bracket_when_measured() {
|
|
192
|
+
let us = Duration::from_micros;
|
|
193
|
+
// The total, wait, ruby and GC pause in microseconds with the objects allocated, and the
|
|
194
|
+
// breakdown: kino is what is left, floored at zero. One row per case; rustfmt would split
|
|
195
|
+
// each row field by field.
|
|
196
|
+
#[rustfmt::skip]
|
|
197
|
+
let rows = [
|
|
198
|
+
(45_200, 100, 41_000, Some((9_700, 52_000)), "(ruby 41.0ms [gc 9.7ms; 52k obj]; kino 4.1ms; wait 0.1ms)"),
|
|
199
|
+
(4_000, 1_000, 2_000, None, "(ruby 2.0ms; kino 1.0ms; wait 1.0ms)"),
|
|
200
|
+
(40_000, 1_000, 40_000, Some((0, 10)), "(ruby 40.0ms [gc 0.0ms; 10 obj]; kino 0.0ms; wait 1.0ms)"),
|
|
201
|
+
];
|
|
202
|
+
for (total, wait, ruby, gc, expected) in rows {
|
|
203
|
+
let gc = gc.map(|(pause, objects)| (us(pause), objects));
|
|
204
|
+
let timing = Timing {
|
|
205
|
+
wait: us(wait),
|
|
206
|
+
ruby: us(ruby),
|
|
207
|
+
gc,
|
|
208
|
+
};
|
|
209
|
+
let mut breakdown = String::new();
|
|
210
|
+
write_breakdown(&mut breakdown, us(total), &timing);
|
|
211
|
+
assert_eq!(breakdown, expected);
|
|
212
|
+
}
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
#[test]
|
|
218
216
|
fn count_humanizes_allocation_counts() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
#[test]
|
|
226
|
-
fn timestamp_is_date_time_and_numeric_offset() {
|
|
227
|
-
// `YYYY-MM-DD HH:MM:SS +HHMM`, e.g. `2026-08-22 14:03:11 +0300`.
|
|
228
|
-
let ts = now_stamp();
|
|
229
|
-
let (datetime, offset) = ts.rsplit_once(' ').expect("offset field");
|
|
230
|
-
let (date, time) = datetime.split_once(' ').expect("date and time");
|
|
231
|
-
assert_eq!(date.len(), 10, "date {date}");
|
|
232
|
-
assert_eq!(&date[4..5], "-");
|
|
233
|
-
assert_eq!(time.len(), 8, "time {time}");
|
|
234
|
-
assert_eq!(&time[2..3], ":");
|
|
235
|
-
assert_eq!(offset.len(), 5, "offset {offset}");
|
|
236
|
-
assert!(matches!(&offset[0..1], "+" | "-"));
|
|
237
|
-
assert!(offset[1..].bytes().all(|b| b.is_ascii_digit()));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
#[test]
|
|
241
|
-
fn completion_ends_with_the_blank_line_newline() {
|
|
242
|
-
let line = super::completion(200, "GET", "/", Duration::from_millis(1), None);
|
|
243
|
-
assert!(line.ends_with("\u{2190} 200 GET / 1.0ms\n") || line.ends_with("1.0ms\x1b[0m\n"));
|
|
217
|
+
for (n, humanized) in [(0, "0"), (523, "523"), (1500, "1.5k"), (52_000, "52k")] {
|
|
218
|
+
let mut count = String::new();
|
|
219
|
+
write_count(&mut count, n);
|
|
220
|
+
assert_eq!(count, humanized);
|
|
221
|
+
}
|
|
244
222
|
}
|
|
245
223
|
}
|