Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves documentation for VirtualThreads boundedElastic behavior #3635

Merged
merged 12 commits into from
Nov 14, 2023

Conversation

OlegDokuka
Copy link
Contributor

No description provided.

OlegDokuka added 2 commits November 8, 2023 15:02
wip
Signed-off-by: OlegDokuka <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
@OlegDokuka OlegDokuka added the type/documentation A documentation update label Nov 10, 2023
@OlegDokuka OlegDokuka added this to the 3.6.0 milestone Nov 10, 2023
@OlegDokuka OlegDokuka requested a review from a team as a code owner November 10, 2023 14:39
@OlegDokuka OlegDokuka changed the title Improves rocumentation for VirtualThreads boundedElastic behavior Improves documentation for VirtualThreads boundedElastic behavior Nov 10, 2023
@@ -624,6 +624,18 @@ invoked whenever a `Runnable` task submitted to a `Scheduler` throws an `Excepti
that if there is an `UncaughtExceptionHandler` set for the `Thread` that ran the task,
both the handler and the hook are invoked).

[[scheduler-virtual-thread]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review section 4.5 and consider updating the boundedElastic description instead of adding a new one here. The remark about newBoundedElastic can become part of the above section for factories, so it offers a guidance to the user how to replace the old behaviour with the new one in places that they need a non-global instance.

* @return the common <em>boundedElastic</em> instance, a {@link Scheduler} that dynamically creates workers with
* an upper bound to the number of backing threads and after that on the number of enqueued tasks, that reuses
* threads and evict idle ones
* threads and evict idle ones. If runs on Java 21 with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @return section needn't be so detailed. It can just mention that a shared global boundedElastic instance is created and returned instead of repeating notes from the above.

Signed-off-by: OlegDokuka <[email protected]>
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Just some minor polishing suggestions for consideration.


import reactor.util.annotation.NonNull;
import reactor.util.annotation.Nullable;

/**
* The noop {@link VirtualThread} Reactor {@link ThreadFactory} to be
* used with {@link ThreadPerTaskBoundedElasticScheduler}. It throws exceptions when is
* used with {@link BoundedElasticPerThreadScheduler}. It throws exceptions when is
* being created, so it indicates that current Java Runtime does not support
* {@link VirtualThread}s.
Copy link
Contributor

@rstoyanchev rstoyanchev Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth saying something like:

This VirtualThreadFactory variant is included when Reactor is used with JDK versions lower than 21, and all methods raise an UnsupportedOperationException. An alternative variant is available for use on JDK 21+ where virtual threads are supported.


ThreadPerTaskBoundedElasticScheduler(int maxThreads, int maxTaskQueuedPerThread, ThreadFactory factory) {
BoundedElasticPerThreadScheduler(int maxThreads, int maxTaskQueuedPerThread, ThreadFactory factory) {
Copy link
Contributor

@rstoyanchev rstoyanchev Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, something like:

This BoundedElasticPerThreadScheduler variant is included when Reactor is used with JDK versions lower than 21, and all methods raise an UnsupportedOperationException. An alternative variant is available for use on JDK 21+ where virtual threads are supported.

@OlegDokuka OlegDokuka modified the milestones: 3.6.0, 3.6.1 Nov 14, 2023
OlegDokuka added 4 commits November 14, 2023 14:03
Signed-off-by: OlegDokuka <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
* @deprecated in favor of
* {@link #newBoundedElasticThreadPerTask(int, int, ThreadFactory)}.
* Should be safely removed in 3.8.0
*
* @return a new {@link Scheduler} that dynamically creates workers with an upper bound to
* the number of backing threads
*/
default Scheduler newThreadPerTaskBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory) {
Copy link
Member

@chemicL chemicL Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we have both threadPerTaskBoundedElastic and boundedElasticThreadPerTask... Even though the latter is more favourable, with the fact that we already released threadPerTaskBoundedElastic, I think it's just better to leave one variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the release of 3.6.0 without this PR I suggest we keep the name that is already in the public API - threadPerTaskBoundedElastic, instead of having both variants.

OlegDokuka and others added 2 commits November 14, 2023 14:45
Signed-off-by: OlegDokuka <[email protected]>
…sticSchedulerSupplier.java

Co-authored-by: Dariusz Jędrzejczyk <[email protected]>
@@ -63,6 +63,10 @@
* Factories prefixed with {@code new} (eg. {@link #newBoundedElastic(int, int, String)} return a new instance of their flavor of {@link Scheduler},
* while other factories like {@link #boundedElastic()} return a shared instance - which is the one used by operators requiring that flavor as their default Scheduler.
* All instances are returned in a {@link Scheduler#init() initialized} state.
* <p>
* Since 3.6.0 {@link #boundedElastic()} can run tasks on {@link VirtualThread}s if the application
* runs on a Java 21 runtime and the {@link #DEFAULT_BOUNDED_ELASTIC_ON_VIRTUAL_THREADS}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revisit all the places where we mention JDK 21 and consider if 21+ is more appropriate

OlegDokuka and others added 2 commits November 14, 2023 15:29
Co-authored-by: Dariusz Jędrzejczyk <[email protected]>
Signed-off-by: OlegDokuka <[email protected]>
@OlegDokuka OlegDokuka merged commit 2b62374 into main Nov 14, 2023
6 checks passed
@chemicL chemicL deleted the main-loom-docs-improvements branch April 11, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants