#๐Ÿ”’ Its my first time using websockets and I need help making them faster

24 messages ยท Page 1 of 1 (latest)

digital inlet
#

Its my first time using websockets with fastAPI and requests, Currently, I'm trying to display dots that change every 0.05 seconds based on API data but i just cant get the frequency to drop below 2 seconds. Its so slow and and I'm not sure what to do.
I've tried chunking and compression and neither of these methods work, is anyone able to suggest other ideas? I can share my code if you need specifics

fickle atlasBOT
#

@digital inlet

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

past canyon
digital inlet
#

yes, is this not feasible?

past canyon
#

I've never pushed websockets that far, but that seems incredibly frequent.

digital inlet
#

yes, i know it is very frequent, perhaps it is not the correct way to go about it. If you have any suggestions to solutions on alternate methods to solve this problem that would be greatly appreciated

quartz patio
#

are you saying that you are using the requests library in the same code as fastapi?
if that is so, you might have blocking code waiting for the requests functions/methods to return and you would probably be better off using an async library such as httpx or aiohttp to make the requests from the fastapi code

digital inlet
#

what does zlib do?

digital inlet
#

going to try improve further using compression now

humble bane
#

Probably compression will slow it down

#

Could you try SSE instead of websockets?

quartz patio
humble bane
#

With SSE you could use hypercorn with quic support

#

Also make sure you're pooling your http request connections using FastAPI lifespan_context

digital inlet
humble bane
#

SSE is server sent events

digital inlet
#

what are the benifits compared to websockets?

humble bane
#

They tunnel inside http2 and quic

fickle atlasBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.