0

I am new to redis and I noticed that all the services online have different numbers of connections depending on price. I am also wondering about how much memory is necessary for a real time chat app where no chat data needs to be stored.

For example one service gives 25MB and 10 connections for free.

I am building a chat app and I am using nodejs/mongodb/socketio. I create the connection to the db when the app loads and thats it. Is there more than one connection there happening in the background? If two people connect to my app at the same time and invoke some function that requires a database connection does that mean that two connections are being used? This isn't something I have even considered before.

And more specifically seeing as my app is using socketio and I am thinking about using redis does the amount of redis connection correlate in anyway with the amount of websocket connections or are they completely separate things?

And regarding memory. I understand that data stored in redis can be set to expire and will auto delete once it has expired. How fast will it delete stuff? Even the smallest 25MB seems to be huge in terms of a real time app. Is it possible to say give data an expiry time of 1 or 2 minutes to keep the db size low?

It seems that for a live chat app 25MB is actually pretty big. Are lots of connections necessary? If so why don't any of the redis services offer small db size with large connection amounts?

Paulie
  • 1,567
  • 4
  • 16
  • 21

1 Answers1

0

One connection for your "subscriber" and one for your "publisher". The publisher pushes messages onto a channel or queue and the subscriber pops a queue or listens to a channel. I some apps on a linode with 512mb of ram just fine. If you are using socket.io, there is bus.io which builds a distributed message bus onto of redid and socket.io. Check it out https://www.npmjs.org/package/bus.io

Nathan Romano
  • 7,016
  • 3
  • 19
  • 18
  • So in my socketio app I have rooms. Would it be correct to say that everyone who connects to a room would use one connection as (subscriber) and the room would take one connection (as the publisher). And these connections are always open? Bearing in mind that in my app a user can connect to multiple rooms does this not makes the redis services online which charge $70 for 1024 connections look like a bad option. It seems it would be better to just use a full cloud service like linode/digitalocean and install redis myself where connections are presumably(?) unlimited and for much less money. – Paulie Jun 10 '14 at 17:27
  • I don't believe each socket connection open a connection to redis. There is one redis client for publishing data and one for receiving data. I know with bus.io it is a message bus onto of socket.io it uses one connection for publishing an done for subscribing. A socket connection simply attaches / detaches a listener whenever it connects or disconnects. It does not open a new connection. – Nathan Romano Jun 10 '14 at 18:15
  • I'm looking at redis is for scaling my sio app across multiple servers. Just the response in [this thread](http://stackoverflow.com/questions/9267292/examples-in-using-redisstore-in-socket-io) It says that you would have one client per worker which presumably could be one worker per cluster node. So in my case rather than cluster I would be scaling to different servers so I would need one client per server. This number is likely never to exceed 5 or 10 clients so it seems I would only need a very few connections in total. But this makes me confused why anyone would need 1000s connections? – Paulie Jun 10 '14 at 18:50
  • If you may checkout bus.io it does exactly what you are trying to accomplish. It will scale out your app across redis using socket.io. Each app instance will have a connection for publishing, subscribing, and pushing/pulling from a queue. You won't need tons of connections. – Nathan Romano Jun 10 '14 at 19:00
  • Thanks for the info. I had a look at bus io and I found it confusing. I tried to install the chat demo and I get a lot of errors when running npm install to get the dependencies (I am on windows 7). I had to install python which got rid of a lot of the errors but it still stays it cannot find bus.io when running the app. Looking at the client code it seems it is pure socket js. There is nothing about bus io on the end client side correct? – Paulie Jun 10 '14 at 22:45
  • Yes you use socket.io on the client. And the server you use bus.io(). When your app runs the instance(s) connect to a redis queue and a redis pub sub. The clients emit events. Bus.io captures them and turns them into messages that go to the queue. The queue dispatches messages to the app instances for processing. After they are processed they get delivered to the target. – Nathan Romano Jun 10 '14 at 22:59
  • Which part do you find confusing? – Nathan Romano Jun 10 '14 at 22:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55402/discussion-between-nathan-romano-and-paulie). – Nathan Romano Jun 10 '14 at 23:38
  • The demo app requires you to npm install too – Nathan Romano Jun 11 '14 at 05:46
  • I recently published bus.io-client that bus.io uses. You can still use the socket.io-client in the browser or use the bus.io-client. – Nathan Romano Jul 02 '14 at 17:43