Skip to content

Heavy contention on blocking #2528

@jonhoo

Description

@jonhoo

Code that invokes spawn_blocking, or block_in_place (which internally calls spawn_blocking), all end up taking a shared lock here:

let mut shared = self.inner.shared.lock().unwrap();

This causes a lot of unnecessary contention between unrelated tasks if you frequently need to run blocking code. The problem is exacerbated as load increases, because more calls to spawn_blocking causes each individual call to become more expensive, and each call holds up an executor thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-enhancementCategory: A PR with an enhancement or bugfix.M-blockingModule: tokio/task/blockingT-performanceTopic: performance and benchmarks

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions