Skip to content

Commit

Permalink
Update Tornado and Twisted recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis authored and behackett committed Mar 23, 2013
1 parent 59f30ba commit bd57514
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
38 changes: 6 additions & 32 deletions doc/faq.rst
Expand Up @@ -38,41 +38,15 @@ Starting with version 2.2 PyMongo supports Python 3.x where x >= 1. See the

Does PyMongo support asynchronous frameworks like Gevent, Tornado, or Twisted?
------------------------------------------------------------------------------
The only async framework that PyMongo fully supports is `Gevent
<http://www.gevent.org/>`_.

Currently there is no great way to use PyMongo in conjunction with `Tornado
<http://www.tornadoweb.org/>`_ or `Twisted <http://twistedmatrix.com/>`_.
PyMongo provides built-in connection pooling, so some of the benefits of those
frameworks can be achieved just by writing multi-threaded code that shares a
:class:`~pymongo.mongo_client.MongoClient`.
PyMongo fully supports :doc:`Gevent <examples/gevent>`.

There are asynchronous MongoDB drivers in Python: `Motor for Tornado
<https://github.com/mongodb/motor>`_ and `TxMongo for Twisted
<http://github.com/fiorix/mongo-async-python-driver>`_. Compared to PyMongo,
however, these projects are less stable, lack features, and are less actively
maintained.

It is possible to use PyMongo with Tornado, if some precautions are taken to
avoid blocking the event loop:

- Make sure all MongoDB operations are very fast. Use the
`MongoDB profiler <http://www.mongodb.org/display/DOCS/Database+Profiler>`_
to watch for slow queries.
To use MongoDB with `Tornado <http://www.tornadoweb.org/>`_ see the
`Motor <https://github.com/mongodb/motor>`_ project.

- Create a single :class:`~pymongo.mongo_client.MongoClient` instance for your
application in your startup code, before starting the IOLoop.

- Configure the :class:`~pymongo.mongo_client.MongoClient` with a short
``socketTimeoutMS`` so slow operations result in a
:class:`~pymongo.errors.TimeoutError`, rather than blocking the loop and
preventing your application from responding to other requests.

- Start up extra Tornado processes. Tornado is typically deployed with one
process per CPU core, proxied behind a load-balancer such as
`Nginx <http://wiki.nginx.org/Main>`_ or `HAProxy <http://haproxy.1wt.eu/>`_;
when using Tornado with a blocking driver like PyMongo it's recommended you
start two or three processes per core instead of one.
For `Twisted <http://twistedmatrix.com/>`_, see `TxMongo
<http://github.com/fiorix/mongo-async-python-driver>`_. Compared to PyMongo,
TxMongo is less stable, lack features, and is less actively maintained.

What does *OperationFailure* cursor id not valid at server mean?
----------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions doc/tools.rst
Expand Up @@ -113,9 +113,6 @@ These are alternatives to PyMongo.

* `Motor <https://github.com/mongodb/motor>`_ is a full-featured, non-blocking
MongoDB driver for Python Tornado applications.
* `asyncmongo <https://github.com/bitly/asyncmongo>`_ is an asynchronous library
for accessing mongo which is built on the Tornado IOLoop, but doesn't support
to replica sets.
* `TxMongo <http://github.com/fiorix/mongo-async-python-driver>`_ is an
asynchronous Python driver for MongoDB, although it is not currently
recommended for production use.

0 comments on commit bd57514

Please sign in to comment.