Answer the question
In order to leave comments, you need to log in
Storing data between servers, for quick access?
Hi I would like to implement a service using web sockets. I need to remember each socket, store all sockets in an object, select the ones I need and delete the ones I don't need. The problem is that I have implemented clustering and, in connection with this, several processes are running. I wanted to implement it without using redis, i.e. store everything in the master process, but here the problem is not just one server, but several, and balancing through hapProxy, so this option also disappears, how to implement this, for example, using redis or memcached?
I don't want to use redis client and stuff like that because i have a very small task, i don't have data caching, just one middle object, so i want to implement my task like this: i have 4 servers and one load balancer in each of four servers implemented clustering (each server has 4 processes) in total I have 20 processes.
When the balancer redirects the user, let’s say, to server No. 1, then it is on this server that the websocket connection event occurs, and when the connection event occurs, I add the user, i.e., the user’s socket, to the object of all users, i.e., user sockets, but on my server No. 1 now a socket has been added, but it hasn’t been added on other servers, because there was no redirection on these servers, of course you can do it using radish (on a separate server), add a socket to radish with each connection event, and then access this server , but there are a number of downsides.
What I would like to do is: On every connection event I add the user's socket to the object and then send that user's socket to other servers and they add that user's socket to their user's socket object, is this an efficient solution?
But here is a big minus. I will spend a lot of traffic to send the object =(
Answer the question
In order to leave comments, you need to log in
You need to do sharding for sockets. wss:host/channelname => wss:host/serverid/channelname + getServerIdByClientId(clientId) function.
Somewhere like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question