惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
V
Visual Studio Blog
The Register - Security
The Register - Security
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
T
Threatpost
P
Proofpoint News Feed
美团技术团队
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
Vercel News
Vercel News
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
S
Security @ Cisco Blogs
AWS News Blog
AWS News Blog
SecWiki News
SecWiki News
I
InfoQ
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hacker News - Newest:
Hacker News - Newest: "LLM"
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
B
Blog RSS Feed
H
Hacker News: Front Page
雷峰网
雷峰网
Know Your Adversary
Know Your Adversary

Zero の 日常

MacBook M1 Pro 双屏方案 上海电信SDN更换7015TV CNAME与MX记录冲突小记 RHEL 7.9 从 GRUB 引导启动 Hardware upgrade for 2022 Valve Index + HTC Tracker 3.0 开箱记录! 有手就行系列:SlimeVR全身追踪方案 基于goestools与xrit-rx的GK2A气象卫星接收教程 Prometheus实现对IDRAC的SNMP监控 Maven中央仓库项目上传指南 CQ CQ CQ DE BG5ISN PSE K 关于我买不到空气显卡这件事 Mac iTerm2 lrzsz 从零开始的飞机追踪之旅 GitHub单个文件脱敏处理 Protobuf浅解 Prometheus + AlertManager实现告警推送 Prometheus Exporter Prometheus监控系统部署
Nginx负载均衡(加权轮询)
Zero · 2020-08-10 · via Zero の 日常

权重变量

  • weight
    配置的权重,即在配置文件或初始化时约定好的每个节点的权重

  • effective_weight
    后端的有效权重,初始值为 weight
    在释放后端时,如果发现与后端的通信过程中发生了错误,则减小 effective_weight
    此后有新的请求过来时,在选取后端的过程中,再逐步增加 effective_weight,最终又恢复到 weight
    这个配置作用主要是为了当后端发生错误时,降低其权重

  • current_weight
    后端的当前权重,初始值为 0
    每次选取后端时,会遍历集群中所有后端,对于每个后端,让它的 current_weight 增加它的 effective_weight,同时累加所有后端的 effective_weight,保存为 total
    如果该后端的 current_weight 是最大的,就选定这个后端,然后把它的 current_weight 减去 total
    如果该后端没有被选定,那么 current_weight 不用减小

算法逻辑

轮询所有节点,计算当前状态下所有节点的 effectiveWeight 之和 totalWeight,currentWeight = currentWeight + effectiveWeight,选出所有节点中 currentWeight 中最大的一个节点为命中节点。命中节点的 currentWeight = currentWeight - totalWeight。

示例

1
2
3
4
5
upstream test {
server localhost:8081 weight=1
server localhost:8082 weight=2
server localhost:8083 weight=3
}
current_weight current_weight += effective_weight total 命中 current_weight
[0,0,0] [1,2,3] 6 8003 [1,2,-3]
[1,2,-3] [2,4,0] 6 8002 [2,-2,0]
[2,-2,0] [3,0,3] 6 8003 [3,0,-3]
[3,0,-3] [4,2,0] 6 8001 [-2,2,0]
[-2,2,0] [-1,4,3] 6 8002 [-1,-2,3]
[-1,-2,3] [0,0,6] 6 8003 [0,0,0]
[0,0,0] [1,2,3] 6 8003 [1,2,-3]

其他文章