I’m sure I’m doing something silly and wrong, I’m just not sure what.
In the following two MWE, a server is sending a 1 MB payload a hundrad times to one client, all within the same Julia session (v1.10.0
single thread).
The HTTP.WebSockets
(HTTP v1.10.1
) are performing 6 times worse than Oxygen.jl
(v1.4.5
), and I’m not sure why. I thought websockets were supposed to be faster than http requests…?
Here’s the websocket MWE:
using HTTP.WebSockets
const payload = Vector{UInt8}(undef, 10^6) # 1 MB
server = WebSockets.listen!("127.0.0.0", 8000) do ws
for msg in ws
send(ws, payload)
end
end
n = 100
WebSockets.open("ws://127.0.0.0:8000") do ws
send(ws, UInt8(1))
t = @elapsed begin
for (_, msg) in zip(1:n, ws)
send(ws, UInt8(1))
end
end
fps = n/t
@show fps
end;
and here’s the oxygen one:
using Oxygen
using HTTP
const payload = Vector{UInt8}(undef, 10^6) # 1 MB
@get "/" function(req::HTTP.Request)
binary(payload)
end
Threads.@spawn serve()
n = 100
t = @elapsed begin
for i in 1:n
HTTP.open("GET", "http://127.0.0.1:8080/") do io
while !eof(io)
read(io, 10^6)
end
end
end
end
fps = n/t
@show fps