0
votes

I have two processes with a shared sqlite database, each one has its own connection to the database. one process writes to the database in a high rate, and one process reads from the database. My concern is how to avoid "reader starvation" issue, since the writer accesses the database in a high rate, thus locking the database for the reader.

I'm using sqlite3_busy_timeout so the reader waits if the database is locked, but from the sqlite3_busy_timeout description I understand that the busy handler simply sleeps a few times with retries. if the writer happnens to lock the database at those times, non of the retries will succeed.

The sqlite file locking documentation describes an opposite problem: "writer starvation" and the mitigations in sqlite version 3. but I couldn't find any reference to the opposite problem "reader starvation". are there any best practices to avoid such issue?

1

1 Answers

1
votes

Put the database in WAL mode.

WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.