我想知道如何在spring-cloud-gateway的hystrix配置中正确执行IsolationSemaphoreMaxConcurrentRequests的设置值。默认值为10,但在我们的情况下,一个用户可以超过该默认值。我应该如何选择正确的价值?如何根据hystrix中的时间窗口和预期的用户数量来计算它?
以下示例配置:
@Value("${hystrix.circuitBreakerRequestVolumeThreshold : 20}")
private int circuitBreakerRequestVolumeThreshold;
@Value("${hystrix.executionTimeoutInMilliseconds : 30000}")
private int executionTimeoutInMilliseconds;
@Value("${hystrix.circuitBreakerSleepWindowInMilliseconds : 10000}")
private int circuitBreakerSleepWindowInMilliseconds;
@Value("${hystrix.metricsRollingPercentileWindowInMilliseconds : 60000}")
private int metricsRollingPercentileWindowInMilliseconds;
@Value("${hystrix.metricsHealthSnapshotIntervalInMilliseconds : 500}")
private int metricsHealthSnapshotIntervalInMilliseconds;
@Value("${hystrix.circuitBreakerErrorThresholdPercentage : 50}")
private int circuitBreakerErrorThresholdPercentage;
@Value("${hystrix.metricsRollingStatisticalWindowInMilliseconds : 10000}")
private int metricsRollingStatisticalWindowInMilliseconds;
@Value("${hystrix.executionIsolationSemaphoreMaxConcurrentRequests : 50}")
private int executionIsolationSemaphoreMaxConcurrentRequests;
public Consumer<HystrixGatewayFilterFactory.Config> getHystrixConfig(String groupName, String serviceName) {
return getHystrixConfig(groupName, serviceName, executionTimeoutInMilliseconds);
}
public Consumer<HystrixGatewayFilterFactory.Config> getHystrixConfig(String groupName, String serviceName, int timeout) {
return config -> config
.setSetter(HystrixObservableCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupName))
.andCommandKey(HystrixCommandKey.Factory.asKey(serviceName))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withCircuitBreakerEnabled(true)
.withCircuitBreakerRequestVolumeThreshold(circuitBreakerRequestVolumeThreshold)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(executionIsolationSemaphoreMaxConcurrentRequests)
.withExecutionTimeoutInMilliseconds(timeout)
.withCircuitBreakerSleepWindowInMilliseconds(circuitBreakerSleepWindowInMilliseconds)
.withMetricsRollingPercentileWindowInMilliseconds(metricsRollingPercentileWindowInMilliseconds)
.withMetricsHealthSnapshotIntervalInMilliseconds(metricsHealthSnapshotIntervalInMilliseconds)
.withCircuitBreakerErrorThresholdPercentage(circuitBreakerErrorThresholdPercentage)
.withMetricsRollingStatisticalWindowInMilliseconds(metricsRollingStatisticalWindowInMilliseconds)
)
)
.setFallbackUri("forward:/hystrixfallback");
}