Hystrix 使用与分析
- - ITeye博客 转载请注明出处哈:http://hot66hot.iteye.com/admin/blogs/2155036. 一:为什么需要Hystrix?. 在大中型分布式系统中,通常系统很多依赖(HTTP,hession,Netty,Dubbo等),如下图:. 在高并发访问下,这些依赖的稳定性与否对系统的影响非常大,但是依赖有很多不可控问题:如网络连接缓慢,资源繁忙,暂时不可用,服务脱机等..
{ "id":"1", "payload": "Sample Payload", "throw_exception":false, "delay_by": 0 }
{ "id":"1", "received":"Sample Payload", "payload":"Reply Message" }
import com.netflix.governator.annotations.Configuration; import rx.Observable; import service1.domain.Message; import service1.domain.MessageAcknowledgement; import java.util.concurrent.TimeUnit; public class MessageHandlerServiceImpl implements MessageHandlerService { @Configuration("reply.message") private String replyMessage; public Observable<MessageAcknowledgement> handleMessage(Message message) { logger.info("About to Acknowledge"); return Observable.timer(message.getDelayBy(), TimeUnit.MILLISECONDS) .map(l -> message.isThrowException()) .map(throwException -> { if (throwException) { throw new RuntimeException("Throwing an exception!"); } return new MessageAcknowledgement(message.getId(), message.getPayload(), replyMessage); }); } }
package aggregate.service; import aggregate.domain.Message; import aggregate.domain.MessageAcknowledgement; import feign.RequestLine; public interface RemoteCallService { @RequestLine("POST /message") MessageAcknowledgement handleMessage(Message message); }
RmoteCallService remoteCallService = Feign.builder() .encoder(new JacksonEncoder()) .decoder(new JacksonDecoder()) .target(RemoteCallService.class, "http://127.0.0.1:8889");
================================================================================ ---- Global Information -------------------------------------------------------- > request count 50 (OK=50 KO=0 ) > min response time 5007 (OK=5007 KO=- ) > max response time 34088 (OK=34088 KO=- ) > mean response time 17797 (OK=17797 KO=- ) > std deviation 8760 (OK=8760 KO=- ) > response time 50th percentile 19532 (OK=19532 KO=- ) > response time 75th percentile 24386 (OK=24386 KO=- ) > mean requests/sec 1.425 (OK=1.425 KO=- )
================================================================================ ---- Global Information -------------------------------------------------------- > request count 50 (OK=50 KO=0 ) > min response time 1 (OK=1 KO=- ) > max response time 1014 (OK=1014 KO=- ) > mean response time 22 (OK=22 KO=- ) > std deviation 141 (OK=141 KO=- ) > response time 50th percentile 2 (OK=2 KO=- ) > response time 75th percentile 2 (OK=2 KO=- ) > mean requests/sec 48.123 (OK=48.123 KO=- )