3

I'm starting out with rethinkdb in python, and taking a look at the different approaches:

  1. Blocking approach with threads
  2. Non-blocking, callback-based approach with Tornado
  3. Greenlet-based approach with gevent

In the first case, the natural thing to do is to give each thread a connection object. In the second and third cases, however, I don't quite get it.

With tornado and gevent, how and when should I create connections? How many should I have around?

salezica
  • 74,081
  • 25
  • 105
  • 166
  • One thing you have to consider with gevent is that is not working on python 3 and I doubt it will be ever ported. Of course there are some forks out there that may be work but I am not very hopeful for future support. May be this takes one parameter out of the equation and makes your decision a little simpler. :-) – nickmilon Apr 19 '15 at 00:03

1 Answers1

6

If you're using a non-blocking library, one connection should be sufficient in RethinkDB 2.0 (prior to 2.0 there was less per-connection parallelism). Per-connection overhead is pretty low, though. Some people open a connection per query and even that isn't too slow, so you should just do whatever's easiest.

EDIT: This advice is now outdated. For newer versions of RethinkDB using one connection per query is strongly discouraged. One connection per thread is still fine.

mlucy
  • 5,249
  • 1
  • 17
  • 21