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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

聊聊hystrix的execution.isolation.semaphore.maxConcurrentRequests属性

發(fā)布時間:2025/4/5 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 聊聊hystrix的execution.isolation.semaphore.maxConcurrentRequests属性 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文主要研究一下hystrix的execution.isolation.semaphore.maxConcurrentRequests屬性

AbstractCommand.applyHystrixSemantics

hystrix-core-1.5.12-sources.jar!/com/netflix/hystrix/AbstractCommand.java

private Observable<R> applyHystrixSemantics(final AbstractCommand<R> _cmd) {// mark that we're starting execution on the ExecutionHook// if this hook throws an exception, then a fast-fail occurs with no fallback. No state is left inconsistentexecutionHook.onStart(_cmd);/* determine if we're allowed to execute */if (circuitBreaker.attemptExecution()) {final TryableSemaphore executionSemaphore = getExecutionSemaphore();final AtomicBoolean semaphoreHasBeenReleased = new AtomicBoolean(false);final Action0 singleSemaphoreRelease = new Action0() {@Overridepublic void call() {if (semaphoreHasBeenReleased.compareAndSet(false, true)) {executionSemaphore.release();}}};final Action1<Throwable> markExceptionThrown = new Action1<Throwable>() {@Overridepublic void call(Throwable t) {eventNotifier.markEvent(HystrixEventType.EXCEPTION_THROWN, commandKey);}};if (executionSemaphore.tryAcquire()) {try {/* used to track userThreadExecutionTime */executionResult = executionResult.setInvocationStartTime(System.currentTimeMillis());return executeCommandAndObserve(_cmd).doOnError(markExceptionThrown).doOnTerminate(singleSemaphoreRelease).doOnUnsubscribe(singleSemaphoreRelease);} catch (RuntimeException e) {return Observable.error(e);}} else {return handleSemaphoreRejectionViaFallback();}} else {return handleShortCircuitViaFallback();}} 這個方法調(diào)用了getExecutionSemaphore來獲取TryableSemaphore,執(zhí)行之前進行tryAcquire,執(zhí)行結束之后進行release

AbstractCommand.getExecutionSemaphore

hystrix-core-1.5.12-sources.jar!/com/netflix/hystrix/AbstractCommand.java

/*** Get the TryableSemaphore this HystrixCommand should use for execution if not running in a separate thread.* * @return TryableSemaphore*/protected TryableSemaphore getExecutionSemaphore() {if (properties.executionIsolationStrategy().get() == ExecutionIsolationStrategy.SEMAPHORE) {if (executionSemaphoreOverride == null) {TryableSemaphore _s = executionSemaphorePerCircuit.get(commandKey.name());if (_s == null) {// we didn't find one cache so setupexecutionSemaphorePerCircuit.putIfAbsent(commandKey.name(), new TryableSemaphoreActual(properties.executionIsolationSemaphoreMaxConcurrentRequests()));// assign whatever got set (this or another thread)return executionSemaphorePerCircuit.get(commandKey.name());} else {return _s;}} else {return executionSemaphoreOverride;}} else {// return NoOp implementation since we're not using SEMAPHORE isolationreturn TryableSemaphoreNoOp.DEFAULT;}}
  • 這里針對ExecutionIsolationStrategy進行判斷,如果是SEMAPHORE,則根據(jù)commandKey獲取或新建對應的TryableSemaphore
  • 創(chuàng)建的話,使用的是TryableSemaphoreActual,其numberOfPermits參數(shù)就是execution.isolation.semaphore.maxConcurrentRequests的值
  • 如果ExecutionIsolationStrategy是THREAD的話,這里TryableSemaphore返回的是TryableSemaphoreNoOp.DEFAULT,也就是不做任何操作,都放行

TryableSemaphore

/* package */static interface TryableSemaphore {/*** Use like this:* <p>* * <pre>* if (s.tryAcquire()) {* try {* // do work that is protected by 's'* } finally {* s.release();* }* }* </pre>* * @return boolean*/public abstract boolean tryAcquire();/*** ONLY call release if tryAcquire returned true.* <p>* * <pre>* if (s.tryAcquire()) {* try {* // do work that is protected by 's'* } finally {* s.release();* }* }* </pre>*/public abstract void release();public abstract int getNumberOfPermitsUsed();} 定義了三個方法,tryAcquire,release、getNumberOfPermitsUsed

TryableSemaphoreActual

/*** Semaphore that only supports tryAcquire and never blocks and that supports a dynamic permit count.* <p>* Using AtomicInteger increment/decrement instead of java.util.concurrent.Semaphore since we don't need blocking and need a custom implementation to get the dynamic permit count and since* AtomicInteger achieves the same behavior and performance without the more complex implementation of the actual Semaphore class using AbstractQueueSynchronizer.*//* package */static class TryableSemaphoreActual implements TryableSemaphore {protected final HystrixProperty<Integer> numberOfPermits;private final AtomicInteger count = new AtomicInteger(0);public TryableSemaphoreActual(HystrixProperty<Integer> numberOfPermits) {this.numberOfPermits = numberOfPermits;}@Overridepublic boolean tryAcquire() {int currentCount = count.incrementAndGet();if (currentCount > numberOfPermits.get()) {count.decrementAndGet();return false;} else {return true;}}@Overridepublic void release() {count.decrementAndGet();}@Overridepublic int getNumberOfPermitsUsed() {return count.get();}} 內(nèi)部是使用AtomicInteger來進行計數(shù),tryAcquire方法,是先增,如果超過限制,則再減

TryableSemaphoreNoOp.DEFAULT

/* package */static class TryableSemaphoreNoOp implements TryableSemaphore {public static final TryableSemaphore DEFAULT = new TryableSemaphoreNoOp();@Overridepublic boolean tryAcquire() {return true;}@Overridepublic void release() {}@Overridepublic int getNumberOfPermitsUsed() {return 0;}} TryableSemaphoreNoOp.DEFAULT是TryableSemaphoreNoOp的單例,默認放行

小結

hystrix的ExecutionIsolationStrategy分為SEMAPHORE及THREAD模式,在command的執(zhí)行前后邏輯,內(nèi)置了對TryableSemaphore的tryAcquire及release操作。只是在獲取TryableSemaphore實現(xiàn)類的時候,針對SEMAPHORE模式才真正根據(jù)execution.isolation.semaphore.maxConcurrentRequests屬性進行限制,而如果是THREAD模式,則返回一個都放行的TryableSemaphoreNoOp實例。

doc

  • execution.isolation.semaphore.maxConcurrentRequests

總結

以上是生活随笔為你收集整理的聊聊hystrix的execution.isolation.semaphore.maxConcurrentRequests属性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 美女扒开屁股让男人捅 | 深夜视频在线看 | 日韩欧美久久精品 | 国产吞精囗交久久久 | 国产精品传媒麻豆hd | 网址在线观看你懂的 | 肌肉猛男裸体gay网站免费 | 精品人妻一区二区三区日产 | 在线观看黄av | 在线观看91av | 久草视频播放 | 婷婷视频| 色婷婷国产精品久久包臀 | 国产aaa视频 | 国产 福利 在线 | 国产高清一区二区三区 | 国产高清在线视频观看 | 国产精品久久久久毛片软件 | 婷婷综合六月 | 久操视频免费观看 | 久草中文在线观看 | 日韩久久久久 | 日本69视频 | 日韩精品在线观看一区二区 | 外国电影免费观看高清完整版 | 中文字幕黑丝 | 人妻aⅴ无码一区二区三区 阿v免费视频 | 中文字幕在线视频精品 | 中文字字幕在线中文乱码 | 国产鲁鲁视频在线观看免费 | 亚洲精品www久久久久久 | 四虎成人永久免费视频 | 国产a免费观看 | 日韩欧美三级 | 美女18毛片 | 国产黄色一级片 | 日日摸日日操 | 亚洲黄色网址大全 | 靠逼网站在线观看 | 日本中文字幕观看 | 一区二区三区视频播放 | 热热热av | 中文字幕永久在线播放 | 日日躁夜夜躁狠狠久久av | 男人的天堂视频网站 | 一级黄色性片 | 精品视频专区 | 屁屁影院一区二区三区 | 欧美一区免费 | 五月婷婷亚洲 | 日韩女同一区二区三区 | 中文日韩在线 | 久久久久久a | 欧美性生活xxx | 成年人免费网站视频 | 国产美女久久久 | 99在线成人精品视频 | 一区二区三区视频免费在线观看 | 青草草在线 | 国产精品视频一 | 美女久久| 国产亚洲欧美日韩精品一区二区三区 | 国产精品久久久久久网站 | 国产精品嫩草影院桃色 | 北条麻妃青青久久 | av资源共享 | 日韩成人在线播放 | 91免费看网站 | 曰韩一级片 | 国语精品久久 | 一级片视频网站 | 久久99久久99精品免观看粉嫩 | 亚洲国产第一 | 亚洲图片自拍偷拍 | 欧美大片www | 日本激情视频一区二区三区 | 一本色道久久综合熟妇 | 国产精品5 | 日韩中文免费 | 久久精品国产清自在天天线 | 亚洲 国产 欧美 日韩 | 蜜臀在线观看 | 伊人久久大香线蕉成人综合网 | 亚洲性生活 | 国产免费成人在线视频 | 亚洲精品在线观看免费 | 校园春色 亚洲色图 | av播播 | 亚洲性猛交 | 久久com| 少妇与公做了夜伦理69 | 无码人妻丰满熟妇区五十路 | 日韩精品视频播放 | 99国产精品99久久久久久粉嫩 | 红桃一区二区三区 | 成人黄色激情视频 | 亚洲视频一区在线播放 | 国产老肥熟| 欧美激情免费视频 |