9 StatisticSlot 資源指標資料統計

2021-10-09 13:50:47 字數 3059 閱讀 3173

statisticslot 是實現資源各項指標資料統計的 processorslot,它與 nodeselectorslot、clusterbuilderslot 組成了資源指標資料統計流水線,分工明確。

首先 nodeselectorslot 為資源建立 defaultnode,將 defaultnode 向下傳遞,clusterbuilderslot 負責給資源的 defaultnode 加工,新增 clusternode 這個零部件,再將 defaultnode 向下傳遞給 statisticslot。

statisticslot 在統計指標資料之前會先呼叫後續的 processorslot,根據後續 processorslot 判斷是否需要拒絕該請求的結果決定記錄哪些指標資料,這也是為什麼 sentinel 設計的責任鏈需要由前乙個 processorslot 在 entry 或者 exit 方法中呼叫 fireentry 或者 fireexit 完成呼叫下乙個 processorslot 的 entry 或 exit 方法,而不是使用 for 迴圈遍歷呼叫 processorslot 的原因。每個 processorslot 都有權決定是先等後續的 processorslot 執行完成再做自己的事情,還是先完成自己的事情再讓後續 processorslot 執行,與流水線有所區別。

public class statisticslot extends abstractlinkedprocessorslot

// add count for global inbound entry node for global statistics.

constants.entry_node.increasethreadnum();

constants.entry_node.addpassrequest(count);

}//這裡比較疑惑 為什麼context.getentrancenode()沒有進行統計

// handle pass event with registered entry callback handlers.

//可呼叫 statisticslotcallbackregistry#addentrycallback 靜態方法註冊 processorslotentrycallback

for (processorslotentrycallbackhandler : statisticslotcallbackregistry.getentrycallbacks())

//一種限流策略,不統計資料,只增減執行緒數

} catch (prioritywaitexception ex)

// add count for global inbound entry node for global statistics.

constants.entry_node.increasethreadnum();

}// handle pass event with registered entry callback handlers.

for (processorslotentrycallbackhandler : statisticslotcallbackregistry.getentrycallbacks())

} catch (blockexception e)

// add count for global inbound entry node for global statistics.

constants.entry_node.increaseblockqps(count);

}// handle block event with registered entry callback handlers.

for (processorslotentrycallbackhandler : statisticslotcallbackregistry.getentrycallbacks())

throw e;

} catch (throwable e)

constants.entry_node.increaseexceptionqps(count);

}throw e;}}

//在這裡統計rt響應時長

@override

defaultnode node = (defaultnode)context.getcurnode();

if (context.getcurentry().geterror() == null)

// record response time and success count.

node.addrtandsuccess(rt, count);

if (context.getcurentry().getoriginnode() != null)

node.decreasethreadnum();

if (context.getcurentry().getoriginnode() != null)

constants.entry_node.addrtandsuccess(rt, count);

constants.entry_node.decreasethreadnum();

}} else

// handle exit event with registered exit callback handlers.

collectionexitcallbacks = statisticslotcallbackregistry.getexitcallbacks();

for (processorslotexitcallback handler : exitcallbacks)

}}

entry方法基本分為四種情況 :

1. 正常通過(未被限流或降級)

2. 捕獲到型別為 prioritywaitexception 的異常 (乙個特殊的限流策略,不影響業務執行,只影響統計)

3. 捕獲到 blockexception 異常 (被限流阻斷,繼續外拋)

4. 捕獲到其它異常(並非指業務異常,因為此時業務**還未執行,通過捕獲呼叫 tracer#trace 方法記錄的(見helloworld例子))

exit方法主要做了兩件事情:

1.併發執行緒數減1

2.統計rt時間

9l0 062題庫資源分享

隨著testinside認證考題 testinside 9l0 062認證考試題庫助專業人士完成夢想,以及深入了解的9l0 062考試模式,分級標準和標記。我們有經驗豐富曾參與到試驗研究或自己參加過9l0 062認證考試的專業人士共同參與.testinside提供給你的是非傳統模式的學習指南並為您提...

入門SkinUI(9) 資源(7) 選單

1001 text ids website height 50 layout personalinfo.xml 1005 text ids website icon website.png 1006 text ids about icon about.png 1007 text ids quit i...

Docker筆記(9) 容器的資源分配

1.記憶體分配 記憶體限額與作業系統類似,容器可使用的記憶體包括兩部分 物理記憶體和swap。docker通過下面兩組引數來控制容器記憶體的使用量。1 m或 memory 設定記憶體的使用限額,例如100mb,2gb。2 memory swap 設定記憶體 swap的使用限額。預設情況下對容器記憶體...