JuliaWeb / HTTP.jl

HTTP for Julia
https://juliaweb.github.io/HTTP.jl/stable/
Other
626 stars 177 forks source link

Websocket performance optimization #1140

Closed lassepe closed 1 month ago

lassepe commented 5 months ago

By default, HTTP.WebSockets uses a TCP socket configuration that is rather slow:

However, if one disables Nagel's algorithm on the tcp socket, the Julia implementation is on par. In fact, with the tuned socket below I get Julia to 1e-5s response time.

function server()
    server = WebSockets.listen!("127.0.0.1", 8081) do ws
       # without these options below, the socket is way too slow.
        Sockets.nagle(ws.io.io, false)
        Sockets.quickack(ws.io.io, true)

        for msg in ws
            WebSockets.send(ws, msg)
        end
    end
end

Proposal: It would be nice to make this tuning the default and expose some relevent settings via the keywords of HTTP.WebSockets.listen! and HTTP.WebSockets.open.

lassepe commented 1 month ago

Xref: https://brooker.co.za/blog/2024/05/09/nagle.html

quinnj commented 1 month ago

SGTM! Mind making a PR?