JAVA B2B2C e-commerce spring cloud Distributed Micro Services: Hystrix rely isolation

Dependence isolation

"Bulkhead mode" for those familiar with Docker readers are no strangers, Docker achieve isolation process through the "bulkhead mode", so as not to affect each other between the container and the container. The Hystrix Use this mode to achieve isolation thread pool, it creates a separate thread for each pool Hystrix command, this delay is too high dependency services under the package appear even if a command in Hystrix, understand springcloud architecture can add beg: 3536247259, only the call-dependent services have an impact, and will not slow down other services.

Reliance on services are identified by the thread pool, you can bring the following benefits:

The application itself is fully protected, not by uncontrollable affect dependent services. Even allocated to rely on the service thread pool is filled, it will not affect the rest of the application itself foreheads.

Can effectively reduce the risk of access to new services. If you run the new service access problems or instability, it will not affect the application of other requests.

When the dependent services failed to recover from its thread pool will be able to immediately clean up and restore the health service, in contrast to clean the container level recovery much slower.

When the dependent services configuration errors, the thread pool will quickly reflect this problem (by the number of failures, delays, timeouts and refused to increase the case of other indicators). At the same time, we can refresh in real-time dynamic attributes without affecting application functionality (introduced by the follow-up will be used in conjunction with the Spring Cloud Config Spring Cloud Bus) to handle it.

When the dependent services due to the adjustment mechanism to achieve its performance causes great changes occur, in which case the thread pool information monitoring indicators will reflect such changes. At the same time, we can also refresh themselves with real-time dynamic application dependent threshold value services to adjust to change relying party.

In addition to the above advantages by a thread pool isolation play services, each private thread pool provides built concurrent implementation can use it to build service-dependent synchronous asynchronous access.

In short, by implementing the thread pool to service dependent isolation, to make our application more robust, and does not depend on individual service problems caused by abnormal non-related services. It also allows us to become more flexible application, you can without stopping services, with adjustments to achieve dynamic configuration refresh performance configuration.

Although the isolation of the thread pool program with so many benefits, but many users may be concerned for each dependent on whether the service is assigned a thread pool would be too much load and increase system overhead. For this, the user need not worry too much, because most of these concerns are also engineers will be taken into account, Netflix in the design Hystrix, that the benefits of the thread pool overhead relative isolation brought about is second to none. At the same time, Netflix has done a test for the overhead associated thread pool, to demonstrate and to dispel concerns Hystrix achieve the performance impact.

The figure is a performance monitoring Hystrix Hystrix official Netflix command, the command 60 requests per second speed (QPS) to access a single service instance, the number of peaks of threads running of the service instance 350 per second.

We can see from the chart of statistics, using a thread pool thread pool without using the isolation and time-consuming isolation difference in the following table:

Comparison of isolation without using a thread pool thread pool using time-consuming isolation gap

The median 2ms 2ms 2ms
90 percentile 3ms 8ms 5ms
99 percentile 28ms 37ms 9ms

In 99% of cases, using a thread pool isolation delays have 9ms, for most of the demand for such consumption is minimal, not to mention a huge boost for the system on the stability and flexibility brings. While for most of us can ignore the request overhead thread pool, and for a small part of the delay itself is very small request (may need only 1ms), then the delay overhead 9ms is still very expensive. In fact Hystrix also has designed another one solution: semaphore.

In addition to using the thread pool Hystrix addition, a signal may be used to control the amount of concurrent single-dependent services, the amount of overhead to the signal overhead is much smaller than the thread pool, but it can not set the timeout and asynchronous access. Therefore, only the service is only dependent on the use of semaphores under sufficiently reliable. Semaphore support and in HystrixCommand HystrixObservableCommand at 2:

Command: If the isolation policy parameters execution.isolation.strategy set SEMAPHORE, Hystrix will use semaphore alternative thread pool to control the dependent services concurrency control.

Downgrade logic: When Hystrix attempt to downgrade logic when it will use semaphore in the calling thread.

Semaphore default value is 10, we can also control the number of concurrent threads through dynamic refresh configuration. A method for estimating the amount of signal magnitude and the estimated degree of concurrency is similar to the thread pool. Only memory data access request generally takes less than 1ms, performance can be achieved 5000rps, this level we can request the semaphore is set to 1 or 2, we can set this standard signal and the actual amount of time-consuming request.

How to use
said so much dependent on the benefits of isolation, then how do we use to achieve Hystrix dependent on isolation it? In fact, when we define a service on a downgrade, already achieved automatic dependent isolation.

In the previous example, we used the @HystrixCommand to be a function package became Hystrix command, where in addition to the definition of service degradation, Hystrix implementation of the framework will automatically call for the isolation function. So, rely on isolation, degradation of service in use at all times to achieve integration, so use Hystrix to achieve fault-tolerant protection services on the programming model is very handy, and consider more comprehensive. In addition to rely on isolation, service degradation, there are an important element: the circuit breaker. We'll do the next one in detail, these three important weapon constitutes a strong service portfolio Hystrix achieve fault tolerance protection.

java version of spring cloud social e-commerce platform source code, please add penguin beg: 3536247259

Guess you like

Origin blog.51cto.com/14622290/2466798