Skip to content

Commit

Permalink
Document WebSocket support for threading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Apr 18, 2021
1 parent 0cc35ce commit 2f085b3
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions docs/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Socket.IO servers to integrate easily into existing WSGI or ASGI applications::
Serving Static Files
--------------------

The Engine.IO server can be configured to serve static files to clients. This
The Socket.IO server can be configured to serve static files to clients. This
is particularly useful to deliver HTML, CSS and JavaScript files to clients
when this package is used without a companion web framework.

Expand Down Expand Up @@ -832,8 +832,7 @@ Standard Threads
While not comparable to eventlet and gevent in terms of performance,
the Socket.IO server can also be configured to work with multi-threaded web
servers that use standard Python threads. This is an ideal setup to use with
development servers such as `Werkzeug <http://werkzeug.pocoo.org>`_. Only the
long-polling transport is currently available when using standard threads.
development servers such as `Werkzeug <http://werkzeug.pocoo.org>`_.

Instances of class ``socketio.Server`` will automatically use the threading
mode if neither eventlet nor gevent are not installed. To request the
Expand All @@ -854,15 +853,22 @@ development web server based on Werkzeug::
# ... Socket.IO and Flask handler functions ...

if __name__ == '__main__':
app.run(threaded=True)
app.run()

The example that follows shows how to start an Socket.IO application using
Gunicorn's threaded worker class::

$ gunicorn -w 1 --threads 100 module:app

When using the threading mode, it is important to ensure that the WSGI server
can handle multiple concurrent requests using threads, since a client can have
up to two outstanding requests at any given time. The Werkzeug server is
single-threaded by default, so the ``threaded=True`` option is required.
With the above configuration the server will be able to handle up to 100
concurrent clients.

Note that servers that use worker processes instead of threads, such as
gunicorn, do not support a Socket.IO server configured in threading mode.
When using standard threads, WebSocket is supported through the
`simple-websocket <https://github.com/miguelgrinberg/simple-websocket>`_
package, which must be installed separately. This package provides a
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
~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 2f085b3

Please sign in to comment.