When Spring Cloud’s stream-limiting downgrading component comes to mind, Netflix’s Hystrix usually comes to mind.

But in late 2018, Netflix announced that Hystrix would no longer be actively developed and that the project would be in maintenance mode. Hystrix 1.5.18 is stable enough to meet the needs of Netflix’s existing apps, so it will shift its focus to an adaptive implementation that responds more to real-time application performance. For the fuse breaker requirements of the new application, other projects will be adopted, and Netflix recommends Resilience4j.

Hystrix, a key Netflix suite for Spring Cloud, has become the app of choice to ensure microservice stability. In fact, in addition to Netflix and Resilience4j, there is another new option for stream limiting downgrade, namely Alibaba’s Sentinel component.

I. Brief introduction of Ali open Source Sentinel

In August 2018, Alibaba announced that Sentinel would be open source. At the same time, it launched an adaptor integrated with Dubbo, which was donated to the Apache Dubbo community.

1. The history of the Sentinel

Sentinel was born in 2012 and its main function is inlet flow control. From 2013 to 2017, Sentinel developed rapidly within Alibaba Group and became a basic technology module, covering all core scenarios. Sentinel has thus accumulated a large number of traffic aggregation scenarios and production practices. Sentinel became open source in 2018 and continues to evolve.

2. Adaptation of Sentinel to mainstream framework

Sentinel is divided into two parts:

The core library (Java client) is independent of any framework/library, can run in all Java runtime environments, and has good support for frameworks such as Dubbo/Spring Cloud. The Console (Dashboard) is based on Spring Boot and can be packaged to run directly without the need for additional application containers such as Tomcat.

Sentinel ADAPTS to a variety of mainstream frameworks, including Spring Cloud, Dubbo, etc. Sentinel’s open source enriches Alibaba’s micro service open source system and provides more solutions for stability components.

What problem does Sentinal solve

In the case of large-scale microservices architectures, avoiding an avalanche of services, minimizing downtime, and maximizing service availability is essential. Current limiting and downgrading is a very important means, and the specific implementation methods can be summarized as the eight-character proverbs, which are respectively current limiting, downgrading, fusing and isolation. Sentinel takes flow as the entry point to protect the stability of service from multiple dimensions such as flow control, fusing downgrading and system load protection.

Current limiting

Traffic limiting As the name implies, the system sets the highest QPS threshold for each type of request in advance. If the threshold is higher than the threshold, the system returns the request directly and does not invoke subsequent resources. Sentinel provides two traffic statistics methods, one is to count the number of concurrent threads, and the other is to count QPS. When the number of concurrent threads exceeds a certain threshold, new requests will be rejected immediately. When the QPS exceeds a certain threshold, the system can respond by direct rejection, cold start, and constant speed. Thus plays the role of flow control.

Fusing the drop

If the invocation of a target service is slow or there is a large number of timeouts, the invocation of the target service is cut off. For subsequent invocation requests, the target service is returned to quickly release resources. A circuit breaker typically requires a different recovery strategy to resume the call if the target service improves. For example, service A achieves tens of thousands of QPS per second, but service B cannot achieve tens of thousands of QPS per second at this time. Then, how to ensure that service B can still work normally when service A calls service B frequently? A common situation is that when service A calls service B, the response time of service B is too long due to the failure of service B to meet the requirements of high frequency calls, leading to the response time of service A, which will have A chain reaction affecting all applications on the whole chain of dependencies. In this case, the method of fusing and degrading is needed. Sentinel fuses or degrades services by limiting the number of concurrent threads and degrading resources through response time.

shape

Usually, the flow we encounter has the characteristics of randomness, irregularity and uncontrolled, but the processing capacity of the system is often limited. We need to shape the flow according to the processing capacity of the system, that is, regularization, so as to deal with the flow according to our needs. Here’s a good example of traffic shaping:

Sentinel controls the flow through three dimensions of resource invocation relationship, operation index and control effect, which can be combined flexibly.

System load protection

Microservices are very prone to avalanche effects and need to avoid the most dangerous scenario of service downtime.

Avalanche prevention is an important part of system protection. When system load is high, if you continue to let requests in, the system may crash and fail to respond. Sentinel also provides adaptive protection at the system level. In a clustered environment, network load balancing will forward the traffic that should be carried by one machine to other machines.

Main characteristics of Sentinel

Application scenarios

Sentinel follows alibaba’s core traffic driving scenarios in the past 10 years, such as SEC killing (i.e. burst traffic control within the range of system capacity), message peaking and valley filling, cluster flow control, real-time fusing of downstream unavailable applications, etc.

Real-time monitoring

Sentinel also provides real-time monitoring capabilities. From the console, you can see a summary of the performance of a single machine-by-second data, or even a cluster of less than 500 machines, for accessing the application.

ADAPTS to multiple open source components

Sentinel provides out-of-the-box integration modules with other open source frameworks/libraries, such as Spring Cloud, Dubbo, and gRPC. You can quickly access Sentinel by introducing the appropriate dependencies and simple configuration.

SPI support, easy to expand

Sentinel provides an easy-to-use, comprehensive SPI extension interface. You can quickly customize the logic by implementing an extension interface. For example, customize rule management and adapt dynamic data sources.

4. Sentinel open source ecology

Sentinel supports current major microservices development suites, especially Dubbo and Spring Cloud, and is an important implementation of Spring Cloud Alibaba suite.

5. Sentinel vs. Hystrix

Hystrix focuses on fault tolerance with isolation and fuses, calls that time out or are fuses fail quickly, and provides fallback mechanisms.

Sentinel focuses on:

  • Diversified flow control
  • Fusing the drop
  • System load protection
  • Real-time monitoring and console

A table is made to compare Sentinel and Hystrix features.

function Sentinel Hystrix resilience4j
Isolation strategy Semaphore isolation (concurrent thread flow limiting) Thread pool isolation/semaphore isolation Semaphore isolation
Fuse downgrading strategy Based on response time, exception ratio, number of exceptions Based on abnormal ratio Based on exception rate, response time
Real-time statistical implementation Sliding Windows (LeapArray) Sliding Windows (based on RxJava) Ring Bit Buffer
Dynamic Rule Configuration Support for multiple data sources Support for multiple data sources Support co., LTD.
scalability Multiple extension points Plug-in form Interface form
Annotation-based support support support support
Current limiting Based on QPS, traffic limiting based on call relationships is supported Limited support Rate Limiter
Traffic shaping Support preheating mode, constant speed mode, preheating queuing mode (can be configured in flow rules) Does not support Does not support
System adaptive protection support Does not support Does not support
The console Out of the box console for configuring rules, viewing second-level monitoring, machine discovery Simple monitoring view No console is provided, and other monitoring systems can be connected

reference

Sentinel Official Documentation

Scan our public account: Architecture evolution for first-hand technical information and original articles