Hystrix使用Archaius作为配置的默认实现,下面介绍的是HystrixPropertiesStrategy的默认实现,你也可以通过插件方式重新实现。

  每一个配置有四个级别:

  • 全局默认

  当下面的三个配置都没有设置的时候,就会使用全局默认值。

  • 动态全局默认

  你可以手动设置全局配置。

  • 默认实例配置

  你也可以手动设置实例的默认值。

HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(int value)

  在构造时设置默认值

public HystrixCommandInstance(int id) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(500)));
this.id = id;
}

  还有些简便的构造方法

public HystrixCommandInstance(int id) {
super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"), 500);
this.id = id;
}
  • 动态实例

  可以为实例设置动态的配置来覆盖前面三中配置。动态配置以下面的格式配置。

hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds

  使用HystrixCommandKey.name来替换上面的HystrixCommandKey。

  据一个例子,如果一个命令的key叫做SubscriberGetAccount,那么配置如下:

hystrix.command.SubscriberGetAccount.execution.isolation.thread.timeoutInMilliseconds

命令配置

  下面是HystrixCommand的配置:

执行

  下面的配置来控制HystrixCommand.run的执行。

execution.isolation.strategy

  这个配置决定HystrixCommand.run用什么策略执行,有以下两种策略可以选择:

  THREAD--使用独立的线程池来执行,执行的并发量由线程池大小控制。

  SEMAPHORE--使用调用请求的线程池执行,执行的并发量由设定的信号量决定。

线程池还是信号量执行

  默认建议是使用线程池来运行HystrixCommand;使用信号量来运行HystrixObservableCommand。

  使用线程池执行可以在服务延时时对系统进行保护。

  通常只有在流量太大以至无法使用线程池的情况下使用信号量来执行HystrixCommand。通常使用在无网络请求。

  Netflix API有100个命令运行在40多个线程池,只有一小部分命令没有以线程池方式运行。哪些命令主要是从内存缓存中获取数据。

默认值 THREAD
可选值 THREAD,SEMAPHORE
默认配置 hystrix.command.default.execution.isolation.strategy
实例配置 hystrix.command.HystrixCommandKey.execution.isolation.strategy
设置默认实例配置

HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD)

HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)

execution.isolation.thread.timeoutInMilliseconds

  这个配置可以设置命令执行的timeout时间,如果发生了timeout,HystrixCommand会标识为TIMEOUT并且执行fallback逻辑。你也可以关闭timeout检查。

默认值 1000
默认属性 hystrix.command.default.execution.isolation.thread.timeoutInMillisecond
实例属性 hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds
设置默认实例属性 HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(int value)

execution.timeout.enabled

  设置是否开启HystrixCommand.run()的timeout检查。

默认值 true
默认属性 hystrix.command.default.execution.timeout.enabled
实例属性 hystrix.command.HystrixCommandKey.execution.timeout.enabled
设置默认实例属性 HystrixCommandProperties.Setter() .withExecutionTimeoutEnabled(boolean value)

execution.isolation.thread.interruptOnTimeout

  设置当HystrixCommand.run()发生timeout后是否需要中断。

默认值 true
默认属性 hystrix.command.default.execution.isolation.thread.interruptOnTimeout
实例属性 hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnTimeout
设置默认实例属性 HystrixCommandProperties.Setter() .withExecutionIsolationThreadInterruptOnTimeout(boolean value)

execution.isolation.thread.interruptOnCancel

  设置当发生cancellation时,HystrixCommand.run()是否需要中断。

默认值 false
默认属性 hystrix.command.default.execution.isolation.thread.interruptOnCancel
实例属性 hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnCancel
设置默认实例属性 HystrixCommandProperties.Setter() .withExecutionIsolationThreadInterruptOnCancel(boolean value)

execution.isolation.semaphore.maxConcurrentRequests

  当HystrixCommand.run()使用ExecutionIsolationStrategy.SEMAPHORE执行时,设置请求的并发数。超过设置并发数的请求将被拒绝。设置信号量大小的逻辑和设置线程池大小的逻辑是一样的,但是信号量往往使用在执行快的命令上。

  据一个例子,5000rps的寻找内存中metrics并计算的单个实例,只需要设置2个信号量。这样信号量只占tomcat线程中很小的一部分,不会影响整体系统性能。

默认值 10
默认属性 hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
实例属性 hystrix.command.HystrixCommandKey.execution.isolation.semaphore.maxConcurrentRequests 
默认实例属性 HystrixCommandProperties.Setter() .withExecutionIsolationSemaphoreMaxConcurrentRequests(int value)

降级

  下面的配置来控制HystrixCommand.getFallback()的执行,这些配置适用于ExecutionIsolationStrategy.THREAD and ExecutionIsolationStrategy.SEMAPHORE.

fallback.isolation.semaphore.maxConcurrentRequests

  这个属性控制HystrixCommand.getFallback()最大的并发量。如果超过最大并发量,fallback执行将会被拒绝,然后抛出异常。

默认值 10
默认属性 hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests
实例属性 hystrix.command.HystrixCommandKey.fallback.isolation.semaphore.maxConcurrentRequests
默认实例属性 HystrixCommandProperties.Setter() .withFallbackIsolationSemaphoreMaxConcurrentRequests(int value)

fallback.enabled

  该配置控制是否开启HystrixCommand.getFallback()

默认值 true
默认属性 hystrix.command.default.fallback.enabled
实例属性 hystrix.command.HystrixCommandKey.fallback.enabled
默认实例属性 HystrixCommandProperties.Setter() .withFallbackEnabled(boolean value)

熔断

  熔断配置控制熔断器。

circuitBreaker.enabled

  该配置控制是否开启熔断器

默认值 true
默认属性 hystrix.command.default.circuitBreaker.enabled
实例属性 hystrix.command.HystrixCommandKey.circuitBreaker.enabled
默认实例属性 HystrixCommandProperties.Setter() .withCircuitBreakerEnabled(boolean value)

circuitBreaker.requestVolumeThreshold

  该配置设置窗口期内触发熔断的最小请求数,例如该值设置成20,当只有19个请求时,即使这19个请求都失败,也不会触发熔断。

默认值 20
默认属性 hystrix.command.default.circuitBreaker.requestVolumeThreshold
实例属性 hystrix.command.HystrixCommandKey.circuitBreaker.requestVolumeThreshold
默认实例属性 HystrixCommandProperties.Setter() .withCircuitBreakerRequestVolumeThreshold(int value)

circuitBreaker.sleepWindowInMilliseconds

  

hystrix文档翻译之配置的更多相关文章

  1. Hystrix线程池配置

    Hystrix配置文件配置 断路器: hystrix.command.default.circuitBreaker.requestVolumeThreshold(当在配置时间窗口内达到此数量的失败后, ...

  2. hystrix(4) properties配置

    这一节我们来讲hystrix的properties配置体系,properties配置也是各个功能模块的基础功能.hystrix将配置分成三个部分: 1.HystrixCommandProperties ...

  3. Hystrix 常用属性配置

    配置参数 默认值 说明 命令-执行属性配置 hystrix.command.default.execution.isolation.strategy THREAD 配置隔离策略,有效值 THREAD, ...

  4. 服务容错保护断路器Hystrix之五:配置

    接着<服务容错保护断路器Hystrix之二:Hystrix工作流程解析>中的<2.8.关于配置>再列举重要的配置如下 一.hystrix在生产中的建议 1.保持timeout的 ...

  5. Hystrix使用说明,配置参数说明

    一.什么情况下会触发fallback方法? 名字 描述 触发fallback EMIT 值传递 NO SUCCESS 执行完成,没有错误 NO FAILURE 执行抛出异常 YES TIMEOUT 执 ...

  6. feign使用hystrix熔断的配置

    熔断器hystrix 在分布式系统中,每个服务都可能会调用很多其他服务,被调用的那些服务就是依赖服务,有的时候某些依赖服务出现故障也是很正常的. Hystrix 可以让我们在分布式系统中对服务间的调用 ...

  7. Hystrix【参数配置及缓存】

    1.常用参数说明 hystrix参数的详细配置可参照 https://github.com/Netflix/Hystrix/wiki/Configuration 下面是一些常用的配置: 配置项 默认值 ...

  8. hystrix熔断器之配置

    HystrixCommandProperties命令执行相关配置: hystrix.command.[commandkey].execution.isolation.strategy 隔离策略THRE ...

  9. hystrix文档翻译之插件

    插件 可以通过实现插件来改变Hystrix的行为.可以通过HystrixPlugins来注册自定义插件,这些插件会被应用到HystrixCommand,HystrixObservableCommand ...

随机推荐

  1. Wireshark中的Checksum: 0x90c5 [validation disabled]问题

    Wireshark中的Checksum: 0x90c5 [validation disabled]问题 废话不多说先上问题图: 这是我在做关于DNS协议PPT的时候出现的协议树第五项展开结果,可以发现 ...

  2. 四则运算(C语言实现)

    四则运算(c语言实现) 合伙人:魏甫——3118004973  ,温钦益——3118004975 https://github.com/iamdate/work/tree/master 一.项目及其要 ...

  3. NumPy笔记-ndarray

    ndarray,N维数组对象(矩阵) 所有元素必须是相同类型 ndim属性,维度个数 shape属性,各维度大小 dtype属性,数据类型 创建ndarray np.array(collection) ...

  4. MPI实现Jacobi

    一.Jacobi迭代 #include<stdio.h> #include<mpi.h> #include<stdlib.h> #define totalsize ...

  5. [状压DP]P1441 题解 砝码称重

    前置知识:状压DP 洛谷传送门 emm....看到题目,我第一个想到的就是枚举.暴力大法好! 具体怎么枚举?当然是子集枚举啦!枚举出每一个可能的砝码选择方案.对于每一个合法的(也就是选取数量等于\(n ...

  6. “大地主”IPv6的地址实验配置

    上一篇文章,我们简单的介绍了一下IPv6协议的邻居发现BD和简单的基础配置,这里我们通过实验观察一下 IPv6邻居发现中会发送的报文,顺便熟悉一下,新的地址配置 根据拓扑图配置地址 这里原理和IPv4 ...

  7. Javascript循环和代码规范

    1 - 循环 1.1 for循环 语法结构 for(初始化变量; 条件表达式; 操作表达式 ){ //循环体 } 名称 作用 初始化变量 通常被用于初始化一个计数器,该表达式可以使用 var 关键字声 ...

  8. Appium + Python App自动化第一个脚本

    今天跟大家讲解一个Appium和Python App自动化的脚本.[1]打开你的夜神模拟器(或者连接你的手机) [2]打开桌面的Appium [3]下载你要测的App的apk文件,放到桌面[4]拖动你 ...

  9. linux系统工程师修改打开文件数限制代码教程。服务器运维技术

    提示linux文件打开错误,修改linux打开文件数参数. /etc/pam.d/login 添加 session required /lib/security/pam_limits.so 注意看这个 ...

  10. Unity调用PC摄像头

    转载于Unity3d圣典里面,具体哪位大侠写的我忘咯. using UnityEngine; using System.Collections; public class CameraTest : M ...