-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
All database interactions going through Diesel are synchronous, even though most of them happen within tokio's cooperative multitasking framework. That means that long-running db interactions will block the tokio worker they are running on; if enough workers (by default, one per CPU core) block, the whole system grinds to a halt. At that point, no work can be done, including work that doesn't even involve the database, but simply gets scheduled on the tokio runtime.
Upstream Diesel is not going to add async database interactions anytime soon so we need to come up with our own approach. One possible way to address this is with tokio's tokio_threadpool::blocking
where slow work gets pushed to a separate pool of slow tasks, freeing up the main workers.
Open questions around this:
- how to best integrate that and how to change our internal API's (should most
Store
functions returnFuture
?) - how to determine which db work is slow and needs to be treated that way (might be that we should do all db work on the
blocking
pool)