Replies: 7 comments 2 replies
-
You would have to find a way to communicate events between your workers - you might want to have a look at https://github.com/encode/broadcaster If you need something easy to integrate with FastAPI but that is more robust, supported by Redis, PostgreSQL or others, check encode/broadcaster." |
Beta Was this translation helpful? Give feedback.
-
I have successfully implemented a FastAPI server with multiple workers and web sockets using Async socketio with redis for sharing between processes. https://pypi.org/project/fastapi-socketio/ If I remember correctly I had to tweak the library to allow for async but I can't remember exactly what I had to do. Sorry. Hope this is helpful. |
Beta Was this translation helpful? Give feedback.
-
back to topic, has anyone ever found a solution to this? it's been almost 3 years and i still didn't manage to achieve this. |
Beta Was this translation helpful? Give feedback.
-
no example on how to implement multiple workers with websocket? |
Beta Was this translation helpful? Give feedback.
-
This is a very good write up on how to implement similar with Websockets and Redis Pub/Sub capabilities to allow horizontal scaling of application and worker servers. |
Beta Was this translation helpful? Give feedback.
-
I just ran into this problem where I created a web socket manager class responsible for handling all the web sockets with unique identifier. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
I'm using the example from FastAPI documentation for websockets, everything works fine while i have only 1 worker on my app, but when i set back 4 workers, seems that each worker has his own
app
instance.How can i manage websockets within multiple workers? Each time i save a connection on the Manager class, it seems to be saved only in one random app instance, no way to save it for each
app
instance for each worker?Operating System
Linux
Operating System Details
No response
FastAPI Version
0.68.1
Python Version
3.9.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions