This commit is contained in:
周伟
2022-05-11 19:04:14 +08:00
parent 9440ac7291
commit d9c5ffd627
826 changed files with 0 additions and 481675 deletions

View File

@@ -25,13 +25,7 @@
<meta name="generator" content="Hexo 4.2.0">
</head>
<body>
<div class="book-container">
<div class="book-sidebar">
@@ -55,289 +49,148 @@
<li><a href="/" class="current-tab">首页</a></li>
</ul>
<ul class="uncollapsible">
<li><a href="../">上一级</a></li>
</ul>
<ul class="uncollapsible">
<li>
<a href="/专栏/深入理解 Sentinel/01 开篇词:一次服务雪崩问题排查经历.md.html">01 开篇词:一次服务雪崩问题排查经历.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/02 为什么需要服务降级以及常见的几种降级方式.md.html">02 为什么需要服务降级以及常见的几种降级方式.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/03 为什么选择 SentinelSentinel 与 Hystrix 的对比.md.html">03 为什么选择 SentinelSentinel 与 Hystrix 的对比.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/04 Sentinel 基于滑动窗口的实时指标数据统计.md.html">04 Sentinel 基于滑动窗口的实时指标数据统计.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/05 Sentinel 的一些概念与核心类介绍.md.html">05 Sentinel 的一些概念与核心类介绍.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/06 Sentinel 中的责任链模式与 Sentinel 的整体工作流程.md.html">06 Sentinel 中的责任链模式与 Sentinel 的整体工作流程.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/07 Java SPI 及 SPI 在 Sentinel 中的应用.md.html">07 Java SPI 及 SPI 在 Sentinel 中的应用.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/08 资源指标数据统计的实现全解析(上).md.html">08 资源指标数据统计的实现全解析(上).md.html</a>
</li>
<li>
<a class="current-tab" href="/专栏/深入理解 Sentinel/09 资源指标数据统计的实现全解析(下).md.html">09 资源指标数据统计的实现全解析(下).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/10 限流降级与流量效果控制器(上).md.html">10 限流降级与流量效果控制器(上).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/11 限流降级与流量效果控制器(中).md.html">11 限流降级与流量效果控制器(中).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/12 限流降级与流量效果控制器(下).md.html">12 限流降级与流量效果控制器(下).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/13 熔断降级与系统自适应限流.md.html">13 熔断降级与系统自适应限流.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/14 黑白名单限流与热点参数限流.md.html">14 黑白名单限流与热点参数限流.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/15 自定义 ProcessorSlot 实现开关降级.md.html">15 自定义 ProcessorSlot 实现开关降级.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/16 Sentinel 动态数据源:规则动态配置.md.html">16 Sentinel 动态数据源:规则动态配置.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/17 Sentinel 主流框架适配.md.html">17 Sentinel 主流框架适配.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/18 Sentinel 集群限流的实现(上).md.html">18 Sentinel 集群限流的实现(上).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/19 Sentinel 集群限流的实现(下).md.html">19 Sentinel 集群限流的实现(下).md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/20 结束语Sentinel 对应用的性能影响如何?.md.html">20 结束语Sentinel 对应用的性能影响如何?.md.html</a>
</li>
<li>
<a href="/专栏/深入理解 Sentinel/21 番外篇Sentinel 1.8.0 熔断降级新特性解读.md.html">21 番外篇Sentinel 1.8.0 熔断降级新特性解读.md.html</a>
</li>
</ul>
</div>
</div>
<div class="sidebar-toggle" onclick="sidebar_toggle()" onmouseover="add_inner()" onmouseleave="remove_inner()">
<div class="sidebar-toggle-inner"></div>
</div>
<script>
function add_inner() {
@@ -347,9 +200,6 @@
inner.classList.add('show')
}
function remove_inner() {
let inner = document.querySelector('.sidebar-toggle-inner')
@@ -357,9 +207,6 @@
inner.classList.remove('show')
}
function sidebar_toggle() {
let sidebar_toggle = document.querySelector('.sidebar-toggle')
@@ -389,9 +236,6 @@
}
function open_sidebar() {
let sidebar = document.querySelector('.book-sidebar')
@@ -415,13 +259,7 @@ function hide_canvas() {
overlay.classList.remove('show')
}
</script>
<div class="off-canvas-content">
<div class="columns">
@@ -473,9 +311,6 @@ function hide_canvas() {
<p>StatisticSlot 源码框架如下:</p>
<pre><code class="language-java">public class StatisticSlot extends AbstractLinkedProcessorSlot&lt;DefaultNode&gt; {
@Override
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count,
@@ -509,9 +344,6 @@ function hide_canvas() {
}
}
@Override
public void exit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) {
@@ -525,9 +357,6 @@ function hide_canvas() {
}
}
</code></pre>
<ul>
@@ -549,9 +378,6 @@ function hide_canvas() {
node.increaseThreadNum();
node.addPassRequest(count);
</code></pre>
<p>如果调用来源不为空,也将调用来源的 StatisticNode 的当前并行占用线程数加 1、当前时间窗口被放行的请求数加 1代码如下</p>
@@ -565,9 +391,6 @@ function hide_canvas() {
context.getCurEntry().getOriginNode().addPassRequest(count);
}
</code></pre>
<p>如果流量类型为 IN则将资源全局唯一的 ClusterNode 的并行占用线程数、当前时间窗口被放行的请求数都增加 1代码如下</p>
@@ -581,9 +404,6 @@ function hide_canvas() {
Constants.ENTRY_NODE.addPassRequest(count);
}
</code></pre>
<p>回调所有 ProcessorSlotEntryCallback#onPass 方法,代码如下:</p>
@@ -595,9 +415,6 @@ function hide_canvas() {
handler.onPass(context, resourceWrapper, node, count, args);
}
</code></pre>
<p>可调用 StatisticSlotCallbackRegistry#addEntryCallback 静态方法注册 ProcessorSlotEntryCallbackProcessorSlotEntryCallback 接口的定义如下:</p>
@@ -609,9 +426,6 @@ function hide_canvas() {
void onBlocked(BlockException ex, Context context, ResourceWrapper resourceWrapper, T param, int count, Object... args);
}
</code></pre>
<ul>
@@ -653,9 +467,6 @@ function hide_canvas() {
handler.onPass(context, resourceWrapper, node, count, args);
}
</code></pre>
<p><strong>第三种情况:捕获到 BlockException 异常</strong>BlockException 异常只在需要拒绝请求时抛出。</p>
@@ -665,9 +476,6 @@ function hide_canvas() {
<pre><code class="language-java"> // Blocked, set block exception to current entry.
context.getCurEntry().setError(e);
// Add block count.
node.increaseBlockQps(count);
@@ -677,9 +485,6 @@ function hide_canvas() {
context.getCurEntry().getOriginNode().increaseBlockQps(count);
}
if (resourceWrapper.getEntryType() == EntryType.IN) {
// Add count for global inbound entry node for global statistics.
@@ -687,9 +492,6 @@ function hide_canvas() {
Constants.ENTRY_NODE.increaseBlockQps(count);
}
// Handle block event with registered entry callback handlers.
for (ProcessorSlotEntryCallback&lt;DefaultNode&gt; handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) {
@@ -697,13 +499,7 @@ function hide_canvas() {
handler.onBlocked(e, context, resourceWrapper, node, count, args);
}
throw e;
</code></pre>
<p>StatisticSlot 捕获 BlockException 异常只是为了收集被拒绝的请求BlockException 异常还是会往上抛出。抛出异常的目的是为了拦住请求,让入口处能够执行到 catch 代码块完成请求被拒绝后的服务降级处理。</p>
@@ -717,9 +513,6 @@ function hide_canvas() {
<pre><code class="language-java"> // Unexpected error, set error to current entry.
context.getCurEntry().setError(e);
// This should not happen.
node.increaseExceptionQps(count);
@@ -729,9 +522,6 @@ function hide_canvas() {
context.getCurEntry().getOriginNode().increaseExceptionQps(count);
}
if (resourceWrapper.getEntryType() == EntryType.IN) {
Constants.ENTRY_NODE.increaseExceptionQps(count);
@@ -739,9 +529,6 @@ function hide_canvas() {
}
throw e;
</code></pre>
<h4><strong>exit 方法</strong></h4>
@@ -809,9 +596,6 @@ function hide_canvas() {
fireExit(context, resourceWrapper, count);
}
</code></pre>
<p>exit 方法中通过 Context 可获取当前资源的 DefaultNode如果 entry 方法中未出现异常,那么说明请求是正常完成的,在请求正常完成情况下需要记录请求的执行耗时以及响应是否成功,可将当前时间减去调用链路上当前 Entry 的创建时间作为请求的执行耗时。</p>
@@ -825,9 +609,6 @@ function hide_canvas() {
......
private ClusterNode clusterNode;
@Override
public void addPassRequest(int count) {
@@ -839,9 +620,6 @@ function hide_canvas() {
}
}
</code></pre>
<p>记录某项指标数据指的是:针对当前请求,记录当前请求的某项指标数据,例如请求被放行、请求被拒绝、请求的执行耗时等。</p>
@@ -865,9 +643,6 @@ function hide_canvas() {
rollingCounterInMinute.addRT(rt);
}
</code></pre>
<p>rollingCounterInSecond 是一个秒级的滑动窗口rollingCounterInMinute 是一个分钟级的滑动窗口,类型为 ArrayMetric。分钟级的滑动窗口一共有 60 个 MetricBucket每个 MetricBucket 都被 WindowWrap 包装,每个 MetricBucket 统计一秒钟内的各项指标数据,如下图所示:</p>
@@ -893,9 +668,6 @@ function hide_canvas() {
OCCUPIED_PASS
}
</code></pre>
<ul>
@@ -957,9 +729,6 @@ function hide_canvas() {
</div>
</div>
</div>
</div>
@@ -967,9 +736,6 @@ function hide_canvas() {
</div>
</div>
<a class="off-canvas-overlay" onclick="hide_canvas()"></a>
</div>
@@ -985,17 +751,11 @@ function hide_canvas() {
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-NPSEEVD756');
@@ -1021,9 +781,6 @@ function hide_canvas() {
setCookie("lastPath", path)
}
function setCookie(cname, cvalue) {
var d = new Date();
@@ -1035,9 +792,6 @@ function hide_canvas() {
document.cookie = cname + "=" + cvalue + "; " + expires + ";path = /";
}
function getCookie(cname) {
var name = cname + "=";
@@ -1055,12 +809,6 @@ function hide_canvas() {
return "";
}
</script>
</html>