flask-socketio one room per user ? expensive?
Asked Answered
R

1

6

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 ?
Recreation answered 23/2, 2015 at 10:22 Comment(1)
Assuming that 1 user = 1 websocket connection and that you are in fact using socket.io, you won't need to instantiate a new room manually every time a new user connects; socket.io automatically creates unique room for each connection.Larose
B
10

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.

Breastbone answered 24/2, 2015 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.