Scale horizontally using Redis #954
-
Is there any possibility of scaling uWebSockets on multiple instances (for eg. using Redis) as it had been possible in past with Socket.io + the old uws using the io.adapter method?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
It's not more complicated than publishing to Redis every time one of your instances end up publishing to their clients. Then the other instances connected to Redis will also publish to their clients. You don't even need Redis for this, you just need some client and some server to act as "master". I'm pretty sure Kubernetes and the like already has support for master/slave set-ups like this. |
Beta Was this translation helpful? Give feedback.
-
Can you explain more in details? I can't imagine how it gonna work. |
Beta Was this translation helpful? Give feedback.
-
It's actually pretty simple: In your server code you just have to setup a redis PubSub connection or whatever you prefer for message broking... Then, when you want to send a message to a channel, instead of directly sending it, publish on redis pubsub the channel and the message. I'll explain better with the following pseudocode:
Instead of the directly publishing on ws. |
Beta Was this translation helpful? Give feedback.
It's not more complicated than publishing to Redis every time one of your instances end up publishing to their clients. Then the other instances connected to Redis will also publish to their clients.
You don't even need Redis for this, you just need some client and some server to act as "master". I'm pretty sure Kubernetes and the like already has support for master/slave set-ups like this.