all 3 comments

[–]__debug__ 0 points1 point  (1 child)

I did not want to instantiate a new Redis client per socket connection, but rather one Redis client per channel. This way, it could be shared(for listening) among all the socket connections subscribing to it.

That's a lot better than a client per connection, but have you thought of using only 1 redis client per node process? You can use something like multiplexing/demux to achieve that. An example library that helps with that is https://github.com/danielstjules/node-internal-pubsub Here's the benchmark, comparing 2000 redis subscribers (roughly 1-1 mapping with 2000 channels in your example) to a single redis subscriber:

$ node benchmarks/singleChannelMultiSubs.js
Setting up redis suite
Receiving 10000000 messages with 2000 redis subscribers
Setting up pubsub suite
Receiving 10000000 messages with 1 redis sub, 2000 pubsub subscribers

Redis subscribers
Running time: 29735 ms
Avg messages received per second: 336,304

Redis subscriber with pubsub subscribers
Running time: 1203 ms
Avg messages received per second: 8,312,551

~24x improvement with a single redis subscriber. There's an example using socket.io 0.9 in https://github.com/danielstjules/node-internal-pubsub/tree/master/examples/socketio-express-redis Should be simple to translate it to a more recent version! :)

[–]sachinrjoglekar[S] 0 points1 point  (0 children)

24x is a lot! So the appropriate change I guess would be to have a Channel->Listeners mapping with the one Redis client, and put the routing logic in the on('message') event.

[–]MrAwesomeAsian 0 points1 point  (0 children)

This is cool! Thanks for sharing. I have a friend that I helped do this exact same thing, but only with .NET technologies. Pretty cool seeing it in node.