在 BerkeleyDB 中多次打开数据库时性能损失
我正在使用 BerkeleyDB 开发一个小型应用程序。我有一个关于在 BDB 中多次打开数据库的问题。
我有一大堆文本(语料库),我想加载其中的一部分来进行计算。我这里有两个伪代码(与python混合)
@1
def getCorpus(token):
DB.open()
DB.get(token)
DB.close()
@2
#open and wait
def openCorpus():
DB.open()
#close database
def closeCorpus():
DB.close()
def getCorpus(token):
DB.get(token)
在第二个示例中,我将在计算之前打开数据库,为每个循环加载令牌,然后关闭数据库。
在第一个示例中,每次循环请求令牌时,我都会打开、获取然后关闭数据库。
有性能损失吗?
我还注意到我正在使用 DBEnv 来管理数据库
I'm using BerkeleyDB to develop a small app. And I have a question about opening a database multiple time in BDB.
I have a large set of text ( corpus ), and I want to load a part of it to do the calculation. I have two pseudo-code (mix with python) here
@1
def getCorpus(token):
DB.open()
DB.get(token)
DB.close()
@2
#open and wait
def openCorpus():
DB.open()
#close database
def closeCorpus():
DB.close()
def getCorpus(token):
DB.get(token)
In the second example, I'll open the db before the calculation, load token for each loop and then close the db.
In the first example, each time the loop ask for the token, I'll open, get and then close the db.
Is there any performance lost ?
I also note that I'm using a DBEnv to manage the database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你不缓存打开的文件,你总是会损失性能,因为:
但在代码编写之前我不会太关心性能。
If you aren't caching the opened file you will always get performance lost because:
But I wouldn't care too much about the performance before the code is written.