文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Spring Cloud 关于:Spring Cloud Netflix Hystrix

2023-06-02 16:12

关注

  服务短路(CircuitBreaker)

  QPS:Query Per Second

  TPS:Transaction Per Second

  QPS:经过全链路压测,计算单机极限QPS,集群QPS=单机PQS*集群机器数量*可靠性比率

  全链路压测,除了压极限QPS,还有错误数量

  全链路:一个完整的业务流程操作

  JMeter:可调整型比较灵活

  Spring Cloud Hystrix Client

  官网:https://github.com/Netflix/Hystrix

  Reactive Java框架:

  java9 Flow API

  Reactor

  RxJava(Reactive X)

  激活Hystrix

  通过@EnableHystrix激活

  配置信息wiki:https//github.com/Netflix/Hystrix/wiki/Configuration

  Hystrix

  1. 注解方式

  @HystrixCommand(defaultFallback= "errorContent",commandProperties =

  {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value= "100")})

  @GetMapping("/user/count")

  public String userCount() throws InterruptedException {

  Random random = new Random();

  int nextInt = random.nextInt(200);

  System.out.println("random time > "+nextInt);

  Thread.sleep(nextInt);

  return userService.userCount();

  }

  public String errorContent() {

  System.out.println("超时了");

  return "-1";

  }

  2. 编程方式

  @GetMapping("/user/count2")

  public String userCount2() {

  return new MyHystrixCommand().execute();

  }

  private class MyHystrixCommand extends com.netflix.hystrix.HystrixCommand{

  protected MyHystrixCommand() {

  super(HystrixCommandGroupKey.Factory.asKey(""), 100);

  }

  @Override

  protected String run() throws Exception {

  Random random = new Random();

  int nextInt = random.nextInt(200);

  System.out.println("random time > "+nextInt);

  Thread.sleep(nextInt);

  return "OK";

  }

  @Override

  protected String getFallback() {

  return UserServiceProviderRestApiController.this.errorContent();

  }

  }

  对比其他Java执行方式:

  Feature

  public class FutrueDemo {

  public static void main(String[] args) {

  Random random = new Random();

  ExecutorService service = Executors.newFixedThreadPool(1);

  Future futrue = service.submit(() -> {

  int value = random.nextInt(200);

  System.out.print("睡眠"+value+"ms.");

  Thread.sleep(value);

  return "OK";

  });

  try {

  futrue.get(100,TimeUnit.MILLISECONDS);

  }catch (Exception e) {

  System.out.println("超时保护...");

  }

  service.shutdown();

  }

  }

  Health Endpoint (/actuator/health)

  {

  "status": "UP",

  "details": {

  "diskSpace": {

  "status": "UP",

  "details": {

  "total": 140382552064,

  "free": 7376781312,

  "threshold": 10485760

  }

  },

  "refreshScope": {

  "status": "UP"

  },

  "discoveryComposite": {

  "status": "UP",

  "details": {

  "discoveryClient": {

  "status": "UP",

  "details": {

  "services": ["user-service-consumer", "user-service-provider", "eureka-server"]

  }

  },

  "eureka": {

  "description": "Remote status from Eureka server",

  "status": "UP",

  "details": {

  "applications": {

  "USER-SERVICE-CONSUMER": 1,

  "EUREKA-SERVER": 2,

  "USER-SERVICE-PROVIDER": 2

  }

  }

  }

  }

  },

  "hystrix": {

  "status": "UP"

  }

  }

  }

  激活熔断保护无锡妇科医院排行 http://www.0510bhyy.com/

  @EnableCircuitBreaker 激活:@EnableHystrix + Spring Cloud功能

  @EnableHystrix 激活,没有一些Spring Cloud功能,如 /hystrix.stream

  hystrix Endpoint(/actuator/hystrix.stream)

  data: {

  "type": "HystrixCommand",

  "name": "MyHystrixCommand",

  "group": "",

  "currentTime": 1563720628038,

  "isCircuitBreakerOpen": false,

  "errorPercentage": 50,

  "errorCount": 2,

  "requestCount": 4,

  "rollingCountBadRequests": 0,

  "rollingCountCollapsedRequests": 0,

  "rollingCountEmit": 0,

  "rollingCountExceptionsThrown": 0,

  "rollingCountFailure": 0,

  "rollingCountFallbackEmit": 0,

  "rollingCountFallbackFailure": 0,

  "rollingCountFallbackMissing": 0,

  "rollingCountFallbackRejection": 0,

  "rollingCountFallbackSuccess": 1,

  "rollingCountResponsesFromCache": 0,

  "rollingCountSemaphoreRejected": 0,

  "rollingCountShortCircuited": 0,

  "rollingCountSuccess": 2,

  "rollingCountThreadPoolRejected": 0,

  "rollingCountTimeout": 1,

  "currentConcurrentExecutionCount": 0,

  "rollingMaxConcurrentExecutionCount": 1,

  "latencyExecute_mean": 0,

  "latencyExecute": {

  "0": 0,

  "25": 0,

  "50": 0,

  "75": 0,

  "90": 0,

  "95": 0,

  "99": 0,

  "99.5": 0,

  "100": 0

  },

  "latencyTotal_mean": 0,

  "latencyTotal": {

  "0": 0,

  "25": 0,

  "50": 0,

  "75": 0,

  "90": 0,

  "95": 0,

  "99": 0,

  "99.5": 0,

  "100": 0

  },

  "propertyValue_circuitBreakerRequestVolumeThreshold": 20,

  "propertyValue_circuitBreakerSleepWindowInMilliseconds": 5000,

  "propertyValue_circuitBreakerErrorThresholdPercentage": 50,

  "propertyValue_circuitBreakerForceOpen": false,

  "propertyValue_circuitBreakerForceClosed": false,

  "propertyValue_circuitBreakerEnabled": true,

  "propertyValue_executionIsolationStrategy": "THREAD",

  "propertyValue_executionIsolationThreadTimeoutInMilliseconds": 100,

  "propertyValue_executionTimeoutInMilliseconds": 100,

  "propertyValue_executionIsolationThreadInterruptOnTimeout": true,

  "propertyValue_executionIsolationThreadPoolKeyOverride": null,

  "propertyValue_executionIsolationSemaphoreMaxConcurrentRequests": 10,

  "propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests": 10,

  "propertyValue_metricsRollingStatisticalWindowInMilliseconds": 10000,

  "propertyValue_requestCacheEnabled": true,

  "propertyValue_requestLogEnabled": true,

  "reportingHosts": 1,

  "threadPool": ""

  }

  Spring Cloud Hystrix Dashboard

  使用@EnableHystrixDashboard激活

  @SpringBootApplication

  @EnableHystrixDashboard

  public class SpringCloudHystrixDashboardApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudHystrixDashboardApplication.class, args);

  }

  }

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯