问题描述
我有访问本地sqlite3的分贝频繁,出于性能考虑一个Android应用程序,所以我始终保持连接打开。但是,我的一个朋友推荐我打开/关闭连接的每个操作。
I have an android application that access local sqlite3 db frequently, for performance consideration so i always keep the connection open. But one of my friends recommended me to open/close the connection every operation.
1)什么是你的球员的意见这两种方法?利弊/利弊。2)我做了一些测试,发现数据库连接并没有太多的PERF的开销。请问数据库连接的性能开销上的数据块的大小而变化?
1) What's your guys opinion on these two methods ? cons/pros.2) I did some testing and find the DB connection doesn't have too much perf overhead. Does the performance overhead of DB connection varies on the size of the DB ?
推荐答案
我不知道在数据库中频繁关闭/打开(无论大小)的任何性能损失。我认为这个问题的答案也取决于什么类型的应用程序正在访问数据库。
I don't know of any performance penalties in frequent closing/opening of the database (regardless of its size). I think the answer to this question also depends on what type of application is accessing the database.
你重新查询数据库很多?
然后好像纠正以保持开放。
Do you "re-query" the database a lot?
Then it seems rectified to keep it open.
你每次取东西时,读取不同的数据?
再次,它似乎是合理的把它打开(因为你不会得到在缓存中的数据,而不是)。
Do you fetch different data each time you fetch something?
Again, it seems reasonable to leave it open (as you won't gain in caching the data instead).
是否有访问同一个数据库中的任何其他应用程序?
如果没有并发或阻塞问题的危险,它可能是明智的,看完后关闭数据库/ /写入到它。
Are there any other applications accessing the same database?
If there is a risk for concurrency or blocking issues, it might be wise to close the database after finished reading/writing from/to it.
一般来说,我会说,你可能会获得更多的缓存数据比优化性能,当离开打开数据库(禁忌关闭它)。
Generally I would say that you might gain more in caching data than in leaving the database open (contra closing it) when optimizing for performance.
这篇关于当结束对Android的数据库连接?之后,您的每一次操作完成,或者您的应用程序退出后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!