Skip to content

Should connections be thread safe? #2082

Open

Description

@coffeemug

I just talked to some folks who are using Rethink with a Python client. At some point they added some multiprocessing, and started getting weird issues. After a while, they had a hunch that connections may not be thread safe, so they started opening a connection per thread. That fixed things for them.

So the obvious question here is whether connections should be thread safe. If not, we need to add better documentation (but I think we should answer this question first). I'd like to see what the state of the art on this is for other NoSQL systems.

Activity

  1. added this to the milestone on Mar 11, 2014
  2. neumino commented on Mar 11, 2014

    @neumino
    Member

    We could provide a connection pool that is thread safe maybe?

  3. coffeemug commented on Mar 11, 2014

    @coffeemug
    ContributorAuthor

    Related to #281.

  4. mlucy commented on Mar 11, 2014

    @mlucy
    Member

    An intermediate option would be detecting when one connection is accessed from multiple threads and erroring.

  5. wojons commented on Mar 12, 2014

    @wojons
    Contributor

    @coffeemug i ran into this a while ago in my php code i simple create a shared memory segement for each connection so if i have a few forks running and they are aware of other conenctions they will try it but will just creata new one if they have to.

  6. matanox commented on Mar 16, 2014

    @matanox

    In node.js, being an evented server, wouldn't a connection be unsafe the same as in a multi-threaded environment? the way node.js programming works, it would be quite hard to keep track of queuing work for a connection so that it is only used linearly. Practically meaning that would mean opening a connection per query, rather than engineering non-blocking code to serialize queries, wouldn't it?

    It is very unproductive to serialize access to a connection in the node.js programing paradigm...

    Is it confirmed that rethinkdb is not thread safe right now? that would mean it's not node.js safe unless each query uses its own connection wouldn't it?

  7. neumino commented on Mar 16, 2014

    @neumino
    Member

    The connections with the node.js driver are "event" safe.

    You can fire query1 then query2 without waiting query1 to return.
    You won't receive the results for query2 before the results for query1 though.

    So while it works, you probably don't want to use a single connection but one connection per query (opening one connection per query, or re-using connections with a pool).

  8. matanox commented on Mar 17, 2014

    @matanox

    Why actually would I want numerous connections with node.js? each connection has overheads in waiting for it to open, and in memory allocations on both ends, so why would it not be recommended to reuse one?
    Thanks!

  9. wojons commented on Mar 17, 2014

    @wojons
    Contributor

    @matanster from my guess i am thinking what this means is that if you have a really big long query on the same same connection started before a super fast short query the long blocking querying wil make the short one be delayed so if you had one connection per query/request you will get less blacking

  10. matanox commented on Mar 17, 2014

    @matanox

    Makes sense @wojons, and happy to hear @neumino!
    Me and rethinkdb are back on now, but I still feel like a very early adopter :) please avoid adding too many features but rather focus on making everything common just work well and robust... too many features make the basics slower and inflate documentation and user group forums. Excuse the plug..

  11. coffeemug commented on Mar 17, 2014

    @coffeemug
    ContributorAuthor

    @matanster -- thanks for chiming in with more general feedback, it helps prioritize things a lot. Would you mind taking a few minutes to write down which parts of RethinkDB still feel like rough edges? It would help immensely. Feel free to email your feedback to me ([email protected]) if it's too rough for github issues.

  12. coffeemug commented on May 21, 2014

    @coffeemug
    ContributorAuthor

    Closing as dup of #2427 (that one has more information).

  13. coffeemug commented on May 21, 2014

    @coffeemug
    ContributorAuthor

    Err, I guess #2427 is python specific, while this issue encompasses all drivers. Reopening.

  14. modified the milestones: , subsequent on Sep 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions