Hystrix fuse - isolation strategy and fuse Source Overview

Thread Pool / semaphore

THREAD (thread isolation)

Using this embodiment, HystrixCommand will be executed on a separate thread, concurrent requests by limiting the number of threads in the thread pool. Different services by using different thread pools, each other will not be affected, to isolation.
hystrix using separate thread pool corresponding to each service provider , for isolating and limiting the services. So a service provider of high-latency or limited resources can only occur in the service provider corresponding thread pool.

SEMAPHORE (semaphore isolation)

In fact, a counter, in that way, HystrixCommand will be executed on the calling thread to restrict the amount of concurrent single service provider via semaphore, the overhead is relatively small (not so much because the thread pool), the number of concurrent requests by the quantity signal limits.

Hystrix default and recommended isolation thread (THREAD),
generally speaking, only when the call load unusually high (for example, each instance to call hundreds of times per second) only need semaphore isolation, since the use of such a scenario would cost THREAD relatively high. Semaphore isolation generally apply only to isolate non-network calls.

Under normal circumstances, the default thread isolation, keep the default.

Thread pool and semaphores are supported by fusing and current limiting. Compared to the thread pool, the amount of unwanted thread switching signal, thus avoiding unnecessary overhead. But the semaphore does not support asynchronous , also does not support time-out , that is when the requested service is not available, the signal will control the amount requested exceeds the limit returns immediately, but already holds the semaphore thread can wait for service or response from the timeout return that may appear a long wait. Under the thread pool mode, when the service exceeds the specified time is not responding, Hystrix thread will be notified by way of response to interrupts and ends immediately returned.

Source

Configuration Source

String groupKey() default "";

    String commandKey() default "";

    String threadPoolKey() default "";

    String fallbackMethod() default "";

    HystrixProperty[] commandProperties() default {};

    HystrixProperty[] threadPoolProperties() default {};

    Class<? extends Throwable>[] ignoreExceptions() default {};

    ObservableExecutionMode observableExecutionMode() default ObservableExecutionMode.EAGER;

    HystrixException[] raiseHystrixExceptions() default {};

    String defaultFallback() default "";

Wrapping request

HystrixCommandAspect section
annotated @HystrixCommand modified method, it will be executed HystrixCommand package, implemented by section.

1, the first request package
2, the calling
3, an exception return

ExcuteType, according to the return value type determines synchronous asynchronous, Future asynchronous callback, others are synchronous
Here Insert Picture Description

breaker

核心接口:com.netflix.hystrix.HystrixCircuitBreaker 实现类:HystrixCircuitBreakerImpl

一个Command key (也就是method)对应一个HystrixCircuitBreaker。

public boolean allowRequest();//是否允许命令执行

public boolean isOpen();//断路器是否打开(开关)

void markSuccess();//在半开状态时,执行成功反馈。将半开转为关闭。

void markNonSuccess();//在半开状态时,执行失败反馈。将半开转为打开。

Statistics command

com.netflix.hystrix.HystrixMetrics

public static class HealthCounts {
        private final long totalCount;执行总数
        private final long errorCount;失败数
        private final int errorPercentage;失败百分比

Rollback failed

AbstractCommand的方法executeCommandAndObserve的局部变量:handleFallback(final Func1<Throwable, Observable<R>> handleFallback)
如果失败,走失败逻辑。
Published 25 original articles · won praise 0 · Views 564

Guess you like

Origin blog.csdn.net/RaymondCoder/article/details/105323321