Replies: 1 comment
-
Hello @SOG-web I am author of https://github.com/centrifugal/centrifuge and https://github.com/centrifugal/centrifugo and the thing you are doing is very similar to what those projects provide and to what I've spent enough of my time for. Basically: multiplexing of subscriptions over client connection, scalability over Redis and even integration with PostgreSQL outbox (which looks very similar to your mutations stream goal). I am not sure whether you are doing this for educational purposes or not. If yes – maybe take a look at source code of projects I pointed and probably you will find some useful ideas. If you are developing for non-educational – then you can just use Centrifuge library (it uses a recent fork of Gorilla WebSocket btw) or Centrifugo (which is built on top of Centrifuge library and provides more features at the cost of being self-contained standalone server with its own rules and mechanics). Now closer to your question. I'd say that broadcasting messages each in a separate goroutine is not a good approach. I'd suggest having 2 goroutines per connection. One reads messages from the connection, and another writes message to the connection by reading from a per-connection queue (a-la mailbox). This allows to achieve reasonably fast broadcasts (where you just put the message into individual connection queue) without making a separate goroutine for each message, which looks rather unpredictable. |
Beta Was this translation helpful? Give feedback.
-
I have a situation of needing to send 10k ws at a time in my project. I am looking for the best way to implement this as I want it to be performant
I currently have two implementation, please I want suggestions on which will work best or any other suggestion on how to get the result with minimal resource usage
Am using this ws to create realtime update for my db per table and the redis is use to manager clients across all server instance(in case of horizontal scaling with kuberneties)
Also am using echo as my web server
Beta Was this translation helpful? Give feedback.
All reactions