SpringCloudAlibaba Sentinel (flow control rules)

Posted by Paul1893 on Sun, 23 Jan 2022 22:54:32 +0100

SpringCloudAlibaba Sentinel (flow control rules)

What is Sentinel

A lightweight cloud native microservice oriented traffic control component.

Sentinel is mainly divided into two parts

  • Core library: Java client, which does not depend on any framework, can run all Java runtime environments, as well as Dubbo / spring cloud and other frameworks
    There is also good support.

  • Console: Dashboard is developed based on SpringBoot and can be run directly after packaging without additional application containers such as Tomcat.

Download and installation of Sentinel

Download address:
Select version

The download is a jar package, which can be run as long as there is a java running environment on the computer
Start Sentinel

Build demonstration cases

Create a new cloudalibaba-sentinel-service8401 model

  1. New model

  2. Change pom

        <!--SpringCloud alibaba sentinel-datasource-nacos: For subsequent persistence-->
        <!--SpringCloud alibaba Sentinel-->
        <!--spring cloud alibaba nacos-->
        <!--web/actuator These two are generally used together and written together-->
  3. Change yml

      port: 8401
        name: cloudalibaba-sentinel-service
            # Nacos service registry address
            server-addr: xxxxxx:8848
            # Configure Sentinel dashboard address
            dashboard: localhost:8080
            # The default port is 8719. If it is occupied, it will automatically start a + 1 scan from 8719 until the occupied port is found.
            port: 8719
            include: "*"
  4. Business class

  5. Start Sentinel and demo model and test

  • To display the started demo class in Sentinel visual interface, you must access the controller business once before displaying it (lazy loading mechanism)

Flow control rules

Noun analysis

Test effect
QPS + direct + fast failure

When the number of accesses per second is greater than 2, the failure page is displayed directly

Number of threads = 1

Number of threads 1: only one api: / testA request can be processed at a time. When the number of threads calling the api reaches the threshold, the flow is limited

Flow control mode - correlation

When testB, the resource associated with testA, reaches the threshold value, it limits the current

Flow control mode - link
Link flow control mode means that when the resources from an interface reach the current limit condition, the current limit is turned on

Flow control effect

  • Quick failure: direct failure, exception thrown: Blocked by Sentinel(flow limiting)

  • Warm Up: Warm Up, that is, when a large number of requests call suddenly, a buffer time will be given

    That is, preheat for 5s. The threshold in this 5s is the threshold divided by coldFactor (3 by default) = 3. The real threshold will not be reached until the preheating time is long

  • Queue up
    When the threshold is exceeded, don't refuse directly and let them queue up

    Failure occurs when the queue exceeds the timeout

Topics: Java Spring Spring Boot Distribution sentinel