How to share DATA between multi worker

I have a websocket service,for collect ws clients and then send msg to these clients,
I use Queue (app.quename=collections.deque()) collects the websocket client,
The Issue is:when i run sanic app with worker>1,some of the msgs received by the client lost.
And then I id() the quename,between the different workers are the same.

That makes sense because they are separate processes. Sharing data between processes can be tricky, but I have found one of the best solutions (happy to share others) is to use a pub/sub.

Here is a working example: https://gist.github.com/ahopkins/9816b39aedb2d409ef8d1b85f62e8bec

Thanks a lot for your suggestion.

1 Like

Do you have any benchmark numbers on using pubsub vs not? Id be pretty interested in seeing that.

What is the alternative? Polling?