Update 系统设计基础.md

补充漏桶与令牌桶的说明和示意图。
This commit is contained in:
CyC2018
2026-10-25 19:34:23 +08:00
parent 5422b53ef0
commit 0cd19245c7
3 changed files with 75 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

+4
View File
@@ -111,6 +111,10 @@
- 降级:主动关闭部分非核心功能,从而保证核心功能可用;
- 熔断:某个依赖的服务持续出错时,暂时不再调用它而是直接返回默认结果,避免故障沿着调用链扩散。
漏桶以固定速率处理请求,桶满时丢弃新的请求;令牌桶以固定速率放入令牌,请求拿到令牌才能被处理,桶中积累的令牌允许一定的突发流量。
<div align="center"> <img src="pics/rate-limit.png" width="580px"/> </div><br>
熔断器有关闭、打开和半开三种状态:失败率超过阈值时打开;打开一段时间后进入半开状态,放行少量请求试探,成功则关闭,失败则重新打开。
<div align="center"> <img src="pics/circuit-breaker.png" width="500px"/> </div><br>
+71
View File
@@ -0,0 +1,71 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.sub { font-size: 11px; fill: #888; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #666; stroke-width: 1.3; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #C0C0C0; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">漏桶与令牌桶</text>
<rect x="20" y="45" width="290" height="240" rx="8" class="frame"/>
<text x="30" y="63" class="b">漏桶</text>
<line x1="95" y1="80" x2="95" y2="108" class="arrow "/>
<line x1="125" y1="80" x2="125" y2="108" class="arrow "/>
<line x1="155" y1="80" x2="155" y2="108" class="arrow "/>
<line x1="185" y1="80" x2="185" y2="108" class="arrow "/>
<text x="140" y="75" class="c sub">请求</text>
<path d="M90,110 L102,210 L188,210 L200,110" class="line"/>
<rect x="104" y="185" width="82" height="18" rx="3" fill="#B1DDF0"/>
<rect x="104" y="163" width="82" height="18" rx="3" fill="#B1DDF0"/>
<rect x="104" y="141" width="82" height="18" rx="3" fill="#B1DDF0"/>
<rect x="104" y="119" width="82" height="18" rx="3" fill="#B1DDF0"/>
<text x="82" y="170" class="e sub">排队</text>
<line x1="205" y1="116" x2="250" y2="116" class="arrow red"/>
<text x="255" y="120" class="note">桶满丢弃</text>
<line x1="145" y1="212" x2="145" y2="250" class="arrow "/>
<text x="155" y="240" class="ok">固定速率处理</text>
<rect x="330" y="45" width="290" height="240" rx="8" class="frame"/>
<text x="340" y="63" class="b">令牌桶</text>
<line x1="430" y1="80" x2="430" y2="108" class="arrow "/>
<text x="440" y="92" class="sub">固定速率放入令牌</text>
<path d="M380,110 L392,210 L478,210 L490,110" class="line"/>
<circle cx="410" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
<circle cx="435" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
<circle cx="460" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
<circle cx="422" cy="175" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
<circle cx="448" cy="175" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
<text x="435" y="140" class="c sub">桶满后不再放入</text>
<rect x="513" y="143" width="80" height="30" rx="6" class="shadow"/>
<rect x="510" y="140" width="80" height="30" rx="6" fill="#B0E3E6"/>
<text x="550" y="159.5" class="b c">请求</text>
<line x1="507" y1="165" x2="470" y2="190" class="arrow "/>
<text x="500" y="196" class="sub">取走令牌</text>
<line x1="550" y1="173" x2="550" y2="245" class="arrow green"/>
<text x="550" y="262" class="c ok">有令牌:处理</text>
<text x="550" y="278" class="c note">没有令牌:拒绝</text>
<text x="435" y="238" class="c sub">积累的令牌允许突发流量</text>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB