Hystrix icon indicating copy to clipboard operation
Hystrix copied to clipboard

Configuring executionTimeoutInMilliseconds for hystrix

Open emailssa opened this issue 9 years ago • 5 comments

Hi

I m trying to configure withExecutionTimeoutInMilliseconds for hystrix. But this doesn't seem to work. Just to check the timeout, i'm passing it as 10000 millisec and in the run() function i have done Thread.sleep(3000).

Expectation run() function execution shouldn't be interrupted till 10 sec and if it takes longer than that, execute fallback().

Actual Fallback is getting called after default 1 sec. Irrespective of whatever timeout i set.

Am i missing something here ?

Code ` public class GetDataFromRecommServiceCommand extends HystrixCommand {

private IRecomService                     recomService;
private RecommendRequest                  request;
private int                               timeout;
private INotifyListener<RecommendResponse> callback;

private static final Logger               logger = LoggerFactory.getLogger(GetDataFromRecommServiceCommand.class);

public GetDataFromRecommServiceCommand(IRecomService recomService, RecommendRequest request, int timeoutInMillisecond,
        INotifyListener<RecommendResponse> callback) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GetDataFromRecommService"))
            .andCommandKey(HystrixCommandKey.Factory.asKey("GetDataFromRecommServiceKey"))
            .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("GetDataFromRecommServicePool"))
            .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeoutInMillisecond))
            .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withFallbackIsolationSemaphoreMaxConcurrentRequests(100)));

    this.recomService = recomService;
    this.request = request;
    this.timeout = timeoutInMillisecond;
    this.callback = callback;
}

@Override
protected RecommendResponse run() throws Exception {
	Thread.sleep(3000);
    RecommendResponse response = recomService.getRecommendations(request);
    callback.notify(response);
    return response;
}

@Override
protected RecommendResponse getFallback() {
    logger.warn("Sending Fallback response. CurrentTimeout is: " + timeout + " millisec");
    return new RecommendResponse();
}

}

`

emailssa avatar Jun 13 '17 16:06 emailssa

That appears correct to me. Can you try installing the metrics stream as in this example app? That will expose an endpoint where you can get a listing of current configuration and that might shed light on what's happening?

mattrjacobs avatar Jun 14 '17 22:06 mattrjacobs

Might be a silly question at first, but is your command key unique? The HystrixPropertiesFactory will cache the arguments based on the key and if you share the key the actual timeout will depend on which HystrixCommand is created first.

davidjanke avatar Jun 24 '17 13:06 davidjanke

Was this issue resolved? We are seeing a similar problem in our environments, I was curious to see if there was a solution to this problem.

deepanandi avatar Jul 17 '17 19:07 deepanandi

@deepanandi: are you extending HystrixCommand like in the above code or using annotations to set up hystrix?

davidjanke avatar Jul 18 '17 06:07 davidjanke

We are using annotations and like you said previously our command key were not unique. But i was curious if there was anyother reason apart from that or command key being unique was the solution..?

deepanandi avatar Jul 20 '17 16:07 deepanandi