Repository navigation
Conversation
Clients name their topics in the handshake (auth.topics) or with
set_subscriptions (acked with {"count": n}) and get only those; clients
that never do stay on the every-topic room. Unread topics are skipped
before serialization. ADR 0009 records the decision.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vbA3j9hMDhLiYyTkHLpH8
Co-Authored-By: bracyw <138251570+bracyw@users.noreply.github.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: bracyw <138251570+bracyw@users.noreply.github.com> Claude-Session: https://claude.ai/code/session_013vbA3j9hMDhLiYyTkHLpH8
socketioxide handles each event in its own task, so lists sent close
together could apply out of order and leave released topics live. Each
list now carries a seq; scylla drops one numbered no higher than the last
it applied, and acks {count, seq}.
TheJeffreyKuo
left a comment
There was a problem hiding this comment.
Looks good, a few problems and nits caught
| SocketClientId(client_id): SocketClientId, | ||
| HandshakeTopics(topics): HandshakeTopics| async move { | ||
| // `data`: every topic, or only the handshake's or `set_subscriptions`' topics | ||
| ns_subscriptions.register(&socket, topics).await; |
There was a problem hiding this comment.
Register set_subscriptions before the connect ack, as #986 does; a list sent right after connecting is dropped
| /// only in its topic rooms: never both (socketioxide does not dedupe a | ||
| /// socket in two target rooms, so it would get the message twice) and | ||
| /// never neither (it would miss a topic it kept). | ||
| every_topic_exit: tokio::sync::RwLock<()>, |
There was a problem hiding this comment.
Do sockets need to leave the every-topic room? No client does, and every emit takes this lock.
| @@ -0,0 +1,25 @@ | |||
| # Deliver each topic through its own Socket.IO room | |||
|
|
|||
| scylla-server sends the live `data` event for a topic only to clients that asked for it, over the Socket.IO connection they already have. Each topic is a room. A client names the full list of topics it reads, in the connect handshake (auth payload `{"topics": [...]}`) or later with the `set_subscriptions` event (`{"seq": n, "topics": [...]}`, acked with `{"count", "seq"}` of the list it ended on), and scylla moves its socket into exactly those rooms. A client that never names any, such as an old Angular build or the Flutter app, sits in one every-topic room (`#`) and gets every topic, as before. Once a client has named a list, even an empty one, it is never in the every-topic room again. `metadata`, `faults`, `timers` and rule notifications still go to every socket. | |||
There was a problem hiding this comment.
Say rule notifications go only to subscribed clients
| @@ -0,0 +1,125 @@ | |||
| # Selective delivery benchmarks | |||
There was a problem hiding this comment.
Are the benchmarks needed in the repo? CI never runs them, and they add a Node package to the crate.
| /// Connect extractor for the topics a socket named in its handshake, the | ||
| /// Socket.IO auth payload `{"topics": [...]}`. `None` when there is no | ||
| /// `topics` field, or it is not a list of strings. | ||
| pub struct HandshakeTopics(pub Option<Vec<String>>); |
There was a problem hiding this comment.
Nit: Take TryData<HandshakeAuth> in the handler and drop this wrapper
Changes
scylla-server sends each data message only to sockets in its topic's Socket.IO room. A client subscribes with a set_subscriptions event (the full list, numbered so the latest always wins even when events are handled out of order) or in the connect handshake's auth topics; once it has, it never gets every topic again. Clients that never subscribe stay on an every-topic room, so older clients keep working. Topics nobody reads are skipped before serializing. ADR 0009 records the decision. Benchmarks are in scylla-server/benchmarks/.
Diagram
flowchart LR subgraph Connect["On connect"] direction TB H{"handshake has<br/>auth.topics?"} H -- no --> ALL["every-topic room<br/>(clients that send no list)"] H -- "yes, even empty" --> T["exactly those topic rooms<br/>(list seq 0)"] end subgraph Change["On set_subscriptions"] direction TB Q{"seq above the<br/>last list applied?"} Q -- no --> DROP["drop it, ack the latest"] Q -- yes --> J["leave removed rooms,<br/>join added ones;<br/>never back to every-topic"] end subgraph Emit["Each MQTT data message"] direction TB N{"any socket in its topic room<br/>or the every-topic room?"} N -- no --> SKIP["skip, never serialized"] N -- yes --> EM["serialize once, emit to<br/>topic room + every-topic room"] end Connect ~~~ Change ~~~ EmitTesting
Benchmarks
Live, 15 clients each on a small page (~25 topics), release builds of this branch and of develop (cc50fa0), M4 Pro laptop:
Per data emit with 15 sockets: develop's broadcast 3.8 µs, rooms with small pages 0.5 µs, a topic nobody reads 0.08 µs. Old clients cost the same as on develop. A page switch acks in 0.3–1.4 ms. Method, every table and caveats are in the benchmarks README.
Notes
Checklist
Closes #993