我应该关闭 rethinkDB 中与数据库的每个连接吗?

should I close each connection to the DB in rethinkDB?

我在 python 中内置了一个服务器,使用 Tornado 和 RethinkDB。 运行 很长一段时间以来,每个用户都打开了多个与数据库的连接。让它们打开 - 从不关闭它们 - 我从来没有遇到任何重大问题。但是查看日志文件我发现有很多这样的警告:

File "/home/bundleroot/commentserver/app.py", line 30, in <module>
        db_connection = r.connect(RDB_HOST,RDB_PORT) 
      File "/home/bundleroot/commentserver/env34/lib/python3.4/site-packages/rethinkdb/net.py", line 542, in connect
        return conn.reconnect(timeout)
      File "/home/bundleroot/commentserver/env34/lib/python3.4/site-packages/rethinkdb/net.py", line 475, in reconnect
        return self._instance.connect(timeout)
      File "/home/bundleroot/commentserver/env34/lib/python3.4/site-packages/rethinkdb/net.py", line 360, in connect
        self._socket = SocketWrapper(self, timeout)
      File "/home/bundleroot/commentserver/env34/lib/python3.4/site-packages/rethinkdb/net.py", line 268, in __init__
        (self.host, self.port, ex))
    rethinkdb.errors.RqlDriverError: Could not connect to localhost:28015. Error: [Errno 111] Connection refused
    Traceback (most recent call last):
      File "/home/bundleroot/commentserver/env34/lib/python3.4/site-packages/rethinkdb/net.py", line 244, in __init__
        socket.create_connection((self.host, self.port), timeout)
      File "/usr/lib/python3.4/socket.py", line 509, in create_connection
        raise err
      File "/usr/lib/python3.4/socket.py", line 500, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused

我应该担心吗?在那种情况下,好的做法是什么?

是的,您需要关闭连接以避免连接泄漏。这个来自 RethinkDB 的 Flask 示例就是这样做的:

https://github.com/rethinkdb/rethinkdb-example-flask-backbone-todo/blob/master/todo.py#L47-L65

即使 RethinkDB 没有对连接数强制执行硬限制(我不确定是否有),您也可以 运行 进入 OS 的限制。