Hystrix是一种用于复杂分布式系统中延迟和容错的Netflix API,它使用隔板模式技术进行线程隔离.有人可以详细说明.
有人可以解释一下Hystrix.我用Google搜索了,但我还不清楚.
请给我一个Hystrix用法的例子.
谢谢你的帮助.
我注意到我的应用程序中的一些命令失败了
Caused by: ! com.netflix.hystrix.exception.HystrixRuntimeException: GetAPICommand timed-out and no fallback available.
out: ! at com.netflix.hystrix.HystrixCommand.getFallbackOrThrowException(HystrixCommand.java:1631)
out: ! at com.netflix.hystrix.HystrixCommand.access$2000(HystrixCommand.java:97)
out: ! at com.netflix.hystrix.HystrixCommand$TimeoutObservable$1$1.tick(HystrixCommand.java:1025)
out: ! at com.netflix.hystrix.HystrixCommand$1.performBlockingGetWithTimeout(HystrixCommand.java:621)
out: ! at com.netflix.hystrix.HystrixCommand$1.get(HystrixCommand.java:516)
out: ! at com.netflix.hystrix.HystrixCommand.execute(HystrixCommand.java:425)
out: Caused by: ! java.util.concurrent.TimeoutException: null
out: !... 11 common frames omitted
Run Code Online (Sandbox Code Playgroud)
这是我的Hystrix配置覆盖:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=210000
hystrix.threadpool.default.coreSize=50
hystrix.threadpool.default.maxQueueSize=100
hystrix.threadpool.default.queueSizeRejectionThreshold=50
Run Code Online (Sandbox Code Playgroud)
这是什么样的超时?它是外部应用程序的读/连接超时吗?我该如何调试呢?
我正在尝试运行Spring Boot(使用Spring Cloud)+ Eureka Server + Hystrix Dashboard和Turbine流,但是我遇到了一个问题,到目前为止我找不到任何解决方案.我使用Spring Boot 1.2.1.RELEASE和Spring Cloud 1.0.0.RC2.这是我有的:
第一个实例是运行Eureka服务器和Hystrix仪表板:
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
@EnableHystrixDashboard
@EnableDiscoveryClient
class Application {
public static void main(String[] args) {
SpringApplication.run Application, args
}
}
Run Code Online (Sandbox Code Playgroud)
在这里你可以找到build.gradle
该实例 - https://gist.github.com/wololock/570272ad7cf2d14a4d3c
Eureka服务器运行正常,我可以在eureka服务器仪表板上看到已注册的实例,我也可以LoadBalancer
使用其ID来获取已注册实例的URL.到目前为止一切都很好.
我有一些使用@EnableHystrix
注释运行的实例,@HystrixCommand
用于定义Hystrix必须监视哪些方法.当我将URL传递给单个实例的hystrix.stream到Hystrix仪表板时,我可以看到它运行没有问题.
我也有单独的Turbine服务器,而不是复杂的服务器:
@EnableAutoConfiguration
@EnableTurbine
@Configuration
@EnableDiscoveryClient
class Application {
public static void main(String[] args) {
SpringApplication.run Application, args
}
}
Run Code Online (Sandbox Code Playgroud)
在这里您可以找到build.gradle
Turbine服务器实例 - https://gist.github.com/wololock/ff0d855b8a890232851e
它使用非常简单的配置,主要基于样本涡轮应用程序提供的配置 - https://github.com/spring-cloud-samples/turbine
info:
component: Turbine
endpoints:
restart:
enabled: …
Run Code Online (Sandbox Code Playgroud) 我刚刚阅读了Hystrix指南,并试图了解默认断路器和恢复周期的运行方式,以及如何自定义其行为.
显然,如果电路跳闸,Hystrix会自动调用命令的getFallBack()
方法; 我明白这一点.但是,首先使电路跳闸的标准是什么?理想情况下,在我们考虑服务离线/不健康并使断路器跳闸之前,我想尝试多次尝试支持服务(例如,最多3次尝试).我怎么能实现这个,在哪里?
但我想如果我覆盖默认的断路器,我还必须覆盖处理默认恢复期的任何机制.如果支持服务出现故障,可能是出于以下几种原因之一:
在大多数情况下,仅仅等待N秒然后再次尝试的恢复期是不够的.如果服务中有错误,或者有人在数据中心拔出了一些网线,我们将始终从此服务中获取失败.只有在少数情况下,客户服务才能在没有任何人为干预的情况下自动修复自身.
所以我想我的下一个问题部分是" 如何自定义默认恢复期策略? ",但我猜主要是:" 当服务中断并需要人工干预时,如何使用Hystrix通知devops? "
我有同样的问题,我试图覆盖application.yaml中的hystrix属性.当我运行应用程序并使用localhost:port/app-context/hystrix.stream检查属性时,我得到所有默认值.
这是我的application.yaml中的hystrix配置
hystrix:
command.StoreSubmission.execution.isolation.thread.timeoutInMilliseconds: 30000
command.StoreSubmission.circuitBreaker.requestVolumeThreshold: 4
command.StoreSubmission.circuitBreaker.sleepWindowInMilliseconds: 60000
command.StoreSubmission.metrics.rollingStats.timeInMilliseconds: 180000
collapser.StoreSubmission.maxRequestsInBatch: 1
collapser.StoreSubmission.requestCache.enabled: FALSE
threadpool.StoreSubmission.coreSize: 30
threadpool.StoreSubmission.metrics.rollingStats.timeInMilliseconds: 180000
Run Code Online (Sandbox Code Playgroud)
这是我在浏览网址时看到的 - localhost:port/app-context/hystrix.stream [这是用于hystrix仪表板的相同流网址] -
data: {"type":"HystrixCommand","name":"storeSubmission","group":"StoreSubmission","currentTime":1435941064801,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountCollapsedRequests":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":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":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1}
data: {"type":"HystrixThreadPool","name":"StoreSubmission","currentTime":1435941064801,"currentActiveCount":0,"currentCompletedTaskCount":35,"currentCorePoolSize":30,"currentLargestPoolSize":30,"currentMaximumPoolSize":30,"currentPoolSize":30,"currentQueueSize":0,"currentTaskCount":35,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":180000,"reportingHosts":1}
Run Code Online (Sandbox Code Playgroud)
问题在于hystrix命令和collapser属性,其中正确设置了线程池属性.我的@configuration类中有以下注释-
@EnableAutoConfiguration(exclude=MongoAutoConfiguration.class)
@EnableHystrix
@EnableHystrixDashboard
Run Code Online (Sandbox Code Playgroud)
有人尝试在Spring-Boot应用程序中使用application.yaml配置hystrix命令属性,可以帮忙吗?
有没有办法在Spring Boot应用程序中HystrixCommand
使用@HystrixCommand
注释时失败的原因?看起来如果您实现自己的HystrixCommand
,您可以访问getFailedExecutionException
但是如何在使用注释时访问它?我希望能够根据发生的异常类型在回退方法中执行不同的操作.这可能吗?
我看到一个音符有关HystrixRequestContext.initializeContext()
,但HystrixRequestContext
不给你访问什么,有没有使用上下文来获取访问例外不同的方式?
我正在尝试使用hystrix-javanica为我的应用程序实现hystrix.
我已经配置了hystrix-configuration.properties,如下所示
hystrix.command.default.execution.isolation.strategy=SEMAPHORE
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000
hystrix.command.default.fallback.enabled=true
hystrix.command.default.circuitBreaker.enabled=true
hystrix.command.default.circuitBreaker.requestVolumeThreshold=3
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=50000
hystrix.command.default.circuitBreaker.errorThresholdPercentage=50
Run Code Online (Sandbox Code Playgroud)
短路模式工作正常,但我对此有疑问 hystrix.command.default.circuitBreaker.requestVolumeThreshold=3
通过文档链接
有人可以回答吗?
这个外部呼叫我有一个假装客户端:
@RequestMapping(method = RequestMethod.GET, value = "GetResourceA", consumes = "application/json")
@Cacheable("ResourceA")
List<Stop> getResourceA() throws MyOwnException;
Run Code Online (Sandbox Code Playgroud)
在我的application.yml
我有这个设置:
hystrix:
command:
default:
execution.isolation.thread.timeoutInMilliseconds: 1000
fallback.enabled: false
Run Code Online (Sandbox Code Playgroud)
现在,如果getResourceA超时,即完成时间超过一秒,我得到这个:
com.netflix.hystrix.exception.HystrixRuntimeException: getResourceA timed-out and no fallback available
Run Code Online (Sandbox Code Playgroud)
或者,如果我定义了一个我自己抛出异常的后备,我得到这个:
com.netflix.hystrix.exception.HystrixRuntimeException: getResourceA timed-out and fallback failed.
Run Code Online (Sandbox Code Playgroud)
我不能从后备中抛出自己的异常吗?
如果我希望在服务停止时抛出自己的异常怎么办?我想没有后备(因为我没有合理的价值从回退中返回),而是抛出我自己的错误,我可以抓住并让程序恢复.有人可以帮我解决这个问题吗?
Ben回答后更新:
所以我尝试了捕获HysterixRuntimeException并检查导致它的原因的方法,但最终得到了这个丑陋的代码:
try {
getResourceA();
} catch (HystrixRuntimeException e) {
if (e.getFailureType().name().equals("TIMEOUT")) {
throw new MyOwnException("Service timed out");
}
throw e;
}
Run Code Online (Sandbox Code Playgroud)
所有能够在超时时抛出MyOwnException的东西.肯定还有另一种方式吗?
我正在尝试使一些微服务更具弹性,并且重试某些类型的HTTP请求将有助于此.
重试超时会给客户带来非常缓慢的体验,因此我不打算在这种情况下重试.重试400s无济于事,因为错误的请求在几毫秒后仍然是一个错误的请求.
我想还有其他原因不能重试一些其他类型的错误,但是哪些错误以及为什么?
hystrix ×10
java ×3
spring ×3
spring-cloud ×3
spring-boot ×2
fail-fast ×1
feign ×1
groovy ×1
http ×1
httpresponse ×1
netflix ×1
spring-retry ×1
turbine ×1