Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis PUBLISH/SUBSCRIBE limits

I'm considering Redis for a section of the architecture of a new project. It will consist of a lot of clients (node.js connections) SUBSCRIBING to particular keys with one process PUBLISHING to those keys as needed.

I'm curious about the limits of the PUBLISH/SUBSCRIBE commands and how to mitigate those. An obvious limit is the amount of file descriptors open on the machine with Redis so at some point I'll need to implement Master-Slave or Consistent Hashing to multiple Redis instances.

Does anyone have any solutions about how to scale this architecture with Redis' PubSub?

like image 685
mistagrooves Avatar asked Jun 28 '11 19:06

mistagrooves


People also ask

What is Redis publish and subscribe?

Advertisements. Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel. In Redis, a client can subscribe any number of channels.

How many channels can Redis have?

So the Data collector is always running, it retrieves the trades and sends them to the channel; there is one channel for every market (600+).

Is Redis publish blocking?

Redis' pub/sub sends messages to clients subscribed (listening) on a channel. If you are not listening, you will miss the message (hence the blocking call). If you want to have it non-blocking, I recommend using a queue instead (redis is pretty good at that too).

Is Redis Pub/Sub fast?

Redis Pub/Sub is designed for speed (low latency), but only with low numbers of subscribers —subscribers don't poll and while subscribed/connected are able to receive push notifications very quickly from the Redis broker—in the low ms, even < 1ms as confirmed by this benchmark.


1 Answers

Redis PubSub scales really easily since the Master/Slave replication automatically publishes to all slaves.

The easiest way is to load balance the connections to node.js with for instance HAProxy, run a Redis slave on each webserver that syncs with a single master that publishes the messages.

I can't give you exact numbers since that greatly depends on the underlying system, but this should scale extremely well. And you don't need to manage the clients and which server they connect to manually. You obviously need some way to handle session state, so you might need to do that anyway, but that's a lot easier to do in the load balancer than in your application.

like image 129
Kamiel Wanrooij Avatar answered Jan 03 '23 04:01

Kamiel Wanrooij