Configuring executionTimeoutInMilliseconds for hystrix
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();
}
}
`
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?
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.
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: are you extending HystrixCommand like in the above code or using annotations to set up hystrix?
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..?