.withExecutionTimeoutInMilliseconds(600) .withExecutionIsolationStrategy(isolationStrategy) .withCircuitBreakerEnabled(true) .withCircuitBreakerRequestVolumeThreshold(3) .withMetricsHealthSnapshotIntervalInMilliseconds(100)
private Setter getSetter() { if (setter == null) { synchronized(LOGGER) { if (setter == null) { setter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(RedisCache.class.getCanonicalName())) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withCircuitBreakerEnabled(true) .withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThreshold()) .withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindow())); } } } return setter; }
propertiesSetter.withCircuitBreakerEnabled(true) .withCircuitBreakerRequestVolumeThreshold(operation.getCircuitBreaker().get(CircuitBreakerConfig.REQUEST_VOLUME_THRESHOLD)) .withCircuitBreakerErrorThresholdPercentage( operation.getCircuitBreaker().get(CircuitBreakerConfig.DELAY_UNIT)).toMillis()); } else { propertiesSetter.withCircuitBreakerEnabled(false);
public static HystrixCommandProperties.Setter createSetter(){ HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter(); setter.withMetricsRollingStatisticalWindowInMilliseconds(10000);// default => statisticalWindow: 10000 = 10 seconds (and default of 10 buckets so each bucket is 1 second) setter.withMetricsRollingStatisticalWindowBuckets(10);// default => statisticalWindowBuckets: 10 = 10 buckets in a 10 second window so each bucket is 1 second setter.withCircuitBreakerRequestVolumeThreshold(20);// default => statisticalWindowVolumeThreshold: 20 requests in 10 seconds must occur before statistics matter setter.withCircuitBreakerSleepWindowInMilliseconds(5000);// default => sleepWindow: 5000 = 5 seconds that we will sleep before trying again after tripping the circuit setter.withCircuitBreakerErrorThresholdPercentage(50);// default => errorThresholdPercentage = 50 = if 50%+ of requests in 10 seconds are failures or latent then we will trip the circuit setter.withCircuitBreakerForceOpen(false);// default => forceCircuitOpen = false (we want to allow traffic) setter.withCircuitBreakerForceClosed(false);// default => ignoreErrors = false setter.withExecutionTimeoutInMilliseconds(1000); // default => executionTimeoutInMilliseconds: 1000 = 1 second setter.withExecutionTimeoutEnabled(true); setter.withExecutionIsolationThreadInterruptOnTimeout(true); setter.withExecutionIsolationThreadInterruptOnFutureCancel(false); setter.withMetricsRollingPercentileEnabled(true); setter.withRequestCacheEnabled(true); setter.withFallbackIsolationSemaphoreMaxConcurrentRequests(10); setter.withFallbackEnabled(true); setter.withExecutionIsolationSemaphoreMaxConcurrentRequests(10); setter.withRequestLogEnabled(true); setter.withCircuitBreakerEnabled(true); setter.withMetricsRollingPercentileWindowInMilliseconds(60000); // default to 1 minute for RollingPercentile setter.withMetricsRollingPercentileWindowBuckets(6); // default to 6 buckets (10 seconds each in 60 second window) setter.withMetricsRollingPercentileBucketSize(100); // default to 100 values max per bucket setter.withMetricsHealthSnapshotIntervalInMilliseconds(500); // default to 500ms as max frequency between allowing snapshots of health (error percentage etc) return setter; }
HystrixCommand.Setter build() { final String groupKey = HystrixUtil.getGlobalKey(commandClass); final String commandKey = "refreshTokenRetrievalCommand"; final HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties .Setter() .withExecutionTimeoutInMilliseconds(6000) .withCircuitBreakerEnabled(true) .withCircuitBreakerSleepWindowInMilliseconds(6000) .withFallbackEnabled(false); return HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)) .andThreadPoolPropertiesDefaults( HystrixThreadPoolProperties .Setter() .withCoreSize(10) .withQueueSizeRejectionThreshold(100) .withMaxQueueSize(100)) .andCommandPropertiesDefaults(commandProperties); } }
HystrixCommand.Setter build() { final String groupKey = HystrixUtil.getGlobalKey(commandClass); final String commandKey = "refreshTokenRetrievalCommand"; final HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties .Setter() .withExecutionTimeoutInMilliseconds(6000) .withCircuitBreakerEnabled(true) .withCircuitBreakerSleepWindowInMilliseconds(6000) .withFallbackEnabled(false); return HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)) .andThreadPoolPropertiesDefaults( HystrixThreadPoolProperties .Setter() .withCoreSize(10) .withQueueSizeRejectionThreshold(100) .withMaxQueueSize(100)) .andCommandPropertiesDefaults(commandProperties); } }
/** * Getter for default command properties to be used by a Hystrix {@code Command}. * * @return A pre-initialized {@code HystrixCommandProperties.Setter}. */ public static HystrixCommandProperties.Setter getDefaultErpCommandProperties() { return HystrixCommandProperties .Setter() .withExecutionTimeoutInMilliseconds(40 * 1000) .withCircuitBreakerEnabled(true) .withCircuitBreakerSleepWindowInMilliseconds(10 * 1000) .withFallbackEnabled(true); } }
private static Setter initSetter(FaultToleranceOperation operation) { HystrixCommandProperties.Setter properties = HystrixCommandProperties.Setter(); HystrixCommandKey commandKey = HystrixCommandKey.Factory .asKey(CompositeCommand.class.getSimpleName() + "#" + SimpleCommand.getCommandKey(operation.getMethod())); properties.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD); properties.withFallbackEnabled(false); properties.withCircuitBreakerEnabled(false); Setter setter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("CompositeCommandGroup")).andCommandKey(commandKey) .andCommandPropertiesDefaults(properties); // We use a dedicated thread pool for each async operation setter.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(commandKey.name())); HystrixThreadPoolProperties.Setter threadPoolSetter = HystrixThreadPoolProperties.Setter(); threadPoolSetter.withAllowMaximumSizeToDivergeFromCoreSize(true); setter.andThreadPoolPropertiesDefaults(threadPoolSetter); return setter; }
CircuitBreakerCommand(StockQuoteDatabase db, String symbol) { super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("MyGroup")) .andCommandPropertiesDefaults( HystrixCommandProperties.Setter() .withCircuitBreakerEnabled(true) .withCircuitBreakerRequestVolumeThreshold(50) .withExecutionTimeoutEnabled(true) .withExecutionTimeoutInMilliseconds(10) )); this.db = db; this.symbol = symbol; }
HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(hystrixHandle.getTimeout()) .withCircuitBreakerEnabled(true) .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests())
/** * Utility method for creating baseline properties for unit tests. */ /* package */static HystrixCommandProperties.Setter getUnitTestPropertiesSetter() { return new HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(1000)// when an execution will be timed out .withExecutionTimeoutEnabled(true) .withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD) // we want thread execution by default in tests .withExecutionIsolationThreadInterruptOnTimeout(true) .withExecutionIsolationThreadInterruptOnFutureCancel(true) .withCircuitBreakerForceOpen(false) // we don't want short-circuiting by default .withCircuitBreakerErrorThresholdPercentage(40) // % of 'marks' that must be failed to trip the circuit .withMetricsRollingStatisticalWindowInMilliseconds(5000)// milliseconds back that will be tracked .withMetricsRollingStatisticalWindowBuckets(5) // buckets .withCircuitBreakerRequestVolumeThreshold(0) // in testing we will not have a threshold unless we're specifically testing that feature .withCircuitBreakerSleepWindowInMilliseconds(5000000) // milliseconds after tripping circuit before allowing retry (by default set VERY long as we want it to effectively never allow a singleTest for most unit tests) .withCircuitBreakerEnabled(true) .withRequestLogEnabled(true) .withExecutionIsolationSemaphoreMaxConcurrentRequests(20) .withFallbackIsolationSemaphoreMaxConcurrentRequests(10) .withFallbackEnabled(true) .withCircuitBreakerForceClosed(false) .withMetricsRollingPercentileEnabled(true) .withRequestCacheEnabled(true) .withMetricsRollingPercentileWindowInMilliseconds(60000) .withMetricsRollingPercentileWindowBuckets(12) .withMetricsRollingPercentileBucketSize(1000) .withMetricsHealthSnapshotIntervalInMilliseconds(100); }
public AbstractFlexibleTestHystrixObservableCommand(HystrixCommandKey commandKey, ExecutionIsolationStrategy isolationStrategy, AbstractTestHystrixCommand.ExecutionResult executionResult, int executionLatency, TestCircuitBreaker circuitBreaker, HystrixThreadPool threadPool, int timeout, CacheEnabled cacheEnabled, Object value, TryableSemaphore executionSemaphore, TryableSemaphore fallbackSemaphore, boolean circuitBreakerDisabled) { super(testPropsBuilder(circuitBreaker) .setCommandKey(commandKey) .setCircuitBreaker(circuitBreaker) .setMetrics(circuitBreaker.metrics) .setThreadPool(threadPool) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(isolationStrategy) .withExecutionTimeoutInMilliseconds(timeout) .withCircuitBreakerEnabled(!circuitBreakerDisabled)) .setExecutionSemaphore(executionSemaphore) .setFallbackSemaphore(fallbackSemaphore)); this.executionResult = executionResult; this.executionLatency = executionLatency; this.cacheEnabled = cacheEnabled; this.value = value; }
AbstractFlexibleTestHystrixCommand(HystrixCommandKey commandKey, ExecutionIsolationStrategy isolationStrategy, AbstractTestHystrixCommand.ExecutionResult executionResult, int executionLatency, TestCircuitBreaker circuitBreaker, HystrixThreadPool threadPool, int timeout, CacheEnabled cacheEnabled, Object value, TryableSemaphore executionSemaphore, TryableSemaphore fallbackSemaphore, boolean circuitBreakerDisabled) { super(testPropsBuilder(circuitBreaker) .setCommandKey(commandKey) .setCircuitBreaker(circuitBreaker) .setMetrics(circuitBreaker.metrics) .setThreadPool(threadPool) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(isolationStrategy) .withExecutionTimeoutInMilliseconds(timeout) .withCircuitBreakerEnabled(!circuitBreakerDisabled)) .setExecutionSemaphore(executionSemaphore) .setFallbackSemaphore(fallbackSemaphore)); this.executionResult = executionResult; this.executionLatency = executionLatency; this.cacheEnabled = cacheEnabled; this.value = value; }
private TestCommandWithoutCircuitBreaker() { super(testPropsBuilder().setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE).withCircuitBreakerEnabled(false))); }
private LatchedSemaphoreCommand(String commandName, TestCircuitBreaker circuitBreaker, TryableSemaphore semaphore, CountDownLatch startLatch, CountDownLatch waitLatch) { super(testPropsBuilder() .setCommandKey(HystrixCommandKey.Factory.asKey(commandName)) .setCircuitBreaker(circuitBreaker) .setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE) .withCircuitBreakerEnabled(false)) .setExecutionSemaphore(semaphore)); this.startLatch = startLatch; this.waitLatch = waitLatch; }
public NoRequestCacheTimeoutWithoutFallback(TestCircuitBreaker circuitBreaker) { super(testPropsBuilder(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE).withExecutionTimeoutInMilliseconds(200).withCircuitBreakerEnabled(false))); // we want it to timeout }
protected TestCommand() { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("testTimeoutConcurrency")) .andCommandKey(HystrixCommandKey.Factory.asKey("testTimeoutConcurrencyCommand")) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(3) .withCircuitBreakerEnabled(false) .withFallbackIsolationSemaphoreMaxConcurrentRequests(NUM_CONCURRENT_COMMANDS)) .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter() .withCoreSize(NUM_CONCURRENT_COMMANDS) .withMaxQueueSize(NUM_CONCURRENT_COMMANDS) .withQueueSizeRejectionThreshold(NUM_CONCURRENT_COMMANDS))); }
private LatchedSemaphoreCommand(String commandName, TestCircuitBreaker circuitBreaker, TryableSemaphoreActual semaphore, CountDownLatch startLatch, CountDownLatch waitLatch) { super(testPropsBuilder() .setCommandKey(HystrixCommandKey.Factory.asKey(commandName)) .setCircuitBreaker(circuitBreaker) .setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE) .withCircuitBreakerEnabled(false)) .setExecutionSemaphore(semaphore)); this.startLatch = startLatch; this.waitLatch = waitLatch; }
public RequestCacheTimeoutWithoutFallback(TestCircuitBreaker circuitBreaker) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionTimeoutInMilliseconds(200).withCircuitBreakerEnabled(false))); // we want it to timeout }
public NoRequestCacheTimeoutWithoutFallback(TestCircuitBreaker circuitBreaker) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionTimeoutInMilliseconds(200).withCircuitBreakerEnabled(false))); // we want it to timeout }