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. 理解RESTful原理

    如何给老婆解释什么是RESTful 老婆经常喜欢翻看我订阅的技术杂志,她总能从她的视角提出很多有趣的问题. 一个悠闲的周日下午,她午觉醒来,又习惯性的抓起这个月的杂志,饶有兴趣地看了起来. 果不其然, ...

  2. ceph osd跟cpu进行绑定

    通过cgroup将ceph-osd进程与某一个 CPU core 绑定脚本: mkdir -p /sys/fs/cgroup/cpuset/ceph # cup number : ,,, = - ec ...

  3. ovs 删除流表 指定 actions 中字段

    例: ovs-ofctl del-flows br-int in_port=100,out_group=100 -O openflow13 ovs-ofctl del-flows br-int in_ ...

  4. 操作系统-I/O(2)设备的分配

    作业执行前对设备提出申请时,指定某台具体的物理设备会让设备分配变得简单,但如果所指定设备出现故障,即便计算机系统中有同类设备也不能运行 设备独立性:用户通常不指定物理设备,而是指定逻辑设备,使得用户作 ...

  5. 建设开发者生态:6项华为API管理原则落地

    摘要: 为了向开发者提供良好.一致.稳定的华为API的体验,华为通过明确“API管理六项原则”,来支持开发者生态建设. 一个不开放的组织,会慢慢成为一潭僵水,一个封闭的系统,能量最终会耗尽,在产品开发 ...

  6. Promise对象入门

    简介 promise对象可以获取异步操作的消息,提供统一的API,各个异步操作都可以用同样的方法进行处理. promise对象不受外界影响,其有三种状态:pending(进行中).fulfilled( ...

  7. 前端修仙之路---一、如何用gulp搭建一套web前端开发框架

    引言 相信从事web前端开发的朋友都知道,现在流行的Vue.AngularJS等框架中,它们都有独立的脚手架来创建项目,比如Vue有vue-cli,Angular有angula-cli.脚手架可以一键 ...

  8. Lct 动态链接树

    通过树链剖分能了解轻重边 Acdreamer 的博客 http://blog.csdn.net/acdreamers/article/details/10591443 然后看杨哲大大的论文,能了解轻重 ...

  9. Salesforce LWC学习(二十三) Lightning Message Service 浅谈

    本篇参考: https://trailhead.salesforce.com/content/learn/superbadges/superbadge_lwc_specialist https://d ...

  10. 做一名合格的DBA

    Oracle DBA的角色定义 开发型DBA 数据库安装 数据库架构设计(架构和建模) 代码开发(存储过程,SQL) 运维型DBA 数据库日常监控 故障处理 性能优化 数据备份,容灾 数据库安全规划 ...