Browse Source

Added docs on websocket support with gevent

pull/5/head
Miguel Grinberg 10 years ago
parent
commit
b59cefcfdb
  1. 28
      docs/index.rst
  2. 3
      setup.py

28
docs/index.rst

@ -248,29 +248,44 @@ Gevent
~~~~~~ ~~~~~~
`Gevent <http://gevent.org>`_ is another asynchronous framework based on `Gevent <http://gevent.org>`_ is another asynchronous framework based on
coroutines, very similar to eventlet. Only the long-polling transport is coroutines, very similar to eventlet. An Socket.IO server deployed with
currently available when using gevent. gevent has access to the long-polling transport. If project
`gevent-websocket <https://bitbucket.org/Jeffrey/gevent-websocket/>`_ is
installed, the WebSocket transport is also available.
Instances of class ``socketio.Server`` will automatically use gevent for Instances of class ``socketio.Server`` will automatically use gevent for
asynchronous operations if the library is installed and eventlet is not asynchronous operations if the library is installed and eventlet is not
installed. To request gevent to be selected explicitly, the ``async_mode`` installed. To request gevent to be selected explicitly, the ``async_mode``
option can be given in the constructor:: option can be given in the constructor::
eio = socketio.Server(async_mode='gevent') sio = socketio.Server(async_mode='gevent')
A server configured for gevent is deployed as a regular WSGI application, A server configured for gevent is deployed as a regular WSGI application,
using the provided ``socketio.Middleware``:: using the provided ``socketio.Middleware``::
app = socketio.Middleware(eio) app = socketio.Middleware(sio)
from gevent import pywsgi from gevent import pywsgi
pywsgi.WSGIServer(('', 8000), app).serve_forever() pywsgi.WSGIServer(('', 8000), app).serve_forever()
An alternative to running the eventlet WSGI server as above is to use If the WebSocket transport is installed, then the server must be started as
follows::
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
app = socketio.Middleware(sio)
pywsgi.WSGIServer(('', 8000), app,
handler_class=WebSocketHandler).serve_forever()
An alternative to running the gevent WSGI server as above is to use
`gunicorn <gunicorn.org>`_, a fully featured pure Python web server. The `gunicorn <gunicorn.org>`_, a fully featured pure Python web server. The
command to launch the application under gunicorn is shown below:: command to launch the application under gunicorn is shown below::
$ gunicorn -k gevent -w 1 module:app $ gunicorn -k gevent -w 1 module:app
Or to include WebSocket::
$ gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 module: app
Same as with eventlet, due to limitations in its load balancing algorithm, Same as with eventlet, due to limitations in its load balancing algorithm,
gunicorn can only be used with one worker process, so the ``-w 1`` option is gunicorn can only be used with one worker process, so the ``-w 1`` option is
required. Note that a single eventlet worker can handle a large number of required. Note that a single eventlet worker can handle a large number of
@ -316,6 +331,9 @@ 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 up to two outstanding requests at any given time. The Werkzeug server is
single-threaded by default, so the ``threaded=True`` option is required. single-threaded by default, so the ``threaded=True`` option is required.
Note that servers that use worker processes instead of threads, such as
gunicorn, do not support a Socket.IO server configured in threading mode.
Multi-process deployments Multi-process deployments
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~

3
setup.py

@ -25,8 +25,7 @@ setup(
platforms='any', platforms='any',
install_requires=[ install_requires=[
'six>=1.9.0', 'six>=1.9.0',
'eventlet>=0.17.4', 'python-engineio>=0.6.0'
'python-engineio>=0.5.0'
], ],
tests_require=[ tests_require=[
'mock', 'mock',

Loading…
Cancel
Save