0

In Quarkus, rest client can be defined to return my DTO, or CompletionStage.

I have 2 endpoints to call, first I want to retrieve some JobDTO from endpoint 1, then update it and save it back using 2nd endpoint.

I observed that:

  • If I define both endpoints returning CompletionStage<JobDTO>, main thread will initialize executor-thread-0 to call endpoint 1, and then executor-thread-0 hands over the work to executor-thread-1 to call endpoint 2
  • If I define 1st to return CompletionStage<JobDTO>, then 2nd endpoint to return JobDTO, only executor-thread-0 is used, 2nd endpoint call happens on it too.

I know that in this case, by default, ForkJoinPool.commonPool is used.

So, which is better? It's blocking I/O operation so I guess it's better to only block 1 thread if API call is slow; however I am not sure how the work stealing pool works, when I/O blocking happens.

For example if I define both to return CompletionStage, and 1st endpoint returns fast, executor-thread-0 will quickly hand over work to executor-thread-1. Then, will executor-thread-0 fetch more work and hands it over to executor-thread-2 to cause more threads blocking? Or it still hands to executor-thread-1 and queuing there?

Do I have to calculate the latency of these 2 endpoints and do some calculation, and then use some custom ExecutorService?

WesternGun
  • 11,303
  • 6
  • 88
  • 157

1 Answers1

0

I think I have figured it out.

If you define some different CompletionStage yourself, you need to provide the executor service, like in this blog; each stage needs one, so you may end up with multiple.

But the work of calling the endpoint when return type is CompletionStage will use Quarkus rest client pool, which can be configured by some properties as mentioned here. For example, I can configure quarkus.rest-client."my-api".connection-pool-size. This key is found in io.quarkus.restclient.config.RestClientConfig, among many others.

Of course if I define both endpoint to return CompletionStage, they will run in this above pool.

I think I will still block on one thread in this pool instead of splitting the work into 2 threads.

WesternGun
  • 11,303
  • 6
  • 88
  • 157