[case32]alibaba Current Limiting Component Sentinel Actual Combat

  arch

Order

This article mainly studies how to use alibaba’s open source current limiting component Sentinel

maven

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sentinel</artifactId>
            <version>0.2.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  • Spring-cloud-starter-sentinel will install it locally if it does not exist in maven warehouse.

Configuration

server.port=8080
spring.application.name=sentinel-demo
spring.cloud.sentinel.port=7080
spring.cloud.sentinel.dashboard=localhost:9999
management.endpoints.web.exposure.include=*
  • The port of the application specified here is 8080, the communication port with sentinel server is 7080, and the address of sentinel server is localhost:9999

Start dashboard

java -Dserver.port=9999 \
-Dcsp.sentinel.dashboard.server=localhost:9999 \
-Dproject.name=sentinel-dashboard \
-jar sentinel-dashboard.jar

Add current limit rules

图片描述

Sentinel endpoint to access application:http://localhost: 8080/Actor/Sentinel, returned as follows:

{
  "DegradeRules": [],
  "SystemRules": [],
  "FlowRules": [
    {
      "resource": "/actuator",
      "limitApp": "default",
      "grade": 1,
      "count": 10,
      "strategy": 0,
      "refResource": null,
      "controlBehavior": 0,
      "warmUpPeriodSec": 10,
      "maxQueueingTimeMs": 500
    }
  ],
  "properties": {
    "enabled": true,
    "port": "7080",
    "dashboard": "localhost:9999",
    "filter": {
      "order": -2147483648,
      "urlPatterns": [
        "/*"
      ]
    }
  }
}

Current limit verification

wrk -t12 -c1000 -d10s -T30s  --latency http://localhost:8080/actuator

Access dashboard

图片描述

The number of rejections per minute can be seen, and the graphical curve can also be seen through real-time monitoring.

图片描述

The blue curve is b_qps, i.e. qps requested by blocked

After being fluidised, the interface returns

curl -i http://localhost:8080/actuator
HTTP/1.1 200
Transfer-Encoding: chunked
Date: Sun, 12 Aug 2018 13:41:15 GMT

Blocked by Sentinel (flow limiting)

Summary

The components used here are spring-cloud-alibaba components, similar to spring-cloud-netlfix, which are part of alibaba’s open source components integrated into spring cloud. It is very convenient to integrate sentinel now.

doc