zoukankan      html  css  js  c++  java
  • 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

      

  • 相关阅读:
    JVM参数设置-jdk8参数设置
    JVM参数配置详解-包含JDK1.8
    IntelliJ Idea 常用快捷键列表
    架构组织形式的讨论,以及架构师之路的建议
    ElasticSearch-6.3.2 linux 安装
    CAT 安装运行配置教程
    JPMML解析PMML模型并导入数据进行分析生成结果
    第9章 多态和抽象
    第10章 接口
    第8章 类的高级概念
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8109413.html
Copyright © 2011-2022 走看看