Uploaded image for project: 'ListenBrainz'
  1. ListenBrainz
  2. LB-1004

Improve websocket server setup in local development and production

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • None
    • None

      Earlier this year we moved the socket.io websockets server to listenbrainz.org/socket.io (instead of socket.listenbrainz.org) so that we could use same-domain cookies to authenticate the endpoint.

      We still run a separate container/process for the socket.io server. This uses a dummy flask app and connects the socket.io server to it. This process also starts a background thread that listens to rabbitmq messages and if it's a listen message, forwards it to socketio (so that it's sent to the frontend).

      I have a feeling that this could be improved and that we could remove the ws server, but I'm not 100% sure of the steps.

      • It should be possible to connect the socket.io server to the main flask app and host it with uwsgi's ws server: https://flask-socketio.readthedocs.io/en/latest/deployment.html#uwsgi-web-server
      • However, keep in mind the additional comments on this page about running multiple workers. Perhaps it doesn't make sense for us to have 200 workers (the same number as uwsgi web workers)
      • If we keep the separate socket.io server, I'd like to see if there is a way to avoid the use of the separate thread to process rabbitmq messages. It'd be nice to be able to send these messages directly to socket.io directly from the listen writer (or API in the case of listening now). I'm not sure if there's a way of configuring socket.io with a backing queue and pushing directly to this instead
      • In local development, we should try and run the socket.io server in the main webserver container (with the same points above about sending listen events from an external thread)

            Unassigned Unassigned
            alastairp Alastair Porter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Version Package