Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia WebSocket slow to read/write #175

Closed
nordicice opened this issue Aug 23, 2021 · 1 comment
Closed

Julia WebSocket slow to read/write #175

nordicice opened this issue Aug 23, 2021 · 1 comment

Comments

@nordicice
Copy link

I was testing Julia WebSockets and I found that they are much slower than the Python/Node equivalents. I wrote a test to send a ping and measure the time taken for a pong response from some crypto exchanges as an example. Julia consistently takes 50ms for the test below, whereas python takes 2-4 ms. Is this expected?

Julia:

using WebSockets
function main()
WebSockets.open("wss://wsaws.okex.com:8443/ws/v5/public") do ws
for i = 1:100
a = time_ns()
write(ws, "ping")
data, success = readguarded(ws)
b = time_ns()
println(String(data), " ", (b - a) / 1000000)
sleep(0.1)
end
end
end
main()

Equivalent Python:

import websockets
import asyncio
import time

async def main():
uri = "wss://wsaws.okex.com:8443/ws/v5/public"
async with websockets.connect(uri) as websocket:
msg = "hello"
for i in range(101):
a = time.time()
await websocket.send(msg)
x = await websocket.recv()
b = time.time()
print(b-a)
time.sleep(0.1)

asyncio.get_event_loop().run_until_complete(main())

@findmyway
Copy link

Could you try the code in #159 (comment) ?

Based on my test, adding the following two lines will make the performance on par with Python (slightly slower):

using Sockets
using WebSockets

function main()
    WebSockets.open("wss://wsaws.okex.com:8443/ws/v5/public") do ws
        Sockets.nagle(ws.socket.bio, false)
        Sockets.quickack(ws.socket.bio, true)
        for i = 1:100
            a = time_ns()
            write(ws, "ping")
            data, success = readguarded(ws)
            b = time_ns()
            println(String(data), " ", (b - a) / 1000000)
            sleep(0.1)
        end
    end
end

main()

@hustf hustf closed this as completed Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants