内存 SQLite 数据库可以通过并发扩展吗?

发布于 2024-08-27 16:12:15 字数 179 浏览 5 评论 0原文

为了防止 SQLite 内存数据库被清理,必须使用相同的连接来访问数据库。但是,使用相同的连接会导致 SQLite 同步对数据库的访问。因此,如果我有许多线程对内存数据库执行读取,则在多核计算机上运行的速度比对文件支持的数据库运行完全相同的代码要慢。

有什么办法可以两全其美吗?也就是说,内存数据库允许对数据库进行多个并发调用?

In order to prevent a SQLite in-memory database from being cleaned up, one must use the same connection to access the database. However, using the same connection causes SQLite to synchronize access to the database. Thus, if I have many threads performing reads against an in-memory database, it is slower on a multi-core machine than the exact same code running against a file-backed database.

Is there any way to get the best of both worlds? That is, an in-memory database that permits multiple, concurrent calls to the database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贩梦商人 2024-09-03 16:12:15

答案是否定的。我向 SQLite 用户组询问并得到 Pavel Ivanov 的以下回复:

不,SQLite 不支持对任何数据库的完全并发访问。这
您可以获得的唯一并发性是拥有磁盘数据库,而无需
共享缓存(因此实际上有多个数据库副本
记忆)。当然,我不考虑并发选项
不同的流程。

The answer is no. I asked on the SQLite user group and got the following response from Pavel Ivanov:

No, SQLite doesn't support full concurrent access to any database. The
only concurrency you can earn is having on-disk database without
shared cache (so actually having several copies of the database in
memory). Of course I don't consider option of concurrency from
different processes.

戏舞 2024-09-03 16:12:15

如果将页面大小和缓存大小设置得足够大以容纳整个数据库,则读取操作将从缓存中完成,性能将几乎等于内存数据库。

If you set the page size and cache size large enough to contain the entire database, read operations will be fulfilled from the cache and the performance will be nearly equal to an in-memory database.

橘亓 2024-09-03 16:12:15

从这里我明白答案是肯定的 http://www.sqlite.org/faq.html# q6

from here i understood that answer is yes http://www.sqlite.org/faq.html#q6

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文