首页 > 解决方案 > 如何为 executionIsolationSemaphoreMaxConcurrentRequests 选择正确的值

问题描述

我想知道如何在 spring-cloud-gateway 的 hystrix 配置中正确设置 executionIsolationSemaphoreMaxConcurrentRequests 的值。默认值为 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");
}

标签: javaspring-cloudhystrixspring-cloud-gatewaycircuit-breaker

解决方案


推荐阅读