Skip to content

Move slow db interactions to tokio blocking pool #905

@lutter

Description

@lutter

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 return Future?)
  • 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions