仅读取数据后是否需要关闭ZODB连接
我正在使用 ZODB 进行 python 对象持久化。我使用 web2py 作为框架。
我使用的 ZODB 数据库仅用于读取。我已经编写了用于在模型中打开数据库的代码。然后,connection.root()
对象被缓存在 RAM 中,以便它保留在那里以应对其他请求。
我的问题是,如果 ZODB 数据库仅用于读取访问并且没有挂起的写入,是否有必要关闭该数据库?
I am using ZODB for my python object persistence. I am using web2py as a framework.
The ZODB database I am using is accessed only for reads. I have written the code for opening the database inside my models. The connection.root()
object is then cached in RAM so it stays there for other requests.
My question is, is it necessary to close a ZODB database if it is used only for read access and there are no pending writes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你不需要关闭它。每个打开的连接确实会消耗一点内存等,但听起来无论如何你都不会拥有数千个连接,每个 web2py 进程只需要一个
No you don't need to close it. Each open connection does consume a little memory etc, but it sounds like you aren't going to have thousands of them anyway, just one per web2py process
您不必关闭它,但如果您想避免缓存的对象耗尽您的内存,您应该定期运行
connection.cacheMinimize()
。如果您还定期写入数据并提交,则可以跳过这一点,因为commit()
包含cacheMinimize()
。You don't have to close it, but you should run
connection.cacheMinimize()
regularly, if you want to avoid, that the cached objects eats up your memory. If you're also writing data and commit regularly, you can skip that, ascommit()
includescacheMinimize()
.