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. javascript 数组的组合

    javascript 数组的组合 一.前言 二.数组的组合 concat()方法 push(...items) 其他方法 三.结束语 一.前言 今天在开发项目过程中,遇到了一个需求,先请求了30个数据 ...

  2. 关于tomcat的一些基础知识

    tomcat的启动环境是要需要配置jdk的,本次示例用的是jdk1.8和tomcat 8.5. jdk环境变量配置可以在网上随意找到,这里就不再作示范了. 什么是Tomcat Tomcat简单的说就是 ...

  3. HMM隐马尔可夫模型来龙去脉(一)

    目录 隐马尔可夫模型HMM学习导航 一.认识贝叶斯网络 1.概念原理介绍 2.举例解析 二.马尔可夫模型 1.概念原理介绍 2.举例解析 三.隐马尔可夫模型 1.概念原理介绍 2.举例解析 四.隐马尔 ...

  4. client-go workqueue demo

    链接地址:https://github.com/kubernetes/client-go [root@wangjq examples]# tree . ├── create-update-delete ...

  5. centos yum 安装golang

    rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install golan ...

  6. 你还在用a标签吗?——用button替代a

    前言:a标签,不止你在用,我也在用.但某些时候我们可以考虑用button替代a. 在多页应用中,a标签很常见,我们常用来作为一个普通超链接,进行页面跳转. 而在单页应用中,我们使用路由进行页面切换,a ...

  7. JavaScript中pipe实战

    JavaScript中pipe原理 代码示例 const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x); 原理 一行代码 ...

  8. 23种设计模式 - 单一职责(Decorator - Bridge)

    其他设计模式 23种设计模式(C++) 每一种都有对应理解的相关代码示例 → Git原码 ⌨ 单一职责 在软件组件的设计中,如果责任划分的不清晰,使用继承得到的结果往往是随着需求的变化,子类急剧膨胀, ...

  9. asterisk 传真服务器配置

    摘要: asterisk 可以作为电子传真服务器,进行收发电子传真.但是配置起来,比较麻烦,需要一番折腾.在这儿分享一下电子传真的配置,希望对朋友们有所帮助. 正题: asterisk 如果需要收发电 ...

  10. 2020重新出发,NOSQL,什么是Redis?

    @ 目录 Redis是什么? NoSQL和传统数据库的区别 Redis的优点 Redis在Java Web中的应用 缓存 高速读/写场合 Redis是什么? Redis 是一个由 Salvatore ...