Skip to content

Performance Regression from 1.45.1 to 1.46 #7692

@Dav1dde

Description

@Dav1dde

When initially updating Tokio from 1.45 to 1.47 (later problem bisected to PR: #7342), I experienced a very large performance regression in a custom thread pool designed to process CPU heavy tasks.

The tread pool's code is fully available here.

A high level overview:

  • The thread pool manages N threads (std::thread::)
  • Tasks between threads are shared with a flume mpmc channel, which is bounded to N*2.
  • Each thread invokes Tokio's Runtime::block_on
  • Each thread runs an async task which:
    1. Polls a list of tasks stored in an FuturesUnordered until the FuturesUnordered returns Pending
    2. Polls a task from the flume channel
    3. Inserts the task into the FuturesUnrodered and starts again

Profiles taken (with perf):

Unfortunately I did not get a small reproduction done, I bisected tokio commits and load testing the full binary.

A random guess, there are now spurious (or constant) wake ups. As it looks like the pool still gets all of its work done, but when it should be idle it is burning through CPU.

Real Data

Bisected Tokio commits (in the commit message) and the commit hash of the associated builds:
Image
Image

Transition from one version to the next:
Image

CPU Usage:
Image

Internal Service and Thread Pool Utilization (measured on Time spent polling tasks), the top two lines are affected thread pools:
Image

Only Thread pool utilization (again measured on each thread time spent in poll over time), two thread pools:
Image

Average time spent per task in the bigger thread pool does not change (ignore the small section that increases, this is normal). Conclusion from this, time spent is not because the tasks changed:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateI-slowProblems and improvements related to performance.M-runtimeModule: tokio/runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions