Getting exception from Hystrix

不问归期 提交于 2021-01-29 10:35:50

问题


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:


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() {
    
    }


来源:https://stackoverflow.com/questions/64390516/getting-exception-from-hystrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!