【发布时间】:2023-01-14 21:45:31
【问题描述】:
我试图了解检测 AWS 异步客户端使用的默认线程池执行程序的最佳方法。 Source。我们正在使用 Micrometer 来跟踪所有指标。
我的目的是了解我是否应该使用自定义线程池执行程序,或者默认的线程池执行程序是否足够好。
我当前的代码如下(并且按预期工作):
//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();
我觉得有一种更简单的方法,但找不到。有没有更简单的方法来检测而无需重新定义默认执行程序?
【问题讨论】:
标签: spring-micrometer aws-java-sdk-2.x