Eugene Soldatov
Eugene Soldatov

Reputation: 10135

Tornado sockets using redis sub\pub

I need advice about performance using web-sockets together with redis pub/sub channels. I use tornado as web-server.

I have about 100 clients which listen status of some event. Each client have separate event and need to listen only own event. Socket connection is short-live, something about 1-20 seconds. I see two options:

  1. Create separate pub/sub channel in redis for each socket-event pair. In this case I will have many channels.

  2. Create one pub/sub channel, subscribe all clients to it and filter messages in controller to forward them to appropriate client. In this case I have many clients which listen one channel.

Which of these options is better for performance?

Upvotes: 0

Views: 822

Answers (1)

MK Yung
MK Yung

Reputation: 4581

Case 1)

Assume you have M clients, each client subscribes to only one channel (and not subscribe to pattern), then the complexity for publishing N msg is O(N).

Case 2)

Assume you have M clients subscribed to one channel, all the clients receive N messages. The publish and filtering process complexity is O(MN).

So you should choose Case 1. Case 1 is faster because it is always constant time for redis to publish a message to a channel (unless it is a pattern)

Read about redis publish time complexity here

Upvotes: 1

Related Questions