英文:
Getting exception from Hystrix
问题
我正在使用Hystrix用于Spring Boot项目,但是遇到了超时异常。
以下是有关详细信息的控制器代码:
@GetMapping("/getData")
@HystrixCommand(fallbackMethod = "getDataFallBack", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "60000"),
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE")
})
public ResponseEntity<Object> getData() {
}
/**
* getData的降级方法
*/
public ResponseEntity<Object> getDataFallBack(Throwable e) {
LOGGER.info("在降级方法中", e);
}
在进行更多调用的测试,例如在5分钟内进行1500次调用时,会出现超时异常。在检查日志时,发现以下日志:
java.lang.RuntimeException: 无法获取执行信号量
at com.netflix.hystrix.AbstractCommand.handleSemaphoreRejectionViaFallback(AbstractCommand.java:966) ~[hystrix-core-1.5.18.jar!/:1.5.18]
...
请问有人可以告诉我如何解决这个问题吗?
英文:
I am using hystrix for spring boot project but getting timeout exception.
Please find below controller code for details
@GetMapping("/getData")
@HystrixCommand(fallbackMethod = "getDataFallBack", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "60000"), @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE") })
public ResponseEntity<Object> getData() {
}
/**
* Fallback method for getData
*/
public ResponseEntity<Object> getDataFallBack(Throwable e) {
LOGGER.info("In fallback method", e)
}
While testing with more calls like 1500 hits in 5 min then getting timeout exception. While checking logs then find below logs
java.lang.RuntimeException: could not acquire a semaphore for execution
at com.netflix.hystrix.AbstractCommand.handleSemaphoreRejectionViaFallback(AbstractCommand.java:966) ~[hystrix-core-1.5.18.jar!/:1.5.18]
at com.netflix.hystrix.AbstractCommand.applyHystrixSemantics(AbstractCommand.java:554) ~[hystrix-core-1.5.18.jar!/:1.5.18]
at com.netflix.hystrix.AbstractCommand.access$200(AbstractCommand.java:60) ~[hystrix-core-1.5.18.jar!/:1.5.18]
at com.netflix.hystrix.AbstractCommand$4.call(AbstractCommand.java:419) ~[hystrix-core-1.5.18.jar!/:1.5.18]
at com.netflix.hystrix.AbstractCommand$4.call(AbstractCommand.java:413) ~[hystrix-core-1.5.18.jar!/:1.5.18]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) [rxjava-1.3.8.jar!/:1.3.8]
at rx.Observable.unsafeSubscribe(Observable.java:10327) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) [rxjava-1.3.8.jar!/:1.3.8]
at rx.Observable.unsafeSubscribe(Observable.java:10327) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) [rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) [rxjava-1.3.8.jar!/:1.3.8]
Can someone please let me know how to solve this issue?
答案1
得分: 1
你需要添加hystrix属性execution.isolation.semaphore.maxConcurrentRequests,并将其设置为更大的数字(200)。
execution.isolation.semaphore.maxConcurrentRequests的默认值为“10”,因此方法getData()允许并行执行不超过10次。
类似地,您需要添加fallback.isolation.semaphore.maxConcurrentRequests,并将其设置为200,用于您的回退方法。
@GetMapping("/getData")
@HystrixCommand(fallbackMethod = "getDataFallBack", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "60000"),
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"),
@HystrixProperty(name = "execution.isolation.semaphore.maxConcurrentRequests", value = "200")
})
public ResponseEntity<Object> getData() {
}
英文:
You need to add hystrix property execution.isolation.semaphore.maxConcurrentRequests and set it to a higher number (200).
The default value of execution.isolation.semaphore.maxConcurrentRequests is "10" so the method getData() will be allowed to be executed in parallel for not more than 10 times.
Similarly you need to add fallback.isolation.semaphore.maxConcurrentRequests and set it to 200 for your fall back method.
@GetMapping("/getData")
@HystrixCommand(fallbackMethod = "getDataFallBack", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "60000"),
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"),@HystrixProperty(name = "execution.isolation.semaphore.maxConcurrentRequests", value = "200") })
public ResponseEntity<Object> getData() {
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论