Skip to content

Commit

Permalink
Improved documentation on horizontal scaling (Fixes #1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Mar 20, 2023
1 parent 7881091 commit 9d02247
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions docs/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,27 @@ The RabbitMQ queue is configured through the
mgr = socketio.AsyncAioPikaManager('amqp://')
sio = socketio.AsyncServer(client_manager=mgr)

Horizontal Scaling
~~~~~~~~~~~~~~~~~~

Socket.IO is a stateful protocol, which makes horizontal scaling more
difficult. When deploying a cluster of Socket.IO processes, all processes must
connect to the message queue by passing the ``client_manager`` argument to the
server instance. This enables the workers to communicate and coordinate complex
operations such as broadcasts.

If the long-polling transport is used, then there are two additional
requirements that must be met:

- Each Socket.IO process must be able to handle multiple requests
concurrently. This is needed because long-polling clients send two
requests in parallel. Worker processes that can only handle one request at a
time are not supported.
- The load balancer must be configured to always forward requests from a
client to the same worker process, so that all requests coming from a client
are handled by the same node. Load balancers call this *sticky sessions*, or
*session affinity*.

Emitting from external processes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -911,24 +932,6 @@ multi-threaded WebSocket server that is compatible with Werkzeug and Gunicorn's
threaded worker. Other multi-threaded web servers are not supported and will
not enable the WebSocket transport.

Scalability Notes
~~~~~~~~~~~~~~~~~

Socket.IO is a stateful protocol, which makes horizontal scaling more
difficult. To deploy a cluster of Socket.IO processes hosted on one or
multiple servers, the following conditions must be met:

- Each Socket.IO process must be able to handle multiple requests
concurrently. This is required because long-polling clients send two
requests in parallel. Worker processes that can only handle one request at a
time are not supported.
- The load balancer must be configured to always forward requests from a
client to the same worker process. Load balancers call this *sticky
sessions*, or *session affinity*.
- The worker processes need to communicate with each other to coordinate
complex operations such as broadcasts. This is done through a configured
message queue. See the section on using message queues for details.

Cross-Origin Controls
---------------------

Expand Down

0 comments on commit 9d02247

Please sign in to comment.