Instrumenting AWS async client sdk threadpool with Micrometer

Viewed 19

I'm trying to understand the best way to instrument the default thread pool executor used by AWS async client. Source. We are using Micrometer for tracking all metrics.

I aim to understand if I should use a custom thread pool executor or if the default one is good enough.

My current code is as follows (and it works as expected):

//use the same thread pool executor as the aws sdk but instrument it.
int processors = Runtime.getRuntime().availableProcessors();
int corePoolSize = Math.max(8, processors);
int maxPoolSize = Math.max(64, processors * 2);
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
                10, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1_000),
                new ThreadFactoryBuilder()
                        .threadNamePrefix("sdk-async-response").build());
// Allow idle core threads to time out
executor.allowCoreThreadTimeOut(true);

var instrumentedExecutor = ExecutorServiceMetrics.monitor(meterRegistry,
                executor,
                "instrumented-ddb-executor");

return DynamoDbAsyncClient.builder()
                .asyncConfiguration(b -> b.advancedOption(FUTURE_COMPLETION_EXECUTOR, instrumentedExecutor))
                .build();

I feel there is a simpler way but cannot find it. Is there a simpler way to instrument without redefining the default executor?

0 Answers
Related