Fork me on GitHub
#aleph
<
2023-10-16
>
Matthew Davidson (kingmob)07:10:34

@jwhitlark expressed some interest in the https://github.com/clj-commons/aleph/issues/690. First, this issue is meant to be exploratory. We need a short report first, before any code. My biggest concern is that it won't be that useful. Every server has had their own ad hoc API for Websockets for years now. Standardization could help people switch servers, but enough servers will have to support the spec before that's useful. My next concern is that Websockets are an older technology. They're simple, but H2 streams should supplant them for many uses. H2 gives you multiplexing for free, without consuming multiple TCP sockets. For a greenfield project, I wouldn't start with websockets when I can open an H2 stream, and make the bodies an infinite/indefinite stream of bytes. Of course, that depends on the client, because the one major blocker is Websockets have better support in browsers for the moment. There's ongoing, experimental, and standards work to support infinite streaming bodies (see Web Transports), but it's not here yet. tl;dr I'm just not sure it's worth it, compared to the many other things we could do. (Like, I think https://github.com/clj-commons/aleph/issues/683`wrap-decompression`https://github.com/clj-commons/aleph/issues/683 for HTTP1 is probably more useful.) I'm not saying no, though!

Matthew Davidson (kingmob)07:10:10

What other issues would be good for newcomers?

hiredman07:10:34

https://www.rfc-editor.org/rfc/rfc8441.html there is an rfc for websocket over http2, and I believe even one for ws over http3

hiredman08:10:00

I find the idea that http2 streams would supplant websockets kind of shocking. They are just different things.

Matthew Davidson (kingmob)08:10:40

The RFC for WS over http2 hasn't really proved popular.

Matthew Davidson (kingmob)08:10:50

Last I checked, nobody implemented it. Checked again, looks like there's partial support in browsers, but not much from servers and reverse proxies.

Matthew Davidson (kingmob)08:10:32

Also, I need to update my comment a bit. I had to doubble-check, and realized that browsers don't support streaming over fetch() yet (though there is standardization and experimental work)

Matthew Davidson (kingmob)08:10:05

But conceptually, WS and H2 steams are really similar, actually.

hiredman08:10:30

Websockets in general are not that great (who knew, stateful connections are annoying on mobile devices) but http streams have the same problem there

Matthew Davidson (kingmob)08:10:35

The request/response nature of HTTP is a bit of a red herring. For infinite streams, thnk of it like the WS handshakes. Once each sides exchange HEADER frames, they can send inifinte DATA frames and do with it what they want

Matthew Davidson (kingmob)08:10:17

For mobile, HTTP/3's QUIC session identifiers would be a big advantage

Matthew Davidson (kingmob)08:10:01

AFAICT, they allow seamless resumption when you switch networks, like going from wifi to cell

👆 1
Matthew Davidson (kingmob)08:10:20

I think if browsers supported a way to use H2/H3 streaming in Js, there wouldn't be any good WS use cases left (other than for legacy purposes). Websockets have slightly less packet overhead, but the lack of multiplexing is a big minus.

raspasov06:10:44

re: multiplexing; I am sure it can have significant benefit when loading a complex webpage with dozens (or likely 100s) of elements however, if I am simply serving API-style endpoints, I am not convinced there’s any significant real-world benefit (welcome to be proven wrong with examples - I tried looking but could not find anything)

raspasov06:10:30

HTTP/3 with QUIC is quite exciting though; the possibility of having all the benefits of WebSocket-style communication without worrying about stateful connections is potentially awesome (but I have not first-hand experience with it, so my excitement is purely theoretical at the moment 🙂 )

raspasov06:10:56

(and that can potentially benefit all kinds of servers: serving complex pages, simple pages, API servers, etc)

Matthew Davidson (kingmob)07:10:54

Yes, not all usage patterns benefit from multiplexing, but many will. For APIs, consider making a few requests near-simultaneously. If they overlap, you benefit from multiplexing. Browsers are definitely the poster child for benefitting from H2 multiplexing tho.

👍 1
Matthew Davidson (kingmob)07:10:54

@U050KSS8M What in H3/QUIC are you most interested in? The QUIC connection ids, per-packet encryption, something else? The WebTransport protocol is the part most like WebSockets

raspasov07:10:02

For sure… I just imagine the WebSocket use case… (which I have experience with first hand); it’s effectively a light wrapper on top of TCP; TCP is the ultimate limiter here; Since WebSockets are full-duplex, there’s no blocking/waiting per-se.

raspasov07:10:35

In terms of QUIC, I am curious about whether it can truly do > allow seamless resumption when you switch networks like you said; I wonder if that’s a potential benefit in servers as well? Aka, can one completely forget about stateful re-connections? (again my knowledge here is limited to a few conference talks I’ve watched on the subject, so not first-hand…)

raspasov07:10:04

With WebSockets that’s definitely the pain point (statefulness, heartbeats, is my connection alive? etc) (but ultimately TCP is the limiting factor there I think)

raspasov07:10:06

WebTransport looks cool, yeah

raspasov07:10:40

I guess the question is, can WebTransport offer all those supposed benefits of seamless resumption, etc

Matthew Davidson (kingmob)07:10:52

> Since WebSockets are full-duplex, there’s no blocking/waiting per-se > that’s definitely the pain point (statefulness, heartbeats, is my connection alive? etc) I mean, H2 streams are full-duplex, too, and a lot of its state mgmt is already handled for you. I think the request/response nature of HTTP really misleads people about what H2/3 can do. At the protocol level, treating the body like an infinite stream of bytes just like Websockets is easy. The only catch is browsers don't support HTTP responses like that very well (though there are still things like Server-Sent Events, which fit many simple use cases). But if you're a server, or using a non-browser client, H2/3 is fine for a lot of WS uses

Matthew Davidson (kingmob)07:10:04

That's where WebTransports seem to come in, though I haven't done much reading up on them yet. Still wrapping up H2 in Aleph.

raspasov07:10:21

I guess I am generally non-excited about HTTP/2 variants since they are all TCP based. Until we can go to UDP (with seamless reconnections), I am not sold on the benefits, at least for the use cases I’m involved in (which admittedly, does not involve serving facebook or CNN-sizes pages…)

raspasov07:10:58

(and I am guessing that’s where the majority of benefit lies)

Matthew Davidson (kingmob)07:10:02

> Aka, can one completely forget about stateful re-connections? It should definitely minimize reconns, especially across network switches. But eventually you'll get an error, or if the conn lives long enough, run out H2 stream identifiers.

Matthew Davidson (kingmob)07:10:41

> can WebTransport offer all those supposed benefits of seamless resumption I think resumption is built into the QUIC layer, so tentatively I'd expect the asnwer to be yes

👍 1
raspasov07:10:44

Hmm yeah… I’ve experienced for example how flaky gRPC (HTTP/2) based connections/patterns can be (on at least 2 occasions over the years); Non-aleph based.

raspasov07:10:50

Yeah that would be the holy grail of connecting 🙂 Just connect and forget!

raspasov07:10:20

(aka it’s all handled seamlessly at the protocol layer under the hood…)

Matthew Davidson (kingmob)07:10:13

Don't quote me on HTTP/3 resumption, there might still be required support at the application layer. I need to take a closer look

Matthew Davidson (kingmob)07:10:48

What's your API use pattern?

raspasov07:10:01

FWIW, currently using Aleph with old-school HTTT/1.1 🙂

raspasov07:10:07

(serving JSON api)

raspasov07:10:09

Works great.

raspasov07:10:55

I’ve used Aleph with websockets and raw TCP over the years (also great, minus the re-connection hassle - but that’s not really Aleph’s fault/problem in general)

Matthew Davidson (kingmob)07:10:20

Because I'd think any time the same client makes multiple (near-)simultaneous requests, you'd benefit from H2's multiplexing. Pipelining never took off, so otherwise, you're forced to wait for responses to come in, and with Websockets, you have to write your own multiplexing, when otherwise you could cheaply fire up a new stream

Matthew Davidson (kingmob)07:10:09

If reconns are your thing, yeah, you need nothing short of QUIC.

Matthew Davidson (kingmob)07:10:57

Oh wow, gloss. I wrote a bunch of that a couple years ago for a speech-to-text project

raspasov07:10:02

“any time the same client makes multiple (near-)simultaneous requests” yeah the question is how many requests really does it get to see the benefits though it would have to be 10+ at the same time… even with HTTP/1.1 (and most of our current patterns are one request at the time, more or less, so truly not much benefit)

Matthew Davidson (kingmob)07:10:33

Yeah, with a light usage pattern, it won't help much. Obviously, the more simultaneous requests, the better H2 will be over H1

Matthew Davidson (kingmob)07:10:17

Need not be 10+ tho, even 2-3 should be faster. Nobody likes waiting 😄

raspasov07:10:39

Yeah, it’s more efficient, I understand;

raspasov07:10:51

Opening 1 socket vs many, etc;

Matthew Davidson (kingmob)07:10:04

Btw, I'd like to hear about your experience with gRPC issues; I've never used it

raspasov07:10:56

I hate to be a conspiracy theorist 😂 but I’ve encountered the opinion that RFC/et al HTTP standards have been sorta taken over by big companies where this kind of efficiency does make sense … but at a smaller scale it’s hard to quantify those benefits and the cost is often much more complexity in protocol, implementation, etc; I am not a “big companies = bad” type of person – I don’t have an ax to grind in this debase but I kinda soft agree with the above… it all depends on the use-case, and often the “best practices/newest thing” is not what one truly needs;

Matthew Davidson (kingmob)07:10:13

True, there's definitely a bunch of cargo-culting of what unicorns do. I guess for me, I view protocols as needing to support the widest range of use cases, since they're shared by everyone

raspasov07:10:20

re: gRPC basically re-connection troubles, and protobuf is its own weird thing (non-human readable; schema-out-of-band)

raspasov07:10:43

> a bunch of cargo-culting of what unicorns do 💯

Matthew Davidson (kingmob)07:10:55

Protobuf is goog's widely-used binary framing lib, right?

raspasov07:10:56

(not even unicorns, but like Facebook & Google)

Matthew Davidson (kingmob)07:10:23

what issues with reconnecting did you run into?

raspasov07:10:19

Well, at some point your stream or connection dies 🙂 (basically, all the issues you’d have with WebSockets)

raspasov07:10:44

re: protocol buffers and formats, old but great Rich Hickey talk (at timestamp) https://youtu.be/ROor6_NGIWU?t=736

raspasov07:10:03

widest range of use cases, since they’re shared by everyoneTotally understand your point, as a maintainer 👍

Matthew Davidson (kingmob)07:10:40

> Well, at some point your stream or connection dies :thinking_face: Was it around 1 billion calls? That's when I'd expect to run out of H2/3 stream ids, and need to make a new conn

Matthew Davidson (kingmob)07:10:10

If not, well, network errors are inevitable

raspasov07:10:20

Was it around 1 billion calls?I am not exactly sure… I doubt it… But that’s good food for thought…

Matthew Davidson (kingmob)07:10:26

Good thing RAM/CPU isn't as flaky as network 😂

raspasov07:10:42

> If not, well, network errors are inevitable Right.. that’s why I have so much hope about QUIC and WebTransport if that can be automagically abstracted away 😁

raspasov07:10:13

> Good thing RAM/CPU isn’t as flaky as network Haha, oh yeah…

jwhitlark19:10:54

I'm going to have to bow out of this one. It is clearly a much more complicated issue that I first assumed. 😲

Matthew Davidson (kingmob)07:10:44

@jwhitlark Thanks for taking a look, though. Think I should remove the "good first issue" tag? In my head, I thought it wouldn't require much code-writing, but I guess it involves a TON of code-reading.

Matthew Davidson (kingmob)08:10:59

I took a closer look at @hiredman’s suggestion to add support RFC 8441, using Websockets over H2. There's https://wpt.fyi/results/websockets/opening-handshake/002.html%3Fwpt_flags%3Dh2?label=experimental&amp;label=master&amp;aligned (all but Safari), so if anyone wants it, we could add an issue for it.