南宁横县网站建设推广/app推广方式有哪些
Sentinel是阿里开源的项目,提供了流量控制,熔断降级,系统负载包含等多个维度来保障服务之间的稳定性。
Sentinel主要特性:
Sentinel与Hystrix的区别:
关于Sentinel与Hystrix的区别详细:https://developer.aliyun.com/article/633786
总结:
Hystrix常用的线程池隔离会造成线程上下文切换的overhead比较大;Hystrix使用的信号量对某个资源调用的并发数进行控制,效果不错,但是无法对满调用进行自动降级;Sentinel通过并发线程数的流量控制提供信号量隔离的功能。此外Sentinel支持熔断降级维度更多,可对多种指标进行流控、熔断,且提供了实时监控和控制面板,功能更为强大。
Sentinel分为两个部分:
- 核心库(java客户端)不依赖任何框架/库,能够运行于所有java运行时环境,同时对Dubbo/SpringCloud等框架也有较好的支持。
- 控制台(Dashboard)基于Spring Boot开发,打包后可以直接运行,不需要额外的Tomcat等应用容器。
1、下载sentinel Dashboard,https://github.com/alibaba/sentinel/releases
2、cmd 运行java -jar sentinel-dashboard-1.7.1.jar。
3、访问http://localhost:8080,账户密码都是sentinel。
简单使用
1,新建项目
2,POM文件
<dependencies><!--nacos客户端 服务注册--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--sentinel 流量监控,服务熔断,服务降级等--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><!--持久化--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--web 监控--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId></dependency></dependencies>
3,YML文件
server:port: 6001
spring:application:name: sentienel-dashboard-servicecloud:nacos:discovery:#nacos服务注册中心地址server-addr: localhost:8848sentinel:transport:#sentinel dashboard 地址dashboard: localhost:8080#默认8179端口port: 8179#监控暴露 启动服务访问http://localhost:port/actuator/sentinel会返回json信息,说明已经整合好了Sentinel
management:endpoints:web:exposure:include: "*"
4,主启动类
@SpringBootApplication
@EnableDiscoveryClient
public class SentinelDashboard6001Main {public static void main(String[] args) {SpringApplication.run(SentinelDashboard6001Main.class,args);}
}
5,业务类
@RestController
public class SentinelController {@GetMapping("/testA")public String getA(){return "test A";}@GetMapping("/testB")public String getB(){return "test B";}
}
访问http://localhost:6001/testB