Update 集群.md

重新绘制负载均衡的配图。
This commit is contained in:
CyC2018
2026-10-26 22:04:25 +08:00
parent 0a9938c54d
commit fdacc9739b
19 changed files with 764 additions and 14 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

+16 -14
View File
@@ -45,14 +45,14 @@
轮询算法把每个请求轮流发送到每个服务器上。
下图中,一共有 6 个客户端产生了 6 个请求,这 6 个请求按 (1, 2, 3, 4, 5, 6) 的顺序发送。(1, 3, 5) 的请求会被发送到服务器 1,(2, 4, 6) 的请求会被发送到服务器 2。
下图中,6 个请求按 (1, 2, 3, 4, 5, 6) 的顺序到达。(1, 3, 5) 的请求会被发送到服务器 1,(2, 4, 6) 的请求会被发送到服务器 2。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/9daa3616-00a4-48c4-9146-792dc8499be3.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-round-robin.png" width="640px"/> </div><br>
该算法比较适合每个服务器的性能差不多的场景,如果有性能存在差异的情况下,那么性能较差的服务器可能无法承担过大的负载(下图的 Server 2)。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/bfea8772-d01b-4a51-8adc-edfd7d3dce84.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-round-robin-weak.png" width="640px"/> </div><br>
#### 2. 加权轮询(Weighted Round Robin)
@@ -60,9 +60,9 @@
例如下图中,服务器 1 被赋予的权值为 5,服务器 2 被赋予的权值为 1,那么 (1, 2, 3, 4, 5) 请求会被发送到服务器 1,(6) 请求会被发送到服务器 2。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/4ab87717-e264-4232-825d-8aaf08f14e8b.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-weighted-round-robin.png" width="640px"/> </div><br>
实际实现(例如 Nginx 的平滑加权轮询)会把请求交错发送,避免连续的请求集中到同一台服务器上。
实际实现(例如 Nginx 的平滑加权轮询)会把请求交错发送,避免连续的请求集中到同一台服务器上,上图最后一行是按 Nginx 源码中的算法计算出的顺序。
#### 3. 最少连接(Least Connections)
@@ -70,13 +70,13 @@
例如下图中,(1, 3, 5) 请求会被发送到服务器 1,但是 (1, 3) 很快就断开连接,此时只有 (5) 请求连接服务器 1;(2, 4, 6) 请求被发送到服务器 2,只有 (2) 的连接断开,此时 (6, 4) 请求连接服务器 2。该系统继续运行时,服务器 2 会承担过大的负载。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/e98deb5a-d5d4-4294-aa9b-9220d4483403.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-least-conn-problem.png" width="640px"/> </div><br>
最少连接算法就是将请求发送给当前最少连接数的服务器上。
例如下图中,服务器 1 当前连接数最小,那么新到来的请求 6 就会被发送到服务器 1 上。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/43d323ac-9f07-4e4a-a315-4eaf8c38766c.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-least-conn.png" width="640px"/> </div><br>
#### 4. 加权最少连接(Weighted Least Connection)
@@ -88,7 +88,7 @@
和轮询算法类似,该算法比较适合服务器性能差不多的场景。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a42ad3a7-3574-4c48-a783-ed3d08a0688a.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-random.png" width="640px"/> </div><br>
#### 6. 源地址哈希法 (IP Hash)
@@ -96,9 +96,9 @@
可以保证同一 IP 的客户端的请求会转发到同一台服务器上,用来实现会话粘滞(Sticky Session)。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/0f399a9f-1351-4b2d-b8a4-2ebe82b1a703.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-ip-hash.png" width="640px"/> </div><br>
缺点是同一出口 IP 后面的大量用户会落到同一台服务器上,造成负载不均;服务器数量变化时取模结果会全部改变,可以改用一致性哈希。
缺点是同一出口 IP 后面的大量用户会落到同一台服务器上,造成负载不均;服务器数量变化时大部分客户端的取模结果都会改变,可以改用一致性哈希。需要注意的是,Nginx 的 ip_hash 只用 IPv4 地址的前 3 个字节计算哈希,同一个 /24 网段的客户端都会落到同一台服务器上。
### 转发实现
@@ -113,7 +113,7 @@ HTTP 重定向负载均衡服务器使用某种负载均衡算法计算得到服
该负载均衡转发的缺点比较明显,实际场景中很少使用它。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/02a1fbfd-7a9d-4114-95df-ca2445587a1f.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-http-redirect.png" width="640px"/> </div><br>
#### 2. DNS 域名解析
@@ -129,7 +129,7 @@ HTTP 重定向负载均衡服务器使用某种负载均衡算法计算得到服
大型网站基本使用了 DNS 作为第一级负载均衡手段,然后在内部使用其它方式做第二级负载均衡。也就是说,域名解析的结果为内部的负载均衡服务器 IP 地址。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/d2c072cc-8b17-480c-813e-18cdb3b4b51f.jpg" width="500px"/> </div><br>
<div align="center"> <img src="pics/lb-dns.png" width="640px"/> </div><br>
#### 3. 反向代理服务器
@@ -174,7 +174,9 @@ HTTP 重定向负载均衡服务器使用某种负载均衡算法计算得到服
参考:
- [Comparing Load Balancing Algorithms](http://www.jscape.com/blog/load-balancing-algorithms)
- [Redirection and Load Balancing](http://slideplayer.com/slide/6599069/#)
- [Nginx: ngx_http_upstream_module](https://nginx.org/en/docs/http/ngx_http_upstream_module.html)
- [Nginx 源码:ngx_http_upstream_round_robin.c](https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream_round_robin.c)
- [Redirection and Load Balancing](https://web.archive.org/web/20250420002753/http://slideplayer.com/slide/6599069/)
## 二、集群下的 Session 管理
@@ -229,5 +231,5 @@ HTTP 重定向负载均衡服务器使用某种负载均衡算法计算得到服
参考:
- [Session Management using Spring Session with JDBC DataStore](https://sivalabs.in/2018/02/session-management-using-spring-session-jdbc-datastore/)
- [Session Management using Spring Session with JDBC DataStore](https://web.archive.org/web/20230602191402/https://www.sivalabs.in/2018/02/session-management-using-spring-session-jdbc-datastore/)
+65
View File
@@ -0,0 +1,65 @@
<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: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">DNS 负载均衡:解析域名时选出服务器</text>
<rect x="48" y="132" width="44" height="29.92" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="52" y="136" width="36" height="21.92" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M66,161.92 v5 M74,161.92 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="58" y="166.92" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="70" y="186" class="c sub b">客户端</text>
<rect x="398" y="64" width="44" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="405" cy="70.5" r="2" fill="#BFBEBA"/>
<line x1="412" y1="70.5" x2="435" y2="70.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="398" y="80" width="44" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="405" cy="86.5" r="2" fill="#BFBEBA"/>
<line x1="412" y1="86.5" x2="435" y2="86.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="420" y="110" class="c sub b">DNS 服务器</text>
<text x="420" y="126" class="c sub">按地域或轮询返回 IP</text>
<rect x="398" y="190" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="196.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="196.5" x2="435" y2="196.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="398" y="206" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="212.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="212.5" x2="435" y2="212.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="398" y="222" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="228.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="228.5" x2="435" y2="228.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="420" y="252" class="c sub b">Server 2</text>
<text x="420" y="268" class="c sub mono">203.0.113.12</text>
<line x1="100" y1="140" x2="390" y2="78" class="arrow "/>
<text x="110" y="72" class="sub mono">① 查询 www.example.com</text>
<line x1="390" y1="96" x2="102" y2="150" class="arrow "/>
<text x="200" y="150" class="sub mono">② A 203.0.113.12,TTL 600</text>
<line x1="100" y1="162" x2="390" y2="204" class="arrow "/>
<text x="150" y="216" class="sub mono">③ GET http://www.example.com/</text>
<text x="30" y="290" class="sub">600 秒内本地和各级 DNS 缓存都直接返回这个地址,下线 Server 2 后要等缓存过期才生效。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

+66
View File
@@ -0,0 +1,66 @@
<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: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">HTTP 重定向:负载均衡器只返回目标地址</text>
<rect x="48" y="132" width="44" height="29.92" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="52" y="136" width="36" height="21.92" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M66,161.92 v5 M74,161.92 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="58" y="166.92" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="70" y="186" class="c sub b">浏览器</text>
<rect x="398" y="64" width="44" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="405" cy="70.5" r="2" fill="#BFBEBA"/>
<line x1="412" y1="70.5" x2="435" y2="70.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="398" y="80" width="44" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="405" cy="86.5" r="2" fill="#BFBEBA"/>
<line x1="412" y1="86.5" x2="435" y2="86.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="420" y="110" class="c sub b">负载均衡器</text>
<text x="420" y="126" class="c sub">www.example.com</text>
<rect x="398" y="190" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="196.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="196.5" x2="435" y2="196.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="398" y="206" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="212.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="212.5" x2="435" y2="212.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="398" y="222" width="44" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="405" cy="228.5" r="2" fill="#7FB2D6"/>
<line x1="412" y1="228.5" x2="435" y2="228.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="420" y="252" class="c sub b">Server 2</text>
<text x="420" y="268" class="c sub mono">203.0.113.12</text>
<line x1="100" y1="140" x2="390" y2="78" class="arrow "/>
<text x="110" y="72" class="sub mono">① GET http://www.example.com/</text>
<line x1="390" y1="96" x2="102" y2="150" class="arrow "/>
<text x="200" y="150" class="sub mono">② 302 Found</text>
<text x="200" y="166" class="sub mono">Location: http://203.0.113.12/</text>
<line x1="100" y1="162" x2="390" y2="204" class="arrow "/>
<text x="150" y="216" class="sub mono">③ GET http://203.0.113.12/</text>
<text x="30" y="290" class="sub">浏览器要发两次请求,之后直接访问 203.0.113.12,负载均衡器无法再调整。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

+85
View File
@@ -0,0 +1,85 @@
<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: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">源地址哈希:同一个 IP 总是落到同一台服务器</text>
<rect x="31" y="62" width="34" height="23.12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="35" y="66" width="26" height="15.12" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M44,85.12 v5 M52,85.12 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="36" y="90.12" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="76" y="74" class="sub mono">192.0.2.30</text>
<text x="76" y="90" class="sub mono">crc32(IP) % 2 = 0</text>
<line x1="220" y1="78" x2="412" y2="96" class="arrow "/>
<rect x="31" y="116" width="34" height="23.12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="35" y="120" width="26" height="15.12" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M44,139.12 v5 M52,139.12 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="36" y="144.12" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="76" y="128" class="sub mono">198.51.100.8</text>
<text x="76" y="144" class="sub mono">crc32(IP) % 2 = 0</text>
<line x1="220" y1="132" x2="412" y2="96" class="arrow "/>
<rect x="31" y="170" width="34" height="23.12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="35" y="174" width="26" height="15.12" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M44,193.12 v5 M52,193.12 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="36" y="198.12" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="76" y="182" class="sub mono">203.0.113.11</text>
<text x="76" y="198" class="sub mono">crc32(IP) % 2 = 1</text>
<line x1="220" y1="186" x2="412" y2="216" class="arrow "/>
<rect x="31" y="224" width="34" height="23.12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<rect x="35" y="228" width="26" height="15.12" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
<path d="M44,247.12 v5 M52,247.12 v5" stroke="#7FB2D6" stroke-width="1.4"/>
<rect x="36" y="252.12" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
<text x="76" y="236" class="sub mono">198.51.100.7</text>
<text x="76" y="252" class="sub mono">crc32(IP) % 2 = 1</text>
<line x1="220" y1="240" x2="412" y2="216" class="arrow "/>
<rect x="417" y="72" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="78.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="78.5" x2="456" y2="78.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="88" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="94.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="94.5" x2="456" y2="94.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="104" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="110.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="110.5" x2="456" y2="110.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="132" class="c sub b">Server 1</text>
<text x="478" y="100" class="sub">余数为 0 的客户端</text>
<rect x="417" y="192" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="198.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="198.5" x2="456" y2="198.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="208" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="214.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="214.5" x2="456" y2="214.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="224" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="230.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="230.5" x2="456" y2="230.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="252" class="c sub b">Server 2</text>
<text x="478" y="220" class="sub">余数为 1 的客户端</text>
<text x="30" y="288" class="sub">示意:用 crc32(IP) % 服务器数 选择服务器。服务器数量变化时,大部分客户端的结果都会改变。</text>
</svg>

After

Width:  |  Height:  |  Size: 5.7 KiB

@@ -0,0 +1,63 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="270" viewBox="0 0 640 270">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">轮询不考虑连接的持续时间</text>
<text x="30" y="102" class="sub b">Server 1</text>
<line x1="110" y1="126" x2="591.6" y2="126" class="line"/>
<text x="30" y="172" class="sub b">Server 2</text>
<line x1="110" y1="196" x2="591.6" y2="196" class="line"/>
<rect x="110" y="84" width="56" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="116" y="94" class="sub" style="font-size:10px">请求 1</text>
<rect x="166" y="154" width="308" height="12" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="172" y="164" class="sub" style="font-size:10px">请求 2</text>
<rect x="222" y="98" width="56" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="228" y="108" class="sub" style="font-size:10px">请求 3</text>
<rect x="278" y="168" width="313.6" height="12" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="284" y="178" class="sub" style="font-size:10px">请求 4</text>
<rect x="334" y="112" width="257.6" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="340" y="122" class="sub" style="font-size:10px">请求 5</text>
<rect x="390" y="182" width="201.6" height="12" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="396" y="192" class="sub" style="font-size:10px">请求 6</text>
<text x="110" y="236" class="c sub mono">0</text>
<text x="166" y="236" class="c sub mono">1</text>
<text x="222" y="236" class="c sub mono">2</text>
<text x="278" y="236" class="c sub mono">3</text>
<text x="334" y="236" class="c sub mono">4</text>
<text x="390" y="236" class="c sub mono">5</text>
<text x="446" y="236" class="c sub mono">6</text>
<text x="502" y="236" class="c sub mono">7</text>
<text x="558" y="236" class="c sub mono">8</text>
<text x="597.6" y="240" class="sub">时间</text>
<line x1="390" y1="62" x2="390" y2="224" stroke="#C0605A" stroke-width="1" stroke-dasharray="4 3"/>
<text x="390" y="56" class="c sub note">请求 6 到达时:Server 1 有 1 个连接,Server 2 有 2 个</text>
<text x="30" y="262" class="sub">请求 1、3 很快结束,请求 2 结束前又来了 4 和 6:轮询把 6 发给了已有 2 个连接的 Server 2。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

+63
View File
@@ -0,0 +1,63 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="270" viewBox="0 0 640 270">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">最少连接:发给当前连接数最少的服务器</text>
<text x="30" y="102" class="sub b">Server 1</text>
<line x1="110" y1="126" x2="591.6" y2="126" class="line"/>
<text x="30" y="172" class="sub b">Server 2</text>
<line x1="110" y1="196" x2="591.6" y2="196" class="line"/>
<rect x="110" y="84" width="56" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="116" y="94" class="sub" style="font-size:10px">请求 1</text>
<rect x="166" y="154" width="308" height="12" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="172" y="164" class="sub" style="font-size:10px">请求 2</text>
<rect x="222" y="98" width="56" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="228" y="108" class="sub" style="font-size:10px">请求 3</text>
<rect x="278" y="168" width="313.6" height="12" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="284" y="178" class="sub" style="font-size:10px">请求 4</text>
<rect x="334" y="112" width="257.6" height="12" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="340" y="122" class="sub" style="font-size:10px">请求 5</text>
<rect x="390" y="84" width="201.6" height="12" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="396" y="94" class="sub" style="font-size:10px">请求 6</text>
<text x="110" y="236" class="c sub mono">0</text>
<text x="166" y="236" class="c sub mono">1</text>
<text x="222" y="236" class="c sub mono">2</text>
<text x="278" y="236" class="c sub mono">3</text>
<text x="334" y="236" class="c sub mono">4</text>
<text x="390" y="236" class="c sub mono">5</text>
<text x="446" y="236" class="c sub mono">6</text>
<text x="502" y="236" class="c sub mono">7</text>
<text x="558" y="236" class="c sub mono">8</text>
<text x="597.6" y="240" class="sub">时间</text>
<line x1="390" y1="62" x2="390" y2="224" stroke="#C0605A" stroke-width="1" stroke-dasharray="4 3"/>
<text x="390" y="56" class="c sub note">请求 6 到达时:Server 1 有 1 个连接,Server 2 有 2 个</text>
<text x="30" y="262" class="sub">同样的请求,最少连接算法把请求 6 发给只有 1 个连接的 Server 1,两台各有 2 个连接。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

+94
View File
@@ -0,0 +1,94 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="276" viewBox="0 0 640 276">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">随机:每个请求随机选一台服务器</text>
<text x="30" y="92" class="sub">请求按顺序到达</text>
<rect x="30" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="42" y="117" class="c sub">1</text>
<rect x="60" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="72" y="117" class="c sub">2</text>
<rect x="90" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="102" y="117" class="c sub">3</text>
<rect x="120" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="132" y="117" class="c sub">4</text>
<rect x="150" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="162" y="117" class="c sub">5</text>
<rect x="180" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="192" y="117" class="c sub">6</text>
<line x1="212" y1="113" x2="262" y2="113" class="arrow "/>
<rect x="275" y="90" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="96.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="96.5" x2="318" y2="96.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="106" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="112.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="112.5" x2="318" y2="112.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="122" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="128.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="128.5" x2="318" y2="128.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="300" y="150" class="c sub b">负载均衡器</text>
<text x="300" y="166" class="c sub">随机</text>
<line x1="330" y1="113" x2="412" y2="76" class="arrow "/>
<rect x="417" y="56" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="62.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="62.5" x2="456" y2="62.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="72" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="78.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="78.5" x2="456" y2="78.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="88" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="94.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="94.5" x2="456" y2="94.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="116" class="c sub b">Server 1</text>
<rect x="478" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="81" class="c sub">1</text>
<rect x="504" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="81" class="c sub">2</text>
<rect x="530" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="81" class="c sub">4</text>
<line x1="330" y1="113" x2="412" y2="176" class="arrow "/>
<rect x="417" y="156" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="162.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="162.5" x2="456" y2="162.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="172" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="178.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="178.5" x2="456" y2="178.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="188" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="194.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="194.5" x2="456" y2="194.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="216" class="c sub b">Server 2</text>
<rect x="478" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="181" class="c sub">3</text>
<rect x="504" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="181" class="c sub">5</text>
<rect x="530" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="181" class="c sub">6</text>
<text x="30" y="254" class="sub">请求少时分配可能不均,请求多时接近平均:模拟 10000 个请求,两台分到 5055 和 4945 个。</text>
</svg>

After

Width:  |  Height:  |  Size: 6.2 KiB

+96
View File
@@ -0,0 +1,96 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="276" viewBox="0 0 640 276">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">轮询不考虑服务器的性能</text>
<text x="30" y="92" class="sub">请求按顺序到达</text>
<rect x="30" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="42" y="117" class="c sub">1</text>
<rect x="60" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="72" y="117" class="c sub">2</text>
<rect x="90" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="102" y="117" class="c sub">3</text>
<rect x="120" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="132" y="117" class="c sub">4</text>
<rect x="150" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="162" y="117" class="c sub">5</text>
<rect x="180" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="192" y="117" class="c sub">6</text>
<line x1="212" y1="113" x2="262" y2="113" class="arrow "/>
<rect x="275" y="90" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="96.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="96.5" x2="318" y2="96.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="106" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="112.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="112.5" x2="318" y2="112.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="122" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="128.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="128.5" x2="318" y2="128.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="300" y="150" class="c sub b">负载均衡器</text>
<text x="300" y="166" class="c sub">轮询</text>
<line x1="330" y1="113" x2="412" y2="76" class="arrow "/>
<rect x="417" y="56" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="62.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="62.5" x2="456" y2="62.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="72" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="78.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="78.5" x2="456" y2="78.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="88" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="94.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="94.5" x2="456" y2="94.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="116" class="c sub b">Server 1</text>
<rect x="478" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="81" class="c sub">1</text>
<rect x="504" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="81" class="c sub">3</text>
<rect x="530" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="81" class="c sub">5</text>
<text x="478" y="106" class="sub ok">8 核,CPU 30%</text>
<line x1="330" y1="113" x2="412" y2="176" class="arrow "/>
<rect x="417" y="156" width="46" height="13" rx="3" fill="#F3C6C2" stroke="#D99A94" stroke-width="1.2"/>
<circle cx="424" cy="162.5" r="2" fill="#D99A94"/>
<line x1="431" y1="162.5" x2="456" y2="162.5" stroke="#D99A94" stroke-width="1"/>
<rect x="417" y="172" width="46" height="13" rx="3" fill="#F3C6C2" stroke="#D99A94" stroke-width="1.2"/>
<circle cx="424" cy="178.5" r="2" fill="#D99A94"/>
<line x1="431" y1="178.5" x2="456" y2="178.5" stroke="#D99A94" stroke-width="1"/>
<rect x="417" y="188" width="46" height="13" rx="3" fill="#F3C6C2" stroke="#D99A94" stroke-width="1.2"/>
<circle cx="424" cy="194.5" r="2" fill="#D99A94"/>
<line x1="431" y1="194.5" x2="456" y2="194.5" stroke="#D99A94" stroke-width="1"/>
<text x="440" y="216" class="c sub b">Server 2</text>
<rect x="478" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="181" class="c sub">2</text>
<rect x="504" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="181" class="c sub">4</text>
<rect x="530" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="181" class="c sub">6</text>
<text x="478" y="206" class="sub note">2 核,CPU 95%,请求排队</text>
<text x="30" y="254" class="sub">两台分到的请求一样多,但 Server 2 的处理能力只有 Server 1 的四分之一。</text>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

+94
View File
@@ -0,0 +1,94 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="276" viewBox="0 0 640 276">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">轮询:请求轮流发给每台服务器</text>
<text x="30" y="92" class="sub">请求按顺序到达</text>
<rect x="30" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="42" y="117" class="c sub">1</text>
<rect x="60" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="72" y="117" class="c sub">2</text>
<rect x="90" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="102" y="117" class="c sub">3</text>
<rect x="120" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="132" y="117" class="c sub">4</text>
<rect x="150" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="162" y="117" class="c sub">5</text>
<rect x="180" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="192" y="117" class="c sub">6</text>
<line x1="212" y1="113" x2="262" y2="113" class="arrow "/>
<rect x="275" y="90" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="96.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="96.5" x2="318" y2="96.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="106" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="112.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="112.5" x2="318" y2="112.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="122" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="128.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="128.5" x2="318" y2="128.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="300" y="150" class="c sub b">负载均衡器</text>
<text x="300" y="166" class="c sub">轮询</text>
<line x1="330" y1="113" x2="412" y2="76" class="arrow "/>
<rect x="417" y="56" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="62.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="62.5" x2="456" y2="62.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="72" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="78.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="78.5" x2="456" y2="78.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="88" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="94.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="94.5" x2="456" y2="94.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="116" class="c sub b">Server 1</text>
<rect x="478" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="81" class="c sub">1</text>
<rect x="504" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="81" class="c sub">3</text>
<rect x="530" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="81" class="c sub">5</text>
<line x1="330" y1="113" x2="412" y2="176" class="arrow "/>
<rect x="417" y="156" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="162.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="162.5" x2="456" y2="162.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="172" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="178.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="178.5" x2="456" y2="178.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="188" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="194.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="194.5" x2="456" y2="194.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="216" class="c sub b">Server 2</text>
<rect x="478" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="181" class="c sub">2</text>
<rect x="504" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="181" class="c sub">4</text>
<rect x="530" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="181" class="c sub">6</text>
<text x="30" y="254" class="sub">两台服务器各分到 3 个请求,适合性能相近的服务器。</text>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

@@ -0,0 +1,122 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="330" viewBox="0 0 640 330">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; 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: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</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.5 L9.5,5 L1,8.5 z" fill="#555"/>
</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.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</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.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="320" y="28" class="title">加权轮询:按权重分配请求</text>
<text x="30" y="92" class="sub">请求按顺序到达</text>
<rect x="30" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="42" y="117" class="c sub">1</text>
<rect x="60" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="72" y="117" class="c sub">2</text>
<rect x="90" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="102" y="117" class="c sub">3</text>
<rect x="120" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="132" y="117" class="c sub">4</text>
<rect x="150" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="162" y="117" class="c sub">5</text>
<rect x="180" y="102" width="24" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="192" y="117" class="c sub">6</text>
<line x1="212" y1="113" x2="262" y2="113" class="arrow "/>
<rect x="275" y="90" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="96.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="96.5" x2="318" y2="96.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="106" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="112.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="112.5" x2="318" y2="112.5" stroke="#BFBEBA" stroke-width="1"/>
<rect x="275" y="122" width="50" height="13" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1.2"/>
<circle cx="282" cy="128.5" r="2" fill="#BFBEBA"/>
<line x1="289" y1="128.5" x2="318" y2="128.5" stroke="#BFBEBA" stroke-width="1"/>
<text x="300" y="150" class="c sub b">负载均衡器</text>
<text x="300" y="166" class="c sub">加权轮询</text>
<line x1="330" y1="113" x2="412" y2="76" class="arrow "/>
<rect x="417" y="56" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="62.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="62.5" x2="456" y2="62.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="72" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="78.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="78.5" x2="456" y2="78.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="88" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="94.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="94.5" x2="456" y2="94.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="116" class="c sub b">Server 1</text>
<rect x="478" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="81" class="c sub">1</text>
<rect x="504" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="515" y="81" class="c sub">2</text>
<rect x="530" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="541" y="81" class="c sub">3</text>
<rect x="556" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="567" y="81" class="c sub">4</text>
<rect x="582" y="66" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="593" y="81" class="c sub">5</text>
<text x="478" y="106" class="sub ">权重 5</text>
<line x1="330" y1="113" x2="412" y2="176" class="arrow "/>
<rect x="417" y="156" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="162.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="162.5" x2="456" y2="162.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="172" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="178.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="178.5" x2="456" y2="178.5" stroke="#7FB2D6" stroke-width="1"/>
<rect x="417" y="188" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<circle cx="424" cy="194.5" r="2" fill="#7FB2D6"/>
<line x1="431" y1="194.5" x2="456" y2="194.5" stroke="#7FB2D6" stroke-width="1"/>
<text x="440" y="216" class="c sub b">Server 2</text>
<rect x="478" y="166" width="22" height="22" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="489" y="181" class="c sub">6</text>
<text x="478" y="206" class="sub ">权重 1</text>
<text x="30" y="248" class="sub b">6 个请求依次发给:</text>
<text x="30" y="277" class="sub">按权重连续分配</text>
<rect x="170" y="262" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="195" y="277" class="c sub">S1</text>
<rect x="228" y="262" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="253" y="277" class="c sub">S1</text>
<rect x="286" y="262" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="311" y="277" class="c sub">S1</text>
<rect x="344" y="262" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="369" y="277" class="c sub">S1</text>
<rect x="402" y="262" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="427" y="277" class="c sub">S1</text>
<rect x="460" y="262" width="50" height="22" rx="4" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
<text x="485" y="277" class="c sub">S2</text>
<text x="30" y="307" class="sub">Nginx 平滑加权轮询</text>
<rect x="170" y="292" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="195" y="307" class="c sub">S1</text>
<rect x="228" y="292" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="253" y="307" class="c sub">S1</text>
<rect x="286" y="292" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="311" y="307" class="c sub">S1</text>
<rect x="344" y="292" width="50" height="22" rx="4" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
<text x="369" y="307" class="c sub">S2</text>
<rect x="402" y="292" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="427" y="307" class="c sub">S1</text>
<rect x="460" y="292" width="50" height="22" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
<text x="485" y="307" class="c sub">S1</text>
</svg>

After

Width:  |  Height:  |  Size: 8.1 KiB