directory

  • preface
  • Service avalanche
  • Sentinel is what?
  • Sentinel VS Hystrix
  • Install the Sentinel
  • Use of Sentinel
  • conclusion

preface

The last article introduced Nacos as a configuration registry. This article will introduce the use of the following component Sentinel. \


Service avalanche

In microservice architecture, multiple service cascaded calls often occur, as shown in the following figure: A as A service provider, B as A service consumer, B calls A, C calls B, and D calls C. If A has A problem, B may fail to call B. If B has A problem, C may fail to call. In this way, the problem continues upward, causing the whole system to become unavailable, that is, the service avalanche.

There are many reasons for service avalanches, such as traffic surges, cache problems, hardware failures, program bugs, thread delays, etc.



Sentinel is what?

Sentinel translates to “Sentinel” and literally means if anything goes wrong in the country, he will be there first to keep out the danger. Alibaba’s Sentinel component is the Sentinel of distributed system, which protects the system from flow control, fuse downgrading, load protection and other aspects.

Key features of Sentinel:

Sentinel VS Hystrix

There’s a similar component in SpringCloud Netflix: the Hystrix porcupine. Here’s how sentinels compare to porcupine:



Sentinel features a Web console interface for monitoring and configuring traffic limiting rules, and Hystrix has long since stopped updating, making Sentinel the obvious alternative.

Install the Sentinel

Go to the Sentinel website and download the jar. The version used here is 1.8.0 github.com/alibaba/Sen…

To run Sentinel, install the Java environment. In Windows, open the CMD command line, switch to the directory where the JAR package is stored, and enter:

Java jar sentinel - dashboard - 1.8.0 comes with. The jarCopy the code

You can see the Sentinel startup log



Enter http://localhost:8080 in your browser to see the console interface. The default password is sentinel



Log in and you’ll find: Nothing

Use of Sentinel

Here we add Sentinel to the previous NACOS case. If you haven’t heard about NACOS yet, there is a link above. 1. Add a dependency to provider-service

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>  </dependency>Copy the code

2, application. Yml

server: port: 8888 spring: application: name: provider-service cloud: nacos: discovery: server-addr: 192.168.7.188:8848 sentinel: transport: dashboard: 192.168.7.188:8080 8719 # sentinel management: endpoints: web: exposure: include: '*'Copy the code

3. Add the controller for the test

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        return "hello sentinel!!";
    }
}
Copy the code

4. Start the NACOS service, then the Sentinel console, and then the provider-Service service

You can see the service in Nacos



5, input on the browser: http://localhost:8888/hello



And then we’ll see something coming out of Sentinel’s console



This means that we successfully started Sentinel and used it to monitor interface calls to our service.


conclusion

Today we have a brief introduction to how to use Sentinel, but more importantly, how to use Sentinel to perform current limiting, fusing, downscaling, etc. This will be covered in the next article. If this article is helpful, please give it a thumbs up 🙂