Repository navigation
Experiment: Hopac-native WebParts (Alt) — nacks, and how it compared to current Suave #861
Replies: 2 comments
|
Interesting. You didn't touch Though I am afraid the impedance on the Hopac/Task boundary it is always gonna be a problem. |
|
|
Uh oh!
There was an error while loading. Please reload this page.
Context
Years ago, there was talk of using Hopac inside Suave. I use Hopac in my own apps, so I tried a breaking, 4.0-style rewrite on a fork — not a drop-in for
master, just a curiosity I wanted to share.Fork / branch: eacasanovaspedre/suave@hopac
The interesting part is not raw RPS (plaintext is a wash). It is that WebParts can be nacked, which original Suave never did. Also, if like me, you also have a lot of code using Hopac or just like it, it's a natural fit to WebParts based on Hopac.
What the experiment is
master(today)WebPart<'a>'a -> Async<'a option>'a -> Hopac.Alt<'a option>choosefallback(choosekept as an alias)Alt.choose/ `<Async.WithTimeout— child keeps runningtimeoutWebPartnacks the childHttpContext.abort(IVar) +abortTokenValueTask/SocketOpValueTask)TaskJob(so waits park the Job, not a thread)chooseis still sequential first-match. Concurrent choice is Hopac’sAlt.choose, which is a different operator on purpose.I also tried turning
SocketOpintoJob. Plaintext dropped (~0.67× at 50 connections). I reverted that; sockets stayValueTask.Benchmarks vs
masterSame machine, same load generator, same apps.
--http1, keep-alive, loopback:3000master@edb9c743hopac(Jobs for connections, ValueTask sockets)Plaintext —
benchmarks/PongServer(OK "PONG", no routing tree)Warmup 10 s discarded, median of 3 × 30 s.
Zero non-2xx on both. Within noise: the extra abort
Alt.choose+ Hopac scheduler on an already-completedOKdoes not show up.Mixed handlers —
benchmarks/LoadMixWarmup 5 s, average of 2 × 15 s. This is the workload that actually uses timers / races.
/okOK "PONG"throughchoose/compute/sleep/race/faninMaster’s ~15.5 ms floor on 5–10 ms sleeps is Windows timer resolution (200 conn / 15 ms ≈ 13.3k, which is exactly
/raceand/faninon master). Hopac’s 10 ms timer is a bit more accurate when the request completes; RPS is still in the same band./timeout(20 ms nack of a 200 ms child) returns 408 in ~30 ms on both. On the fork the child Alt is actually nacked; onmaster,Async.WithTimeoutstill leaves the child running.How to reproduce
Takeaway
For Suave’s current “parse, OK, write” hot path, Hopac is not a speed win — and turning sockets into Jobs was a loss. Where it is different is cancellation of in-flight handlers, which Async WebParts never had.
I am not proposing this as a PR. It is a breaking rewrite (WebPart, choose vs Alt.choose, Hopac 0.5.1, no more >>=). Sharing in case anyone still curious about that old discussion wants to poke the demo or the numbers.
Happy to answer questions or close this if it is noise.
All reactions