Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

Sqlite 如何实现 高性能 读写?

现在项目需求是一个CS架构 图片管理器,需要对下载的缩略图进行缓存。
4~8线程并发的读取, 但是写入缓存时 sqlite 是锁住了整个数据库。无法进行读取操作。

目前只能用延迟写入的方式来优化,防止读取的时候写入操作。

如何才能优化到比较理想的方式?
以前缓存是直接写到硬盘的方式,一个一个的图片文件,速度方面还可以。但是量大很难管理。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SQLite 3.7.0之前不支持写的时候读.
SQLite 3.7.0开始对并发控制做了优化,
提供了WAL(write-ahead log)预写式日志模式,支持一个写和多个读并发,但同一个时刻仍然只能有一个写事务.
开启WAL的时候,官方建议选择NORMAL的同步模式:

PRAGMA synchronous = NORMAL;
PRAGMA journal_mode = WAL;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...