←back to thread

197 points slaily | 2 comments | | HN request time: 0s | source
Show context
slaily ◴[] No.44530519[source]
If you’re building Python async apps (FastAPI, background jobs, etc.) with SQLite, you’ll eventually hit two issues

- Opening/closing connections is fast, but not free—overhead adds up under load

- SQLite writes are globally locked

aiosqlitepool is a tiny library that adds connection pooling for any asyncio SQLite driver (like aiosqlite):

- It avoids repeated database connection setup (syscalls, memory allocation) and teardown (syscalls, deallocation) by reusing long-lived connections

- Long-lived connections keep SQLite's in-memory page cache "hot." This serves frequently requested data directly from memory, speeding up repetitive queries and reducing I/O operations

- Allows your application to process significantly more database queries per second under heavy load

Enjoy!

replies(5): >>44565059 #>>44565071 #>>44566400 #>>44570162 #>>44570945 #
1. manmal ◴[] No.44566400[source]
Doesn’t SQLite have its own in-memory cache? Is this about having more control re cache size?
replies(1): >>44567018 #
2. dathinab ◴[] No.44567018[source]
yes, per "open connection", hence why not closing+reopening connections all the time helps the cache ;)