.setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(isolation) .withExecutionIsolationSemaphoreMaxConcurrentRequests(0)) .setThreadPool(new HystrixThreadPool() {
private TestSemaphoreCommandWithFallback(TestCircuitBreaker circuitBreaker, int executionSemaphoreCount, long executionSleep, Boolean fallback) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE).withExecutionIsolationSemaphoreMaxConcurrentRequests(executionSemaphoreCount))); this.executionSleep = executionSleep; this.fallback = Observable.just(fallback); }
private TestThreadIsolationWithSemaphoreSetSmallCommand(TestCircuitBreaker circuitBreaker, int poolSize, Action0 action) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(TestThreadIsolationWithSemaphoreSetSmallCommand.class.getSimpleName())) .setThreadPoolPropertiesDefaults(HystrixThreadPoolPropertiesTest.getUnitTestPropertiesBuilder() .withCoreSize(poolSize).withMaximumSize(poolSize).withMaxQueueSize(0)) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD) .withExecutionIsolationSemaphoreMaxConcurrentRequests(1))); this.action = action; }
/** * Constructor for {@link TaskHandler} using Semaphore isolation. The Hystrix command name is commandName. The group name is the Handler Name * (HystrixTaskHandler#getName) * * @param taskHandler The taskHandler to be wrapped * @param taskContext The context (Unique context required by Handlers to communicate with the container.) * @param commandName name of the command * @param taskRequestWrapper requestWrapper containing the data and the parameters * @param decoder Decoder sent by the Client * @param concurrentRequestSize no of Max Concurrent requests which can be served */ protected TaskHandlerExecutor(TaskHandler taskHandler, TaskContext taskContext, String commandName, TaskRequestWrapper<S> taskRequestWrapper , int concurrentRequestSize, Decoder decoder ) { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(taskHandler.getName())) .andCommandKey(HystrixCommandKey.Factory.asKey(commandName)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE). withExecutionIsolationSemaphoreMaxConcurrentRequests(concurrentRequestSize))) ; this.taskHandler = taskHandler; this.taskContext = taskContext; this.command = commandName; this.data = taskRequestWrapper.getData(); this.params = taskRequestWrapper.getParams(); this.taskRequestWrapper = taskRequestWrapper; this.decoder = decoder; this.eventBuilder = new ServiceProxyEvent.Builder(commandName, COMMAND_HANDLER); }
/** * Constructor for {@link TaskHandler} using Semaphore isolation. The Hystrix command name is commandName. The group name is the Handler Name * (HystrixTaskHandler#getName) * * @param taskHandler The taskHandler to be wrapped * @param taskContext The context (Unique context required by Handlers to communicate with the container.) * @param commandName name of the command * @param taskRequestWrapper requestWrapper containing the data and the parameters * @param concurrentRequestSize no of Max Concurrent requests which can be served */ protected TaskHandlerExecutor(TaskHandler taskHandler, TaskContext taskContext, String commandName, TaskRequestWrapper<S> taskRequestWrapper , int concurrentRequestSize ) { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(taskHandler.getName())) .andCommandKey(HystrixCommandKey.Factory.asKey(commandName)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE). withExecutionIsolationSemaphoreMaxConcurrentRequests(concurrentRequestSize))) ; this.taskHandler = taskHandler; this.taskContext = taskContext; this.command = commandName; this.data = taskRequestWrapper.getData(); this.params = taskRequestWrapper.getParams(); this.taskRequestWrapper = taskRequestWrapper; this.eventBuilder = new ServiceProxyEvent.Builder(commandName, COMMAND_HANDLER); }
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; }
public RibbonCommand(String groupKey, String commandKey, T restClient, Verb verb, String uri, MultivaluedMap<String, String> headers, MultivaluedMap<String, String> params, InputStream requestEntity) throws URISyntaxException { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults( // we want to default to semaphore-isolation since this wraps // 2 others commands that are already thread isolated HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(DynamicPropertyFactory.getInstance(). getIntProperty(ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores", 100).get()))); this.restClient = restClient; this.verb = verb; this.uri = new URI(uri); this.headers = headers; this.params = params; this.requestEntity = requestEntity; }
protected static Setter getSetter(final String commandKey, ZuulProperties zuulProperties, IClientConfig config) { // @formatter:off Setter commandSetter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand")) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); final HystrixCommandProperties.Setter setter = createSetter(config, commandKey, zuulProperties); if (zuulProperties.getRibbonIsolationStrategy() == ExecutionIsolationStrategy.SEMAPHORE){ final String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores"; // we want to default to semaphore-isolation since this wraps // 2 others commands that are already thread isolated final DynamicIntProperty value = DynamicPropertyFactory.getInstance() .getIntProperty(name, zuulProperties.getSemaphore().getMaxSemaphores()); setter.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get()); } else if (zuulProperties.getThreadPool().isUseSeparateThreadPools()) { final String threadPoolKey = zuulProperties.getThreadPool().getThreadPoolKeyPrefix() + commandKey; commandSetter.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolKey)); } return commandSetter.andCommandPropertiesDefaults(setter); // @formatter:on }
/** * @param request the request to execute * @param observable the observable that emits the response for this request (created with one of the * CaravanHttpClient implementations) * @param fallback the fallback response to emit if the original request fails */ public HttpHystrixCommand(CaravanHttpRequest request, Observable<CaravanHttpResponse> observable, Observable<CaravanHttpResponse> fallback) { super(Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(GROUP_KEY)) .andCommandKey(HystrixCommandKey.Factory.asKey(StringUtils.defaultString(request.getServiceId(), "UNKNOWN"))) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionIsolationStrategy(getIsolationStrategy(request)) .withExecutionIsolationSemaphoreMaxConcurrentRequests(10000))); this.request = request; this.observable = observable; this.fallback = fallback; }
public HostCommand(String groupKey, String commandKey, HttpClient httpclient, HttpHost httpHost, HttpRequest httpRequest) { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults( // we want to default to semaphore-isolation since this wraps // 2 others commands that are already thread isolated HystrixCommandProperties.Setter() .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(DynamicPropertyFactory.getInstance(). getIntProperty(ZuulConstants.ZUUL_HTTPCLIENT + commandKey + ".semaphore.maxSemaphores", 100).get()))); this.httpclient = httpclient; this.httpHost = httpHost; this.httpRequest = httpRequest; }
@Override public HystrixCommand.Setter create(Target<?> target, Method method) { String groupKey = target.name(); String commandKey = Feign.configKey(target.type(), method); return HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(timeout) .withExecutionIsolationSemaphoreMaxConcurrentRequests(connections)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); } };
public static HystrixCommandProperties.Setter create(URL url, String method) { return HystrixCommandProperties.Setter().withCircuitBreakerSleepWindowInMilliseconds(url.getMethodParameter(method, "sleepWindowInMilliseconds", 5000)) .withCircuitBreakerErrorThresholdPercentage(url.getMethodParameter(method, "errorThresholdPercentage", 50)) .withCircuitBreakerRequestVolumeThreshold(url.getMethodParameter(method, "requestVolumeThreshold", 20)) .withExecutionIsolationThreadInterruptOnTimeout(true) .withExecutionTimeoutInMilliseconds(url.getMethodParameter(method, "timeoutInMilliseconds", 1000)) .withFallbackIsolationSemaphoreMaxConcurrentRequests(url.getMethodParameter(method, "fallbackMaxConcurrentRequests", 50)) .withExecutionIsolationStrategy(IsolationStrategy.getIsolationStrategy(url)) .withExecutionIsolationSemaphoreMaxConcurrentRequests(url.getMethodParameter(method, "maxConcurrentRequests", 10)); } }
.withCircuitBreakerEnabled(true) .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests()) .withCircuitBreakerErrorThresholdPercentage(hystrixHandle.getErrorThresholdPercentage()) .withCircuitBreakerRequestVolumeThreshold(hystrixHandle.getRequestVolumeThreshold())
/** * 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); }
private TestSemaphoreCommand(TestCircuitBreaker circuitBreaker, int executionSemaphoreCount, long executionSleep, int resultBehavior, int fallbackBehavior) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(executionSemaphoreCount))); this.executionSleep = executionSleep; this.resultBehavior = resultBehavior; this.fallbackBehavior = fallbackBehavior; }
ResettableCommand(int timeout, int semaphoreCount, int poolCoreSize) { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GROUP")) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(timeout) .withExecutionIsolationSemaphoreMaxConcurrentRequests(semaphoreCount)) .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(poolCoreSize))); }
protected AsynchronousObservableCommand() { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GROUP")) .andCommandKey(HystrixCommandKey.Factory.asKey("AsyncObservable")) .andCommandPropertiesDefaults(new HystrixCommandProperties.Setter().withExecutionIsolationSemaphoreMaxConcurrentRequests(1000)) ); }
private TestSemaphoreCommandWithFallback(TestCircuitBreaker circuitBreaker, int executionSemaphoreCount, long executionSleep, Boolean fallback) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE).withExecutionIsolationSemaphoreMaxConcurrentRequests(executionSemaphoreCount))); this.executionSleep = executionSleep; this.fallback = fallback; }
private TestSemaphoreCommand(TestCircuitBreaker circuitBreaker, int executionSemaphoreCount, long executionSleep, int resultBehavior, int fallbackBehavior) { super(testPropsBuilder().setCircuitBreaker(circuitBreaker).setMetrics(circuitBreaker.metrics) .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter() .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationSemaphoreMaxConcurrentRequests(executionSemaphoreCount))); this.executionSleep = executionSleep; this.resultBehavior = resultBehavior; this.fallbackBehavior = fallbackBehavior; this.asyncFallbackException = FALLBACK_FAILURE_ASYNC; }
protected SynchronousObservableCommand() { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GROUP")) .andCommandKey(HystrixCommandKey.Factory.asKey("SyncObservable")) .andCommandPropertiesDefaults(new HystrixCommandProperties.Setter().withExecutionIsolationSemaphoreMaxConcurrentRequests(1000)) ); }