1

I am using the AWS SDK for Java 2.0, together with the Netty HTTP client, and I noticed that there are two different thread pools that can effectively handle a response. The first one is a ThreadPoolExecutor that can be overriden as part of the service client itself like so

DynamoDbAsyncClient dynamoClient = DynamoDbAsyncClient.builder()
                .httpClient(httpClient)
                .asyncConfiguration(ClientAsyncConfiguration.builder()
                        .advancedOption(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, awsSdkFutureCompletionExecutor)
                        .build())

The second one is the Netty HTTP client's event loop. Depending on where I join the thread, I can see that it is either processed by the aws-java-sdk-NettyEventLoop or the sdk-async-response thread pool.

If I call dynamoClient.query(request).join() I can see that the aws-java-sdk-NettyEventLoop continues any further processing, whereas dynamoClient.query(request).whenComplete(...) means that the sdk-async-response thread is doing the processing.

Is there a recommended approach? Should I prefer to do the processing in one thread pool over the other?

Anvar
  • 1,110
  • 2
  • 10
  • 22

1 Answers1

3

I suspect I know the answer to this one actually. I believe the response is handed over to the sdk-async-response thread pool to guard against someone doing a blocking call in the response handler for a request and thus blocking the Netty event loop. So to answer my own question I think the response processing should be done in the sdk-async-response thread pool. It would probably be good in a future version to be able to not have the response handed over outside of the Netty event loop, with the usual caveats, but for now that doesn't seem to be possible.

Anvar
  • 1,110
  • 2
  • 10
  • 22
  • 3
    If you're confident that you will not do any blocking operations on the completing thread, you can disable the future completion executor and use the event loop threads by specifying `Runnable::run` as the `SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR`. – millems Jul 08 '20 at 23:41