Browse files

Merge pull request #116 from ajdavis/tornado-doc

Recommendations for using Tornado with PyMongo
  • Loading branch information...
2 parents 27d5fe3 + 9de85dc commit 49a748ea4982bf1b43a30db1872a4d3ecaf124dc @behackett committed Mar 30, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 doc/faq.rst
21 doc/faq.rst
@@ -49,6 +49,27 @@ There are asynchronous MongoDB drivers in Python: `AsyncMongo for Tornado
however, these projects are less stable, lack features, and are less actively
+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 <>`_
+ to watch for slow queries.
+- Create a single :class:`~pymongo.connection.Connection` instance for your
+ application in your startup code, before starting the IOLoop.
+- Configure the :class:`~pymongo.connection.Connection` 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 <>`_ or `HAProxy <>`_;
+ when using Tornado with a blocking driver like PyMongo it's recommended you
+ start two or three processes per core instead of one.
What does *OperationFailure* cursor id not valid at server mean?
Cursors in MongoDB can timeout on the server if they've been open for

0 comments on commit 49a748e

Please sign in to comment.