在服务中使用1000条以上Hystrix命令时,我发现内存使用率很高。
用例:
- 服务进行REST调用。
- 每个REST端点可以接收数千个呼叫。端点行为异常时需要断路。
- 可能有成千上万个(上限15000个)这样的REST端点(每个端点在不同的域中)。
- 这些REST端点之间没有公共组密钥。
我能够为大约10,000个唯一命令获得大约1 GB的内存使用量,但没有任何更少的地方。这是我正在使用的设置。如您所见,我几乎关闭了延迟指标。还有什么我可以减少内存占用的方法吗?我非常希望能够从缓存中踢出一些旧的HystrixCircuitBreaker
实例,但是看不到任何实现方法。我计划代替UUID.randomUUID()传递调用方的上下文。
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("BookreaderCommand"))
.andCommandKey(HystrixCommandKey.Factory.asKey("ReadBooks" + UUID.randomUUID()))
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.defaultSetter()
.withMaxQueueSize(20))
.andCommandPropertiesDefaults(HystrixCommandProperties.defaultSetter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(1)
.withCircuitBreakerSleepWindowInmilliseconds(300000)
.withExecutionTimeoutInmilliseconds(1000)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerRequestVolumeThreshold(1)
.withCircuitBreakerErrorThresholdPercentage(100)
.withMetricsRollingStatisticalWindowInmilliseconds(1000)
.withMetricsRollingStatisticalWindowBuckets(1)
.withMetricsRollingPercentileEnabled(false) // Percentile not enabled.
.withMetricsRollingStatisticalWindowInmilliseconds(1000)
.withMetricsRollingPercentileWindowBuckets(1)
.withMetricsHealthsnapshotIntervalInmilliseconds(1000)),