auto commit
|
@ -33,11 +33,12 @@
|
|||
|
||||
下图中,一共有 6 个客户端产生了 6 个请求,这 6 个请求按 (1, 2, 3, 4, 5, 6) 的顺序发送。(1, 3, 5) 的请求会被发送到服务器 1,(2, 4, 6) 的请求会被发送到服务器 2。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/b02fcffd-ed09-4ef9-bc5f-8f0e0383eb1a.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/9daa3616-00a4-48c4-9146-792dc8499be3.jpg" width="500px"/> </div><br>
|
||||
|
||||
|
||||
该算法比较适合每个服务器的性能差不多的场景,如果有性能存在差异的情况下,那么性能较差的服务器可能无法承担过大的负载(下图的 Server 2)。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/73c72e75-193c-4092-aa43-b9c6703c4a22.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/bfea8772-d01b-4a51-8adc-edfd7d3dce84.jpg" width="500px"/> </div><br>
|
||||
|
||||
### 2. 加权轮询(Weighted Round Robbin)
|
||||
|
||||
|
@ -45,7 +46,7 @@
|
|||
|
||||
例如下图中,服务器 1 被赋予的权值为 5,服务器 2 被赋予的权值为 1,那么 (1, 2, 3, 4, 5) 请求会被发送到服务器 1,(6) 请求会被发送到服务器 2。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/92691356-4f7a-46ec-9921-13055d3dcb12.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/4ab87717-e264-4232-825d-8aaf08f14e8b.jpg" width="500px"/> </div><br>
|
||||
|
||||
### 3. 最少连接(least Connections)
|
||||
|
||||
|
@ -53,13 +54,13 @@
|
|||
|
||||
例如下图中,(1, 3, 5) 请求会被发送到服务器 1,但是 (1, 3) 很快就断开连接,此时只有 (5) 请求连接服务器 1;(2, 4, 6) 请求被发送到服务器 2,只有 (2) 的连接断开,此时 (6, 4) 请求连接服务器 2。该系统继续运行时,服务器 2 会承担过大的负载。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/8089a19a-6239-47a0-bf69-54203117d4dc.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/e98deb5a-d5d4-4294-aa9b-9220d4483403.jpg" width="500px"/> </div><br>
|
||||
|
||||
最少连接算法就是将请求发送给当前最少连接数的服务器上。
|
||||
|
||||
例如下图中,服务器 1 当前连接数最小,那么新到来的请求 6 就会被发送到服务器 1 上。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/181edd46-e640-472a-9119-a697de0d2a82.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/43d323ac-9f07-4e4a-a315-4eaf8c38766c.jpg" width="500px"/> </div><br>
|
||||
|
||||
### 4. 加权最少连接(Weighted Least Connection)
|
||||
|
||||
|
@ -71,7 +72,7 @@
|
|||
|
||||
和轮询算法类似,该算法比较适合服务器性能差不多的场景。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/67173c9f-ac87-496a-bd0a-0b1a5cfa735a.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/a42ad3a7-3574-4c48-a783-ed3d08a0688a.jpg" width="500px"/> </div><br>
|
||||
|
||||
### 6. 源地址哈希法 (IP Hash)
|
||||
|
||||
|
@ -79,7 +80,7 @@
|
|||
|
||||
可以保证同一 IP 的客户端的请求会转发到同一台服务器上,用来实现会话粘滞(Sticky Session)
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/9d3c6bfb-4c4c-4b77-9410-56b3f82106d1.jpg" width="500px"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/0f399a9f-1351-4b2d-b8a4-2ebe82b1a703.jpg" width="500px"/> </div><br>
|
||||
|
||||
## 转发实现
|
||||
|
||||
|
|
BIN
docs/pics/0f399a9f-1351-4b2d-b8a4-2ebe82b1a703.jpg
Normal file
After Width: | Height: | Size: 67 KiB |
BIN
docs/pics/43d323ac-9f07-4e4a-a315-4eaf8c38766c.jpg
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
docs/pics/4ab87717-e264-4232-825d-8aaf08f14e8b.jpg
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
docs/pics/9daa3616-00a4-48c4-9146-792dc8499be3.jpg
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
docs/pics/a42ad3a7-3574-4c48-a783-ed3d08a0688a.jpg
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
docs/pics/bfea8772-d01b-4a51-8adc-edfd7d3dce84.jpg
Normal file
After Width: | Height: | Size: 51 KiB |
BIN
docs/pics/e98deb5a-d5d4-4294-aa9b-9220d4483403.jpg
Normal file
After Width: | Height: | Size: 52 KiB |