Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ZUUL forcing a SEMAPHORE isolation to execute its Hystrix commands?

I noticed Spring-Cloud ZUUL forces the execution isolation to SEMAPHORE instead of the THREAD defaults (as recommended by Netflix).

A comment in org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand says:

we want to default to semaphore-isolation since this wraps 2 others commands that are already thread isolated

But still I don't get it :-( What are those two other commands?

Configured this way, Zuul can only sched load but does not allow for timing out and let the client walk away. In short, even if the Hystrix timeout is set to 1000ms, clients will only be released once the call forwarded to the service down the chain returns (or timeouts because of a ReadTimeout for instance).

I tried to force THREAD isolation by overriding the configuration (per service unfortunately, since the default is forced in the code) and everything seems to work as expected. However, I'm not keen in doing this without proper understanding of the implications - certainly in regards of the comment found in the code and the defaults adopted by the Spring Cloud version of Zuul.

Can someone provide more information? Thx

like image 681
Bertrand Renuart Avatar asked Apr 30 '15 10:04

Bertrand Renuart


People also ask

How does Netflix ZUUL work?

It handles all the requests and performs the dynamic routing of microservice applications. It works as a front door for all the requests. It is also known as Edge Server. Zuul is built to enable dynamic routing, monitoring, resiliency, and security.

How does ZUUL filter work?

Zuul provides a framework to dynamically read, compile, and run these Filters. Filters do not communicate with each other directly - instead they share state through a RequestContext which is unique to each request. Filters are currently written in Groovy, although Zuul supports any JVM-based language.

When a circuit for a given route in ZUUL is tripped?

When a circuit for a given route in Zuul is tripped you can provide a fallback response by creating a bean of type ZuulFallbackProvider . Within this bean you need to specify the route ID the fallback is for and provide a ClientHttpResponse to return as a fallback.

Is ZUUL supported by spring cloud?

It is included in the spring cloud starter parent which you can easily import into your project. This config would take all requests with a header “X-Tenant: mbodev” and add an authorization header when forwarding the request to the given uri http://localhost:8080 .


1 Answers

The Hystrix documentation has a good example of why semaphore isolation is appropriate when wrapping commands that are thread isolated. Specifically, it says:

The façade HystrixCommand can use semaphore-isolation since all of the work it is doing is going through two other HystrixCommands that are already thread-isolated. It is unnecessary to have yet another layer of threading as long as the run() method of the façade is not doing any other network calls, retry logic, or other “error prone” things.

Update: The question mentions that thread isolation has to be configured for each service, but I found out that you can control the isolation of all Hystrix commands (including RibbonCommands) by setting the following property:

hystrix.command.default.execution.isolation.strategy = THREAD
like image 78
Jon Ekdahl Avatar answered Sep 28 '22 03:09

Jon Ekdahl