I have developed multiplayer turn-based application on Node Js using socket.io and redis pub/sub.
Brief regarding my implementation are as follows:
Multiplayer turn-based game scaled over ALB using socket.io-redis adapter for redis pub-sub.
My concurrent user base is around ~0.4 Million so I need to scale redis pub-sub as that is a single node as well.
I went through below Links:
https://www.youtube.com/watch?v=6G22a5Iooqk
https://groups.google.com/forum/#!topic/redis-db/B0_fvfDWLGM
Can anyone elaborate how should I proceed for this.
Related
I am currently working on an application with the current tech stack:
Backend:
Mongoose
Express
Apollo
GraphQL
Frontend:
Vuejs
Apollo
GraphQL
So since I am a beginner with GraphQL I had no idea that apollo's inbuilt subscribe PubSub cannot be used in production and has no method of scaling without using services like Redis.
That being said, I have started a local Redis server for testing it, I managed to start a Redis Client in the backend using ioredis and it connects fine to the Redis server. I have now a problem that I can't start this up on my Vue frontend in order to receive messages being published by my backend. The creator of ioredis suggested that it is only for backends and I should use something else for the frontend.
I am currently confused as to how should I go about listening or subscribing to the redis server from my Vue frontend so I can receive published messages? Maybe I am looking at this in the wrong way? Any help would be appreciated.
Note: I have already done this with apollo/graphql's inbuilt subscribe but like mentioned, it can't be scaled.
Okay so multithreading nodeJS isn't much problem from what I've been reading. Just deploy several identical apps and use nginx as reverse proxy and load balancer of all the apps.
But actually native cluster module works pretty well too, I found.
However, what if I have socket.io with the nodeJS app? I have tried the same strategy with nodeJS + socket.IO; however, it obviously did not work because every socket event emitted will be more or less evenly distributed and sockets other than the one that made the connection would have no idea where the request came from.
So best method I can think of right now is to separate nodeJS server and socket.IO server. Scale nodeJS server horizontally (multiple identical apps) but just have one socket.IO server. Although I believe it would be enough for the purpose of our solution, I still need to look out for future. Has anyone succeeded in horizontally scaling Socket.IO? So multiple threads?
The guidelines on the socket.io website use Redis with a package called socket.io-redis
https://socket.io/docs/using-multiple-nodes/
Looks like is just acts like a single pool for the connections, and each node instance connects to that.
Putting your socket server on a separate service (micro-service) is a probably fine, the downside is needing to manage communications between the two instances.
I'm struggling with socket.io to make a chat app with the users that are logged in in my app. I followed the beginner course and I could make a private chat app, but the users aren't the ones that are in my database or they have to create a username to connect to the chat app.
In my search I found this one -
Realtime app with Vue, Laravel, Socket.io and Redis (He's making a similar app using Laravel)
I want the exact same app but using nodejs mongoose express.
Can you help me with some references or tutorials?
Here are some resources that might -
Make A Real-Time Chat Room using Node Webkit, Socket.io, and MEAN
Simple Chat Application using NodeJS and Socket.IO
Please start with any of these and be more specific with what extra feature you're trying to implement. (code would be very helpful)
Couldn't understand what do you mean by the users not in database bit.
Can I use a redis cluster transparently (without writing any client side code for the redis cluster) with socket-io-redis instead of a single redis server as the default examples state? Unfortunately, there seems to be no official documentation on this.
Also, without a redis cluster, how many users can socket.io servers support with a single redis server as socket.io-redis backend?
Update:
Socket.io-redis allows specification of redis clients to use. May be some node_redis compatible redis client which also has support for redis clusters can be used? ioredis (the only other full featured/recommended client) has support for redis clusters but I am not sure if it's compatible with the node_redis client. Does anyone have some info on it or other possible solutions?
Note: I know Redis cloud provides scaling solution with a single endpoint paradigm but I need a cluster solution.
The module socket.io-ioredis allows use of ioredis with socket.io. Ioredis can connect to a redis cluster. However, I have, so far, only used socket.io-ioredis with socket.io with a single node server and single redis instance and it's working okay in this configuration.
i am playing around with nodejs and would like to get some guide on how to benchmark concurrent connections on a websocket in nodejs using things like nowjs, socket.io and etc.
Check out siobench.