%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="org.springside.examples.showcase.demos.hystrix.web.HystrixController,com.netflix.hystrix.*,com.netflix.hystrix.HystrixCommandMetrics.HealthCounts,com.netflix.hystrix.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%! %>
Web Service高级演示
Hystrix 演示
Netflix Hystrix 是一个延迟与容错类库,通过独立访问远程系统、服务和第三方库的节点,在复杂的分布式系统里停止雪崩及提供恢复能力。
演示操作
主要用户故事
- 在默认的正常状态,访问Hystrix服务和依赖资源,均返回正常结果。
- 将资源状态切换为"超时",访问依赖资源,需要在10秒后才返回结果。
- 访问Hystrix服务,2秒后超时,返回503。
- 三次超时后满足短路条件(60秒滚动窗口内起码有3个请求,50%失败),再次刷新服务,立即返回503。
- 10秒短路保护期内,所有访问都立即返回503,不会访问依赖资源。
- 保护期过后,会放行一个请求,如果还是超时,则继续保持短路状态。如果成功则重置所有计数器。
其他用户故事
- 将资源状态切换为"失败",访问依赖资源,立即返回500错误,访问Hystrix服务,即时返回503错误。
- 将异常处理方式切换为"返回默认用户",访问Hystrix服务,返回默认用户。
- 将异常处理方式切换为"访问备用节点",访问Hystrix服务,返回正确结果。
监控结果
<%
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("GetUserCommand");
HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key);
if (metrics!=null){
HealthCounts counts = metrics.getHealthCounts();
HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
%>
- 是否短路:<%= circuitBreaker.isOpen() %>
- 窗口内请求:<%= counts.getTotalRequests()%>,失败百分比:<%= counts.getErrorPercentage() %>%
- 窗口成功:<%= metrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS) %>, 超时:<%= metrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT) %>,失败:<%= metrics.getRollingCount(HystrixRollingNumberEvent.FAILURE) %>,短路:<%= metrics.getRollingCount(HystrixRollingNumberEvent.SHORT_CIRCUITED) %>
- 50%延时:<%= metrics.getTotalTimePercentile(50) +"ms"%>,90%延时:<%= metrics.getTotalTimePercentile(90) +"ms"%>,100%延时:<%= metrics.getTotalTimePercentile(100) +"ms"%>
<%} %>