Zuul 默认 hystrix 隔离策略为 SEMAPHORE

Posted

技术标签:

【中文标题】Zuul 默认 hystrix 隔离策略为 SEMAPHORE【英文标题】:Zuul defaulting hystrix isolation strategy to SEMAPHORE 【发布时间】:2016-04-03 15:54:24 【问题描述】:

这是我之前的问题的延续,在我的 hystrix 仪表板中,线程池部分继续加载:- Hystrix Dashboard with Turbine issue

为什么zuul强制hystrix的隔离策略是SEMAPHORE。我尝试将配置添加到我的 application.yml 但它仍然忽略它并使用 SEMAPHORE。有什么我在这里想念的吗。或者我将如何将其从 SEMAPHORE 更改为 THREAD。

Application.yml

info:
  component: Zuul Server

eureka:
 client:
   service-url: 
      defaultZone: http://localhost:8761/eureka/

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

server:
  port: 8006

zuul:
  routes:
    UserCards-V1: 
         path: /user/v1/accountholders/*/cards/**
         service-id: usercards-v1
         strip-prefix: false
    UserTransactions-V1_1: 
         path: /user/v1/accountholders/*/transactions
         service-id: usertransactions-v1
         strip-prefix: false
    UserTransactions-V1_2:  
         path: /user/v1/accountholders/*/accounts/*/transactions
         service-id: usertransactions-v1
         strip-prefix: false
    UserAccounts-V1: 
         path: /user/v1/accountholders/*/accounts/**
         service-id: useraccounts-v1
         strip-prefix: false
    UserCardholders-V1: 
         path: /user/v1/accountholders/**
         service-id: usercardholders-v1
         strip-prefix: false 

hystrix: 
  command.default.execution.isolation.strategy: THREAD
  command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
  command.default.execution.timeout.enabled: false
  command.default.fallback.enabled: false
  threadpool.default.coreSize: 20


ribbon:
  ConnectTimeout: 3000
  ReadTimeout: 60000

turbine: 
   clusterNameExpression: zuul

Hystrix.stream

data: "type":"HystrixCommand","name":"usercardholders-v1RibbonCommand","group":"RibbonCommand","currentTime":1451411772021,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0,"latencyTotal_mean":0,"latencyTotal":"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0,"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"SEMAPHORE","propertyValue_executionIsolationThreadTimeoutInMilliseconds":60000,"propertyValue_executionTimeoutInMilliseconds":60000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":100,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"RibbonCommand"

data: "type":"HystrixCommand","name":"usercards-v1RibbonCommand","group":"RibbonCommand","currentTime":1451411772522,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":1,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":1,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":1,"latencyExecute_mean":0,"latencyExecute":"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0,"latencyTotal_mean":0,"latencyTotal":"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0,"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"SEMAPHORE","propertyValue_executionIsolationThreadTimeoutInMilliseconds":60000,"propertyValue_executionTimeoutInMilliseconds":60000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":100,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"RibbonCommand"

【问题讨论】:

源代码中有一条注释表明这是故意的:github.com/spring-cloud/spring-cloud-netflix/blob/master/… @Dave Syer... 我可以覆盖它吗?这也可能是我在 hystrix 仪表板中看不到线程池的原因。我之前曾问过有关线程池的问题问题.,... 如果没有线程池肯定可以解释为什么 UI 中什么都没有。你试图覆盖它什么?看起来如果您知道命令键,您可以设置配置键。但是你为什么想要呢? 【参考方案1】:

zuul.ribbonIsolationStrategy=THREAD

你可以使用上面的命令来强制ZUUL使用THREAD策略

【讨论】:

【参考方案2】:

为什么zuul强制hystrix的隔离策略是SEMAPHORE

见https://github.com/spring-cloud/spring-cloud-netflix/blob/f3deb04521c8c0a0b6d9923b0b37d8673cb7fa0b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/support/AbstractRibbonCommand.java#L85。

// 我们希望默认为信号量隔离,因为它包含 // 其他 2 个已经被线程隔离的命令

【讨论】:

以上是关于Zuul 默认 hystrix 隔离策略为 SEMAPHORE的主要内容,如果未能解决你的问题,请参考以下文章

无法使用自定义生成器策略为 getter 名称创建记录

使用 Azure 策略为所有资源类型启用 Azure Defender

skill——iptables

iptables

0604-Zuul构建API Gateway-Zuul的回退

微服务架构中zuul的两种隔离机制实验