Skip to content

anyspawn: allow scheduling work to a different thread when on single threaded runtimes #351

@martintmk

Description

@martintmk

Currently, Spawner exposes a spawn method that schedules the work. On multi threaded runtimes, using Tokio, this schedules the work on any thread. The same method on single threaded runtimes, schedules it always on current thread.

We have a scenario, where a thread spawns so much work that it overwhelms the thread and creates a hotspot. What we need is to have an additional Spawner::spawn_anywhere<R>(data: ThreadAware, execute: fn(data) -> impl Future<Output = R>) method that allows to spawn a work to additional threads.

  • On MT threaded runtimes, this method is basically no-op and behaves the same as spawn method.
  • On ST runtimes, this method relocates the data and calls the execution function on them.

Ideally, these changes would be introduced in a backward compatible way without adding any generics to the Spawner type and keeping it's simplicity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions