Technology Sharing

Spring Cloud Alibaba - Sentinel Distributed System Traffic Sentinel

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

insert image description here

Overview

With the popularity of microservices, the stability between services is becoming more and more important. Sentinel is a traffic management component for distributed, multi-language heterogeneous service architecture. It mainly takes traffic as the entry point to help developers ensure the stability of microservices from multiple dimensions such as traffic routing, traffic control, traffic shaping, circuit breaking and degradation, system adaptive overload protection, and hotspot traffic protection.

To put it simply, Sentinel is a traffic management component, which is equivalent to Spring Cloud Circurk Breaker.

feature

  • Rich application scenarios: Sentinel has taken over the core scenarios of Alibaba's Double 11 promotion traffic in the past 10 years, such as flash sales (that is, burst traffic is controlled within the range that the system capacity can bear), message peak load shifting, cluster traffic control, and real-time circuit breaking of downstream unavailable applications.
  • Complete real-time monitoring: Sentinel also provides real-time monitoring. You can see the second-level data of a single machine connected to the application in the console, or even the summary operation status of a cluster of less than 500 machines.
  • Extensive open source ecosystem: Sentinel provides out-of-the-box integration modules with other open source frameworks/libraries, such as Spring Cloud, Apache Dubbo, gRPC, and Quarkus. You only need to introduce the corresponding dependencies and perform simple configuration to quickly access Sentinel. At the same time, Sentinel provides native implementations in multiple languages ​​such as Java/Go/C.
  • Perfect SPI extension mechanism: Sentinel provides a simple, easy-to-use and perfect SPI extension interface. You can quickly customize the logic by implementing the extension interface, such as customizing rule management, adapting to dynamic data sources, etc.

Key features of Sentinel:
insert image description here

basic concept

resource

Resource is a key concept in Sentinel. It can be anything in a Java application, for example, a service provided by the application, or a service provided by another application called by the application, or even a piece of code. In the following documents, we will use resource to describe a code block.

As long as the code is defined through the Sentinel API, it is a resource and can be protected by Sentinel. In most cases, you can use method signatures, URLs, or even service names as resource names to identify resources.

rule
Rules set around the real-time status of resources can include flow control rules, circuit breaker and degradation rules, and system protection rules. All rules can be adjusted dynamically in real time. (Rules can be set in the Sentinel console, yml configuration, and java code)

Install Sentinel

The use of Sentinel can be divided into two parts:

  • Core library (Java client): does not depend on any framework/library and can run on Java 8 and aboveIt provides a runtime environment for versions of Apache ActiveMQ Artemis and also provides good support for frameworks such as Dubbo and Spring Cloud.
  • Dashboard: Dashboard is mainly responsible for managing push rules, monitoring, and managing machine information.

Download path:https://github.com/alibaba/Sentinel/releases

After downloading, find the jar package and run the command to start the Sentinel console

java -jar sentinel-dashboard-xxx.jar

The local environment must be jdk8 or above, and port 8080 is not occupied (Sentinel console port)
Starting from Sentinel 1.6.0, the Sentinel console introduces basic login functionality. The default username and password are both sentinel. Access URL: http://localhost:8080
insert image description here

Microservices introduce Sentinel case

Create a new microservice, introduce Nacos and Sentinel, register the service into Nacos, and perform traffic monitoring and circuit breaking and downgrading on the service

Introducing dependencies