-
Notifications
You must be signed in to change notification settings - Fork 63
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
allow asynchronous fault tolerance strategies without offloading to an extra thread #533
Comments
This was a deliberate choice because retries will have to run on a different thread and we didn't want to have the first request run on the same thread, but then have retries run on a different thread in case that lead to situations where the first attempt would always work but retries would always fail because of some difference when running asynchronously. Not saying it's something that we can't revisit, but I think that was the original rationale. |
Not sure retries always have to run on a different thread. Just need to make sure that the delay between retries isn't |
+1 to renaming It shouldn't be necessary to use I don't believe there's a need for retries to always be on a separate thread, there should be ways to make it runnable on the same thread, or a mixture of the two. Where the retries are executed should be up to a runtime to decide what is best for it, based on its threading model. |
@Ladicek We discussed this before as mentioned by @Azquelt ! The fact is that the method return type does not force the method itself running asynchronously. The main usage of We discussed whether to update |
@Emily-Jiang Unfortunately, no. |
However, it's a good point that presence or absence of EDIT: filed #535 for the |
@Emily-Jiang Surely it's more practical to define that a return type of But what exactly that asynchronous execution means is up to the implementation. It could be a separate thread, or it could be asynchronously on the same thread. The main benefit is that the behavior is implied by the return type as opposed to needing to be specified. For those familiar with Having consistency across specifications that an asynchronous return type means the method is executed asynchronously is very important |
@Ladicek @kenfinnigan I thought a bit more based on your comments. Maybe we can take this release to make behaviour changes by removing |
I think MP Rest Client is a somewhat different case. With MP Rest Client, the user calls a method provided by the implementation. In contrast, with MP Fault Tolerance, both the caller and the method body are provided by the user. It seems odd to me that I could write a method returning a |
The main idea here is that |
Yesterday, I realized there's probably a better way to explain what I mean: The current There are several options:
|
So we have asynchronous fault tolerance strategies for
CompletionStage
-returning methods, but those only apply if the method is also@Asynchronous
. If the method is not annotated@Asynchronous
, then all the fault tolerance strategies treat the method as synchronous and only apply around the method call.If I have a truly asynchronous method, I don't want to add
@Asynchronous
, because that leads to an explicit move to an extra thread. (There can be several reasons why I don't want that. For example, the method itself can already spawn an extra thread. Or the method can execute on an event loop. Etc.)This is not a made-up scenario -- I found about this issue when trying to use MP RestClient with MP Fault Tolerance! In MP RestClient, if the method returns
CompletionStage
, that itself means that the RestClient implementation needs to run the method asynchronously. Adding@Asynchronous
means that Fault Tolerance will also run it asynchronously. That's a waste of resources.In other words, the
@Asynchronous
annotation has a very narrow meaning -- basically, it always means offloading to an extra thread. That is very limiting. For example, in an event loop world, everything is asynchronous yet running on a single thread (or a small thread pool).I believe we need to add an ability to let
CompletionStage
-returning methods be treated as asynchronous without offloading to an extra thread. I can see several ways of achieving that:CompletionStage
-returning method isn't annotated@Asynchronous
, we still apply all the fault tolerance strategies asynchronously. Here, the@Asynchronous
annotation basically retains the narrow meaning of "force offloading to an extra thread".@Asynchronous
to@ThreadOffload
, so that it's clear what the annotation does. We'd still treat the return type as the primary indicator of whether the method is asynchronous or not.@Asynchronous
annotation to be able to signalize whether offloading to an extra thread is desired. For example,@Asynchronous(threadOffload = true)
to offload to an extra thread, and@Asynchronous(threadOffload = false)
for staying on the original thread. Here, the@Asynchronous
annotation becomes more general. We'd probably defaultthreadOffload
totrue
to stay compatible, and trust user that they know they need to setthreadOffload = false
.The text was updated successfully, but these errors were encountered: