c - 我应该如何调整 SQLite 以获得最小延迟?

标签 c sqlite

我了解到 SQLite 在默认设置下针对吞吐量进行了优化。调整 SQLite 以实现最小(最好是可预测的)写入延迟的最佳方法是什么?我希望在所有情况下都将简单更新+提交的延迟保持在 10 毫秒以下。

我认为我需要在另一个线程上使用 WAL 和检查点,但我不确定检查点是否会阻止主线程上的编写器。

我的应用程序一次只有一个进程访问数据库,因此无需担心并发问题。数据库不损坏​​很重要,但持久性并不那么重要(最近的事务可能会丢失)。

最佳答案

获得低写入延迟的唯一方法是异步执行它们,即不要等待它们从缓存中刷新。

WAL documentation对此说道:

Note that with PRAGMA synchronous set to NORMAL, the checkpoint is the only operation to issue an I/O barrier or sync operation (fsync() on unix or FlushFileBuffers() on Windows). If an application therefore runs checkpoint in a separate thread or process, the main thread or process that is doing database queries and updates will never block on a sync operation. This helps to prevent "latch-up" in applications running on a busy disk drive. The downside to this configuration is that transactions are no longer durable and might rollback following a power failure or hard reset.

要防止主线程中发生检查点,请使用 PRAGMA wal_autocheckpoint .

但这仍然会带来延迟,因为检查点必须在检查点操作期间锁定整个数据库。如果您无法忍受这一点,请将检查点移至您可以负担得起的空闲时间,或者允许 WAL 文件增长到无限大小。

关于c - 我应该如何调整 SQLite 以获得最小延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42463127/

相关文章:

c - make 如何知道要更新哪些文件

c - 如何用静态库编译gcc?

android - 获取 Blob 图像并将该图像转换为位图图像

android - 从 IntentService 构造函数打开数据库连接

c - -wrap 选项的 GNU 链接器通配符

c - 从C文件中读取移动数据(字符串和数字)

针对 windows 64 位目标编译,静态 .libs 问题

sqlite - SQLITE : one row constraint

c# - 运算符 '!=' 不能应用于类型 'Task' 和 'int' 的操作数

android - Sqlite 查询以获取匹配搜索关键字后的下一个可用字符列表