Spring Cloud Netflix Hystrix

  Spring Cloud Netflix Hystrix

  Service short-circuit (CircuitBreaker)

  QPS:Query Per Second

  TPS:Transaction Per Second

  QPS: After full link pressure measurement, calculation single limit QPS, QPS = single cluster number of clusters * the PQS machine reliability ratio *

  Link-pressure measurement, pressure limit QPS, as well as the number of errors in addition to

  Full link: a complete business process operations

  JMeter: flexible adjustable type

  Spring Cloud Hystrix Client

  Official website: https: //github.com/Netflix/Hystrix

  Reactive Java framework:

  java9 Flow API

  Reactor

  RxJava(Reactive X)

  Activation Hystrix

  By activating @EnableHystrix

  Configuration information wiki: https // github.com / Netflix / Hystrix / wiki / Configuration

  Hystrix

  1. annotation mode

  @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 ( "timeout");

  return "-1";

  }

  2. programmatically

  @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();

  }

  }

  Compared to other Java implementation:

  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 ( "time-out protection ...");

  }

  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"

  }

  }

  }

  Activation fuse protection

  @EnableCircuitBreaker activation: @EnableHystrix + Spring Cloud function

  @EnableHystrix activation, without some Spring Cloud features such as /hystrix.stream

  hystrix Endpoint(/actuator/hystrix.stream)

  data: { Wuxi and Women's Hospital ranked http://www.0510bhyy.com/

  "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

  Use @EnableHystrixDashboard activation

  @SpringBootApplication

  @EnableHystrixDashboard

  public class SpringCloudHystrixDashboardApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudHystrixDashboardApplication.class, args);

  }

  }


Guess you like

Origin blog.51cto.com/14335413/2436183