Skip to content

Provide bespoke thread-per-task-bounded-elastic scheduler #4102

@bclozel

Description

@bclozel

The spring-graphql project is using a bespoke Scheduler when sending WebSocket messages to a WS session; this helps to guarantee that messages are sent in a serial fashion in blocking scenarios.

Community recently asked to use a Scheduler backed by virtual threads, when running on Java 21+. This solution works, but there might be room for improvement. With a newSingle scheduler, a virtual thread is kept alive for the entire duration of the websocket session, which is not a typical usage for VTs.

Reactor could provide a way to create a bespoke thread-per-task-bounded-elastic scheduler, with a custom ThreadFactory. This would allow to process messages in an efficient fashion when the task queue is full, and not hold onto a virtual thread when the queue is empty. We realize that reactor cannot mandate virtual threads on Java 21+ runtimes and that a system property must be configured to opt in. However, a custom ThreadFactory should be enough for spring-graphql to implement this.

We don't have performance benchmarks to prove a possible improvement, but this could be a nice addition to the Schedulers API.

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