日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

七.Hystrix Timeout机制

發布時間:2025/3/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 七.Hystrix Timeout机制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

因為在一個復雜的系統里,可能你的依賴接口的性能很不穩定,有時候2ms,200ms,2s,如果你不對各種依賴接口的調用做超時的控制來給你的服務提供安全保護措施,那么很可能你的服務就被依賴服務的性能給拖死了,大量的接口調用很慢,大量線程就卡死了。

(1)execution.isolation.thread.timeoutInMilliseconds

  手動設置timeout時長,一個command運行超出這個時間,就被認為是timeout,然后將hystrix command標識為timeout,同時執行fallback降級邏輯,默認是1000,也就是1000毫秒。

HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(int value)

?

(2)execution.timeout.enabled

  控制是否要打開timeout機制,默認是true

HystrixCommandProperties.Setter().withExecutionTimeoutEnabled(boolean value)

?

/*** 獲取商品信息* @author 張三豐**/ public class GetProductInfoCommand extends HystrixCommand<ProductInfo> {private Long productId;public GetProductInfoCommand(Long productId) {super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ProductInfoService")).andCommandKey(HystrixCommandKey.Factory.asKey("GetProductInfoCommand")).andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("GetProductInfoPool")).andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(10).withMaxQueueSize(12).withQueueSizeRejectionThreshold(15)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(30).withCircuitBreakerErrorThresholdPercentage(40).withCircuitBreakerSleepWindowInMilliseconds(3000).withExecutionTimeoutInMilliseconds(500)//超時時間500毫秒.withFallbackIsolationSemaphoreMaxConcurrentRequests(30)) ); this.productId = productId;}@Overrideprotected ProductInfo run() throws Exception {System.out.println("調用接口,查詢商品數據,productId=" + productId); if(productId.equals(-2L)) {Thread.sleep(3000); }return JSONObject.parseObject("數據", ProductInfo.class); }@Overrideprotected ProductInfo getFallback() {ProductInfo productInfo = new ProductInfo();productInfo.setName("降級商品"); return productInfo;}}

?

轉載于:https://www.cnblogs.com/z-3FENG/p/9696477.html

總結

以上是生活随笔為你收集整理的七.Hystrix Timeout机制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。