hystrix文档翻译之配置
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文档翻译之配置的更多相关文章
- Hystrix线程池配置
Hystrix配置文件配置 断路器: hystrix.command.default.circuitBreaker.requestVolumeThreshold(当在配置时间窗口内达到此数量的失败后, ...
- hystrix(4) properties配置
这一节我们来讲hystrix的properties配置体系,properties配置也是各个功能模块的基础功能.hystrix将配置分成三个部分: 1.HystrixCommandProperties ...
- Hystrix 常用属性配置
配置参数 默认值 说明 命令-执行属性配置 hystrix.command.default.execution.isolation.strategy THREAD 配置隔离策略,有效值 THREAD, ...
- 服务容错保护断路器Hystrix之五:配置
接着<服务容错保护断路器Hystrix之二:Hystrix工作流程解析>中的<2.8.关于配置>再列举重要的配置如下 一.hystrix在生产中的建议 1.保持timeout的 ...
- Hystrix使用说明,配置参数说明
一.什么情况下会触发fallback方法? 名字 描述 触发fallback EMIT 值传递 NO SUCCESS 执行完成,没有错误 NO FAILURE 执行抛出异常 YES TIMEOUT 执 ...
- feign使用hystrix熔断的配置
熔断器hystrix 在分布式系统中,每个服务都可能会调用很多其他服务,被调用的那些服务就是依赖服务,有的时候某些依赖服务出现故障也是很正常的. Hystrix 可以让我们在分布式系统中对服务间的调用 ...
- Hystrix【参数配置及缓存】
1.常用参数说明 hystrix参数的详细配置可参照 https://github.com/Netflix/Hystrix/wiki/Configuration 下面是一些常用的配置: 配置项 默认值 ...
- hystrix熔断器之配置
HystrixCommandProperties命令执行相关配置: hystrix.command.[commandkey].execution.isolation.strategy 隔离策略THRE ...
- hystrix文档翻译之插件
插件 可以通过实现插件来改变Hystrix的行为.可以通过HystrixPlugins来注册自定义插件,这些插件会被应用到HystrixCommand,HystrixObservableCommand ...
随机推荐
- PAT 2-08. 用扑克牌计算24点(25):
题目链接:http://www.patest.cn/contests/ds/2-08 解题思路:思路参考24点游戏技巧http://www.24game.com.cn/articles/points2 ...
- 动态数组java实现
数组是一种顺序存储的线性表,所有元素的内存地址是连续的. 动态数组相对于一般数组的优势是可以灵活地添加或删除元素.而一般数组则受限于固定的内存空间.只能有限的添加元素 动态数组(Dynamic Arr ...
- Kubernetes 编写自定义 controller
原文链接:Kubernetes编写自定义controller 来自kubernetes官方github的一张图: 如图所示,图中的组件分为client-go和custom controller两部分: ...
- ubuntu ARM 源配置
cat /etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu-ports/ xenial main deb-src http://mir ...
- Java算法——分治法
一.基本概念 在计算机科学中,分治法是一种很重要的算法.字面上的解释是“分而治之”,就是把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最后子问题可以简 ...
- python爬虫-贴吧
#!/usr/bin/python# coding=utf-8# 作者 :Y0010026# 创建时间 :2018/12/16 15:33# 文件 :spider_03.py# IDE :PyChar ...
- 以Winsows Service方式运行JupyterLab
有数据分析,数据挖掘,以及机器学习和深度学习实践经验的读者应该会对Jupyter Notebook这一工具十分熟悉,而JupyterLab是它的升级版本,其提供了更具扩展性,更加可定制化的功能选项. ...
- JS - 对金额数字实现千分位格式化处理
添加千分位处理: function fmoney(s, n) { n = n > 0 && n < = 20 ? n : 2; s = parseFloat((s + &q ...
- Node.js调试相关
如何进行Nodejs性能分析? nodejs性能最重要的两个部分:CPU耗时查看和内存泄漏排查 一,CPU相关 主要思路是两个:借助第三方的工具,以及借助v8自带的性能分析工具 借助第三方的工具 主要 ...
- git 合并两个分支的某个文件
软件开发基本都是多个feature分支并行开发,而在上线前有可能某个分支的开发或测试还没有完成,又或者是产品调整,取消了该分支功能的上线计划,我们在release前不合并该分支即可,然而如果该分支中的 ...