Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask-socketio one room per user ? expensive?

I have a flask webapp running pandas to do some data analysis on the backend.

Right now, i took the naive approach of using AJAX for user to send queries back to the server and interact with the data. but as it turns out there is a lot of overhead with each request and everytime i need to reload the data into pandas/memory which is very repetitive.

I was thinking socketio could be of good use here - I would open up a socket connection and this way once the file is loaded into pandas, the user could interact and query the data more responsively with less overhead through the socket.

So my question right now is:

  • Should I open up a room for every user as the users dont need to interact with each other ?
  • Does this scale - opening up a room per user ?
  • Where does namespace fit in here ? Do I assign namespace to different sections of the website and further open up rooms under each namespace for each user ?
  • Or Should I spawn a monkey patched thread ? Greenlet per user ?
like image 253
Shankar ARUL Avatar asked Feb 23 '15 10:02

Shankar ARUL


1 Answers

Opening a room per user is a valid solution that I usually recommend as a way to easily be able to address individual users in server-pushed messages.

The rooms are held in a Python data structure in memory, so they are only expensive in that they use a little bit of memory. I have not measured the amount per user, but it is probably just a few bytes on top of the room name.

The namespace is used to multiplexing multiple different connections into one physical channel. If you just have one connection, then just use the same namespace for everything. You should use multiple namespaces if, for example, you have two client-side apps in your page (such as angular apps), each with its own set of event handlers. Other than that there is no reason to use more than one namespace.

Hope this helps.

like image 61
Miguel Avatar answered Oct 10 '22 16:10

Miguel