Spring boot 弹性4J隔板螺纹性能
我正在使用Resilience4j进行大量测试,并监视线程的行为 我使用的是spring boot 2.2.5、resilience4j 1.4.0。Gatling(加载工具)、visualvm(分析线程) 我意识到:Spring boot 弹性4J隔板螺纹性能,spring-boot,resilience4j,Spring Boot,Resilience4j,我正在使用Resilience4j进行大量测试,并监视线程的行为 我使用的是spring boot 2.2.5、resilience4j 1.4.0。Gatling(加载工具)、visualvm(分析线程) 我意识到: @CircuitBreaker(name = MyServiceCommand.BEAN_NAME, fallbackMethod = "fallback") @TimeLimiter(name = MyServiceCommand.BEAN_NAME) @Bulkhead(na
@CircuitBreaker(name = MyServiceCommand.BEAN_NAME, fallbackMethod = "fallback")
@TimeLimiter(name = MyServiceCommand.BEAN_NAME)
@Bulkhead(name = MyServiceCommand.BEAN_NAME, type = Bulkhead.Type.THREADPOOL)
@Component
@AllArgsConstructor
@Slf4j
public class MyServiceCommand extends ResilienceAbstractCommand {
protected static final String BEAN_NAME = "MyService";
private SlowService slowService;
public CompletableFuture<String> perform() {
return CompletableFuture.completedFuture(slowService.get());
}
private CompletableFuture<String> fallback() {
return CompletableFuture.completedFuture("fallback");
}
}
maxConcurrentCalls, maxWaitDuration
如果您使用的是隔板类型=螺纹池,则上述配置将被忽略maxThreadPoolSize, coreThreadPoolSize, queueCapacity, keepAliveDuration
这些配置将被忽略:
maxConcurrentCalls, maxWaitDuration
@CircuitBreaker(name = MyServiceCommand.BEAN_NAME, fallbackMethod = "fallback")
@TimeLimiter(name = MyServiceCommand.BEAN_NAME)
@Bulkhead(name = MyServiceCommand.BEAN_NAME, type = Bulkhead.Type.THREADPOOL)
@Component
@AllArgsConstructor
@Slf4j
public class MyServiceCommand extends ResilienceAbstractCommand {
protected static final String BEAN_NAME = "MyService";
private SlowService slowService;
public CompletableFuture<String> perform() {
return CompletableFuture.completedFuture(slowService.get());
}
private CompletableFuture<String> fallback() {
return CompletableFuture.completedFuture("fallback");
}
}
SlowService对另一个应用程序进行缓慢的网络调用
我配置这些值只是为了在生产中进行测试
价值观会有所不同
问题是:
@CircuitBreaker(name = MyServiceCommand.BEAN_NAME, fallbackMethod = "fallback")
@TimeLimiter(name = MyServiceCommand.BEAN_NAME)
@Bulkhead(name = MyServiceCommand.BEAN_NAME, type = Bulkhead.Type.THREADPOOL)
@Component
@AllArgsConstructor
@Slf4j
public class MyServiceCommand extends ResilienceAbstractCommand {
protected static final String BEAN_NAME = "MyService";
private SlowService slowService;
public CompletableFuture<String> perform() {
return CompletableFuture.completedFuture(slowService.get());
}
private CompletableFuture<String> fallback() {
return CompletableFuture.completedFuture("fallback");
}
}
1-我的应用程序是I/O绑定的,我希望当有许多请求(40/s)时,由resilience4j创建的线程池达到maxThreadPoolSize数,但仅创建了3个线程(cpu核心数量-1)
我只看到了:
隔板-MyService-1、隔板-MyService-2、隔板-MyService-3
有什么问题吗?
2-我进行了以下配置:
resilience4j.circuitbreaker:
configs:
default:
failureRateThreshold: 40
waitDurationInOpenState: 20s
minimumNumberOfCalls: 5
slowCallRateThreshold: 30
slowCallDurationThreshold: 300s
instances:
MyService:
baseConfig: default
ignoreExceptions:
- com.hotmart.display.commons.exception.BusinessException
resilience4j.bulkhead:
configs:
default:
maxConcurrentCalls: 800
maxWaitDuration: 15000
instances:
MyService:
baseConfig: default
resilience4j.thread-pool-bulkhead:
configs:
default:
maxThreadPoolSize: 10
queueCapacity: 500
instances:
MyService:
baseConfig: default
resilience4j.timelimiter:
configs:
default:
timeoutDuration: 300s
cancelRunningFuture: true
instances:
MyService:
baseConfig: default
maxThreadPoolSize: 1
coreThreadPoolSize: 1
queueCapacity: 2
keepAliveDuration: 3
我将slowService配置为10秒,太慢了
当时我做了3个请求,系统表现如下:
- 一次只处理1,这是正常的,因为核心和maxThread是1
- 请求已被查询,因为队列容量为2,所以可以