Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Hystrix timeout with environment variable

In order to change Hystrix's default request timeout (1000ms), one must set the following property : hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000

What is the corresponding environment variable ?

I would like to "tune" the timeout on my favorite cloud platform without touching the source code first. I'm pretty sure this one doesn't work : HYSTRIX_COMMAND_DEFAULT_EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS=2000


EDIT : Problem was found with Spring Cloud Camden / Spring Boot 1.4.

like image 683
Michael Técourt Avatar asked Feb 06 '17 16:02

Michael Técourt


People also ask

How do I set timeout in Hystrix?

Now, add the @Hystrix command and @HystrixProperty for the Rest API and define the timeout in milliseconds value. Next, define the fallback method fallback_hello() if the request takes a long time to respond. In this example, REST API written in main Spring Boot application class file itself.

What is the default timeout for Hystrix?

After quick investigation we discovered that Hystrix has a default timeout set to 500ms and apparently that wasn't enough for Garage service during holiday peaks.

What is the ideal value for Hystrix timeout?

For example, if your Ribbon connection timeout is one second and the Ribbon client might retry the request three times, than your Hystrix timeout should be slightly more than three seconds.

How does hystrix timeout work?

If you notice when you execute the test, the test will exit after 5,000 ms instead of waiting for 15,000 ms and will throw a HystrixRuntimeException. This demonstrates how Hystrix does not wait longer than the configured timeout for a response. This helps make the system protected by Hystrix more responsive.


3 Answers

VM options and environment variables can be referenced from application configuration, which is often a more convenient way to set properties with longer names.

For example, one can define the following reference in application.yml:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: ${service.timeout}

which will be resolved from the VM option -Dservice.timeout=10000, setting the default Hystrix command timeout to 10 seconds. It is even simpler with environment variables - thanks to relaxed binding, any of these will work (export examples are for Linux):

  • export service.timeout=10000
  • export service_timeout=10000
  • export SERVICE.TIMEOUT=10000
  • export SERVICE_TIMEOUT=10000

The common approach is to use lowercase.dot.separated for VM arguments and ALL_CAPS_WITH_UNDERSCORES for environment variables.

like image 127
jihor Avatar answered Sep 25 '22 18:09

jihor


You could try expression with a default value:

hystrix.command.default.execution.isolation.thread.timeoutIn‌Milliseconds: ${SERVICE_TIMEOUT:2000}

In case you have SERVICE_TIMEOUTsystem variable - it will be used by an application, otherwise, a default value will be picked up.

like image 34
Danylo Zatorsky Avatar answered Sep 22 '22 18:09

Danylo Zatorsky


Found more of a workaround than a solution, using SPRING_APPLICATION_JSON environment variable :

SPRING_APPLICATION_JSON='{ "hystrix" : { "command" : { "default" : { "execution" : { "isolation" : { "thread" : { "timeoutInMilliseconds" : 3000 } } } } } } }'

like image 24
Michael Técourt Avatar answered Sep 23 '22 18:09

Michael Técourt