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

女生的网名这么多〃 提交于 2019-11-30 05:18:38

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

This pattern is defined in the Hystrix documentation

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.

The reason why we only use semaphore is because

  1. We want to throttle number of requests to primary & secondary (may be more) combined
  2. Since isolation is already achieved by the actual hystrix command thread pools (that this facade proxies), we dont need to need to worry about isolatation at this level using threadpools (each thread in the pool has a fixed overhead interms of resource consumption, unlike semaphore which is just a counter). So, lightweight semaphore is good enough

Reference: https://github.com/Netflix/Hystrix/wiki/How-To-Use#primary--secondary-with-fallback

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