Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalability of tornado websocket chat

Tags:

python

tornado

In the tornado websocket chat example, participants are stored in the set (link) , it is convenient in the case of a single server. But if run multiple instances of the application and nginx as a load balancer, how in this case, better to store the participants?

like image 508
saniaxxx26 Avatar asked Jun 03 '13 09:06

saniaxxx26


1 Answers

You may consider using the pubsub feature of Redis. (link)

Edit :

When your clients log on to your chatroom, they can subscribe to a channel, say chatroom. It does not matter which tornado instances they are using. Using this module you can keep asynchronously listening to the channel.

If another client sends a message to your chatroom (that is publish a message to the channel chatroom), all tornado instances will automatically sends the messages to those who subscribed to the channel. Then you can send the message via websocket.

You can take a look at this demo for the example.

like image 150
MK Yung Avatar answered Sep 19 '22 14:09

MK Yung