我有一个Android应用程序,经常访问本地sqlite3db,出于性能考虑,所以我总是保持连接打开.但是我的一个朋友建议我每次手术都要打开/关闭连接.
1)你们对这两种方法有什么看法?赞成/赞成. 2)我做了一些测试,发现DB连接没有太多的性能开销.数据库连接的性能开销是否随数据库大小的不同而不同?
我有一个Android应用程序,经常访问本地sqlite3db,出于性能考虑,所以我总是保持连接打开.但是我的一个朋友建议我每次手术都要打开/关闭连接.
1)你们对这两种方法有什么看法?赞成/赞成. 2)我做了一些测试,发现DB连接没有太多的性能开销.数据库连接的性能开销是否随数据库大小的不同而不同?
我不知道频繁关闭/打开数据库(无论其大小如何)会对性能造成什么影响.我认为这个问题的答案还取决于访问数据库的应用程序类型.
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.
通常,我会说,在优化性能时,缓存数据可能比保持数据库打开(相反,关闭数据库)可能获得更多yield .