[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fRPF1fIHerYdF7hUALzO2c3BGZaAVQ6PaDDQOMemZwXI":3,"$fJU-4tot_gC5fDkujNeoE-cGsdMy5V_KcdUXLuAnTFgw":16,"$f5hdxgCmd6XHB6maF7QaEJtKCm6dnuR5jAJxCtG8wVWQ":423},{"slug":4,"title":5,"description":6,"content":7,"content_html":8,"pub_date":9,"tags":10,"draft":15},"load-balancing-algorithms","负载均衡算法完全指南：从轮询到一致性哈希","系统梳理静态与动态负载均衡算法，涵盖轮询、随机、权重、IP Hash、一致性 Hash、最少连接、最快响应等，并对比 Nginx、Dubbo、Spring Cloud LoadBalancer 的实现差异。","import Chart from '..\u002F..\u002Fcomponents\u002FChart.vue'\n\nexport const weightedDistData = {\n  labels: ['节点 A (weight=3)', '节点 B (weight=1)', '节点 C (weight=2)'],\n  datasets: [{\n    label: '请求占比 %',\n    data: [50, 16.7, 33.3],\n    backgroundColor: [\n      'rgba(0,212,255,0.75)',\n      'rgba(255,0,170,0.75)',\n      'rgba(57,255,20,0.75)',\n    ],\n    borderColor: [\n      'rgba(0,212,255,1)',\n      'rgba(255,0,170,1)',\n      'rgba(57,255,20,1)',\n    ],\n    borderWidth: 1,\n  }]\n}\n\nexport const weightedDistOptions = {\n  plugins: {\n    legend: { display: false },\n    tooltip: {\n      callbacks: {\n        label: (ctx) => ` ${ctx.raw}%`\n      }\n    }\n  },\n  scales: {\n    x: {\n      ticks: { color: '#8888aa', font: { family: 'JetBrains Mono', size: 10 } },\n      grid: { color: 'rgba(30,30,48,0.8)' },\n      border: { display: false },\n    },\n    y: {\n      min: 0,\n      max: 60,\n      ticks: {\n        color: '#8888aa',\n        font: { family: 'JetBrains Mono', size: 10 },\n        callback: (v) => v + '%'\n      },\n      grid: { color: 'rgba(30,30,48,0.8)' },\n      border: { display: false },\n    }\n  }\n}\n\nexport const algoSupportData = {\n  labels: ['轮询', '加权轮询', '随机', 'IP Hash', 'URL Hash', '一致性Hash', '最少连接', '故障重试'],\n  datasets: [\n    {\n      label: 'Nginx',\n      data: [5, 5, 5, 5, 5, 5, 5, 5],\n      backgroundColor: 'rgba(0,212,255,0.7)',\n      borderColor: 'rgba(0,212,255,1)',\n      borderWidth: 1,\n      borderRadius: 3,\n    },\n    {\n      label: 'Dubbo',\n      data: [5, 5, 5, 0, 0, 5, 5, 5],\n      backgroundColor: 'rgba(57,255,20,0.7)',\n      borderColor: 'rgba(57,255,20,1)',\n      borderWidth: 1,\n      borderRadius: 3,\n    },\n    {\n      label: 'Spring Cloud LB',\n      data: [5, 2, 5, 0, 0, 0, 0, 5],\n      backgroundColor: 'rgba(180,0,255,0.7)',\n      borderColor: 'rgba(180,0,255,1)',\n      borderWidth: 1,\n      borderRadius: 3,\n    },\n  ]\n}\n\nexport const algoSupportOptions = {\n  plugins: {\n    legend: {\n      labels: { color: '#c8c8d8', font: { family: 'JetBrains Mono', size: 11 } }\n    },\n    tooltip: {\n      callbacks: {\n        label: (ctx) => {\n          const labels = ['✖️ 不支持', '', '', '', '⚠️ 需自定义', '✅ 支持']\n          return ` ${ctx.dataset.label}: ${ctx.raw === 5 ? '✅ 支持' : ctx.raw === 2 ? '⚠️ 需自定义' : '❌ 不支持'}`\n        }\n      }\n    }\n  },\n  scales: {\n    x: {\n      ticks: { color: '#c8c8d8', font: { family: 'JetBrains Mono', size: 9 }, maxRotation: 30 },\n      grid: { display: false },\n      border: { display: false },\n    },\n    y: {\n      display: false,\n      min: 0,\n      max: 6,\n    }\n  }\n}\n\n## 什么是负载均衡\n\n负载均衡（Load Balancing）是指将客户端请求按照某种策略分发到多个后端服务节点，目标是：\n\n- **避免单点过载**：防止某一节点 CPU\u002F内存耗尽\n- **提升整体吞吐**：充分利用集群资源\n- **容灾与高可用**：节点故障时自动剔除，流量转移\n\n负载均衡分为两大类：**静态算法**（不考虑节点实时状态）和**动态算法**（根据节点当前负载调度）。\n\n---\n\n## 静态负载均衡算法\n\n### 1. 轮询（Round Robin）\n\n最简单的算法：请求依次分发给每个节点，循环往复。\n\n```\n请求序列: 1  2  3  4  5  6\n节点:     A  B  C  A  B  C\n```\n\n**优点**：实现简单，分布均匀（假设节点同质）  \n**缺点**：不考虑节点性能差异和请求处理时长\n\n**Nginx 配置**：\n\n```nginx\nupstream backend {\n    server 192.168.1.10;\n    server 192.168.1.11;\n    server 192.168.1.12;\n    # 默认就是轮询\n}\n```\n\n---\n\n### 2. 随机（Random）\n\n每次请求随机选择一个节点。大量请求下，统计上接近均匀分布。\n\n**优点**：无状态，实现最简  \n**缺点**：小请求量时分布不均\n\n---\n\n### 3. 加权轮询（Weighted Round Robin）\n\n根据节点处理能力分配权重，权重越高分得请求越多。\n\n```\n节点 A: weight=3, 节点 B: weight=1, 节点 C: weight=2\n请求分配: A A A B C C A A A B C C ...\n```\n\n**适用场景**：集群中机器配置不均等（高配机器分更多流量）\n\n```nginx\nupstream backend {\n    server 192.168.1.10 weight=3;\n    server 192.168.1.11 weight=1;\n    server 192.168.1.12 weight=2;\n}\n```\n\n**weight=3:1:2 的实际请求分配比例：**\n\n\u003CChart client:only=\"vue\" type=\"bar\" data={weightedDistData} options={weightedDistOptions} height={200} \u002F>\n\n---\n\n### 4. IP Hash\n\n对客户端 IP 取哈希，映射到固定节点。同一 IP 的请求始终路由到同一后端。\n\n```\nhash(client_ip) % server_count = 目标节点索引\n```\n\n**优点**：天然实现会话保持（Session Sticky），无需额外 Session 共享  \n**缺点**：节点增减时映射变化，大量 Session 失效；NAT 场景下多用户共享 IP 导致负载不均\n\n```nginx\nupstream backend {\n    ip_hash;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n```\n\n---\n\n### 5. URL Hash\n\n对请求 URL 取哈希，相同 URL 路由到同一节点。\n\n**适用场景**：缓存服务器集群——同一资源固定落在同一节点，提升缓存命中率  \n**缺点**：热点 URL 可能导致某节点过载\n\n```nginx\nupstream backend {\n    hash $request_uri consistent;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n```\n\n---\n\n### 6. 一致性哈希（Consistent Hashing）\n\n普通哈希的问题：增减节点时，`hash(key) % N` 的 N 变化，几乎所有 key 都需要重新映射。\n\n一致性哈希将所有节点和 key 映射到同一个圆环（0 ~ 2³²），key 顺时针找到的第一个节点即为目标节点。\n\n```\n          0\n    ┌─────┼─────┐\n  A(90°)  │   C(270°)\n          │\n        B(180°)\n\nkey_hash=120° → 顺时针 → C(270°)\nkey_hash=200° → 顺时针 → C(270°)\nkey_hash=300° → 顺时针 → A(90° + 360°)\n```\n\n**优点**：增减节点时只影响相邻区间，平均只有 `1\u002FN` 的 key 需要迁移  \n**缺点**：节点少时容易分布不均；引入**虚拟节点**（每个物理节点映射多个点）可解决\n\n---\n\n## 动态负载均衡算法\n\n### 7. 最少连接（Least Connections）\n\n将新请求发送给当前**活跃连接数最少**的节点。\n\n```\n节点 A: 活跃连接 100  → 不选\n节点 B: 活跃连接 20   → 选择\n节点 C: 活跃连接 55   → 不选\n```\n\n**优点**：自适应节点处理能力，长连接场景效果好（如 WebSocket）  \n**缺点**：需要维护连接计数，有一定开销\n\n```nginx\nupstream backend {\n    least_conn;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n```\n\n---\n\n### 8. 加权最少连接（Weighted Least Connections）\n\n综合权重和当前连接数：`score = connections \u002F weight`，选 score 最小的节点。\n\n---\n\n### 9. 最快响应时间（Fastest Response）\n\n选择**近期平均响应时间最短**的节点。需要负载均衡器持续采集各节点的响应时间。\n\n**适用场景**：节点间网络延迟差异大（如多机房混合部署）\n\n---\n\n### 10. 预测（Predictive）\n\n基于历史响应时间和当前趋势**预测**节点下一时刻的负载，选择预测负载最低的节点。\n\nF5 BIG-IP 等商用产品支持此算法。\n\n---\n\n### 11. QoS 感知调度\n\n根据请求的服务等级（优先级）调度，高优先级请求优先发送到性能最好的节点。多用于混合业务场景（在线请求 vs 批处理任务）。\n\n---\n\n## 高级策略\n\n### 灰度发布（Canary Release）\n\n通过权重或请求头将少量流量（1%~10%）路由到新版本节点，验证无误后逐步扩大。\n\n```nginx\nupstream backend {\n    server prod.example.com  weight=9;\n    server canary.example.com weight=1;\n}\n```\n\n### 版本隔离\n\n按请求头（如 `X-Version`）或 Cookie 将特定用户路由到指定版本，实现 AB 测试或内测。\n\n### 故障隔离（Circuit Breaker）\n\n节点连续失败超过阈值后，临时从轮询中摘除，避免雪崩。常与健康检查配合使用。\n\n---\n\n## 主流框架支持对比\n\n> ⚠️ Netflix Ribbon 已于 2021 年进入维护模式，Spring Cloud 2020+ 默认切换为 **Spring Cloud LoadBalancer**。新项目不建议继续使用 Ribbon。\n\n| 算法 | Nginx | Dubbo | Spring Cloud LoadBalancer |\n|------|-------|-------|---------------------------|\n| 轮询 | ✅ 默认 | ✅ | ✅ `RoundRobinLoadBalancer` |\n| 加权轮询 | ✅ `weight` | ✅ | ⚠️ 需自定义 |\n| 随机 | ✅ | ✅ | ✅ `RandomLoadBalancer` |\n| IP Hash | ✅ `ip_hash` | ❌ | ❌ |\n| URL Hash | ✅ `hash $uri` | ❌ | ❌ |\n| 一致性 Hash | ✅ `consistent` | ✅ | ❌ |\n| 最少连接 | ✅ `least_conn` | ✅ `LeastActiveLoadBalance` | ❌ |\n| 故障重试 | ✅ `proxy_next_upstream` | ✅ | ✅ `RetryLoadBalancer` |\n\n**三大框架算法支持对比：**\n\n\u003CChart client:only=\"vue\" type=\"bar\" data={algoSupportData} options={algoSupportOptions} height={220} \u002F>\n\n> 注：条形高度表示支持程度：满格=支持，半格=需自定义，空=不支持。\n\n## 选型建议\n\n| 场景 | 推荐算法 |\n|------|---------|\n| 无状态、同质节点 | 轮询 \u002F 随机 |\n| 节点配置差异大 | 加权轮询 |\n| 需要 Session 保持 | IP Hash 或 一致性 Hash |\n| 缓存集群 | URL Hash + 一致性 Hash |\n| 长连接、异步任务 | 最少连接 |\n| 多机房、跨地域 | 最快响应时间 |","\u003Cp>import Chart from ‘…\u002F…\u002Fcomponents\u002FChart.vue’\u003C\u002Fp>\n\u003Cp>export const weightedDistData = {\nlabels: [‘节点 A (weight=3)’, ‘节点 B (weight=1)’, ‘节点 C (weight=2)’],\ndatasets: [{\nlabel: ‘请求占比 %’,\ndata: [50, 16.7, 33.3],\nbackgroundColor: [\n‘rgba(0,212,255,0.75)’,\n‘rgba(255,0,170,0.75)’,\n‘rgba(57,255,20,0.75)’,\n],\nborderColor: [\n‘rgba(0,212,255,1)’,\n‘rgba(255,0,170,1)’,\n‘rgba(57,255,20,1)’,\n],\nborderWidth: 1,\n}]\n}\u003C\u002Fp>\n\u003Cp>export const weightedDistOptions = {\nplugins: {\nlegend: { display: false },\ntooltip: {\ncallbacks: {\nlabel: (ctx) =&gt; \u003Ccode> ${ctx.raw}%\u003C\u002Fcode>\n}\n}\n},\nscales: {\nx: {\nticks: { color: ‘#8888aa’, font: { family: ‘JetBrains Mono’, size: 10 } },\ngrid: { color: ‘rgba(30,30,48,0.8)’ },\nborder: { display: false },\n},\ny: {\nmin: 0,\nmax: 60,\nticks: {\ncolor: ‘#8888aa’,\nfont: { family: ‘JetBrains Mono’, size: 10 },\ncallback: (v) =&gt; v + ‘%’\n},\ngrid: { color: ‘rgba(30,30,48,0.8)’ },\nborder: { display: false },\n}\n}\n}\u003C\u002Fp>\n\u003Cp>export const algoSupportData = {\nlabels: [‘轮询’, ‘加权轮询’, ‘随机’, ‘IP Hash’, ‘URL Hash’, ‘一致性Hash’, ‘最少连接’, ‘故障重试’],\ndatasets: [\n{\nlabel: ‘Nginx’,\ndata: [5, 5, 5, 5, 5, 5, 5, 5],\nbackgroundColor: ‘rgba(0,212,255,0.7)’,\nborderColor: ‘rgba(0,212,255,1)’,\nborderWidth: 1,\nborderRadius: 3,\n},\n{\nlabel: ‘Dubbo’,\ndata: [5, 5, 5, 0, 0, 5, 5, 5],\nbackgroundColor: ‘rgba(57,255,20,0.7)’,\nborderColor: ‘rgba(57,255,20,1)’,\nborderWidth: 1,\nborderRadius: 3,\n},\n{\nlabel: ‘Spring Cloud LB’,\ndata: [5, 2, 5, 0, 0, 0, 0, 5],\nbackgroundColor: ‘rgba(180,0,255,0.7)’,\nborderColor: ‘rgba(180,0,255,1)’,\nborderWidth: 1,\nborderRadius: 3,\n},\n]\n}\u003C\u002Fp>\n\u003Cp>export const algoSupportOptions = {\nplugins: {\nlegend: {\nlabels: { color: ‘#c8c8d8’, font: { family: ‘JetBrains Mono’, size: 11 } }\n},\ntooltip: {\ncallbacks: {\nlabel: (ctx) =&gt; {\nconst labels = [‘✖️ 不支持’, ‘’, ‘’, ‘’, ‘⚠️ 需自定义’, ‘✅ 支持’]\nreturn \u003Ccode> ${ctx.dataset.label}: ${ctx.raw === 5 ? '✅ 支持' : ctx.raw === 2 ? '⚠️ 需自定义' : '❌ 不支持'}\u003C\u002Fcode>\n}\n}\n}\n},\nscales: {\nx: {\nticks: { color: ‘#c8c8d8’, font: { family: ‘JetBrains Mono’, size: 9 }, maxRotation: 30 },\ngrid: { display: false },\nborder: { display: false },\n},\ny: {\ndisplay: false,\nmin: 0,\nmax: 6,\n}\n}\n}\u003C\u002Fp>\n\u003Ch2 id=\"什么是负载均衡\">什么是负载均衡\u003C\u002Fh2>\n\u003Cp>负载均衡（Load Balancing）是指将客户端请求按照某种策略分发到多个后端服务节点，目标是：\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>避免单点过载\u003C\u002Fstrong>：防止某一节点 CPU\u002F内存耗尽\u003C\u002Fli>\n\u003Cli>\u003Cstrong>提升整体吞吐\u003C\u002Fstrong>：充分利用集群资源\u003C\u002Fli>\n\u003Cli>\u003Cstrong>容灾与高可用\u003C\u002Fstrong>：节点故障时自动剔除，流量转移\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>负载均衡分为两大类：\u003Cstrong>静态算法\u003C\u002Fstrong>（不考虑节点实时状态）和\u003Cstrong>动态算法\u003C\u002Fstrong>（根据节点当前负载调度）。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"静态负载均衡算法\">静态负载均衡算法\u003C\u002Fh2>\n\u003Ch3 id=\"1-轮询-round-robin\">1. 轮询（Round Robin）\u003C\u002Fh3>\n\u003Cp>最简单的算法：请求依次分发给每个节点，循环往复。\u003C\u002Fp>\n\u003Cpre>\u003Ccode>请求序列: 1  2  3  4  5  6\n节点:     A  B  C  A  B  C\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>优点\u003C\u002Fstrong>：实现简单，分布均匀（假设节点同质）\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：不考虑节点性能差异和请求处理时长\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Nginx 配置\u003C\u002Fstrong>：\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    server 192.168.1.10;\n    server 192.168.1.11;\n    server 192.168.1.12;\n    # 默认就是轮询\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch3 id=\"2-随机-random\">2. 随机（Random）\u003C\u002Fh3>\n\u003Cp>每次请求随机选择一个节点。大量请求下，统计上接近均匀分布。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>优点\u003C\u002Fstrong>：无状态，实现最简\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：小请求量时分布不均\u003C\u002Fp>\n\u003Chr>\n\u003Ch3 id=\"3-加权轮询-weighted-round-robin\">3. 加权轮询（Weighted Round Robin）\u003C\u002Fh3>\n\u003Cp>根据节点处理能力分配权重，权重越高分得请求越多。\u003C\u002Fp>\n\u003Cpre>\u003Ccode>节点 A: weight=3, 节点 B: weight=1, 节点 C: weight=2\n请求分配: A A A B C C A A A B C C ...\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>适用场景\u003C\u002Fstrong>：集群中机器配置不均等（高配机器分更多流量）\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    server 192.168.1.10 weight=3;\n    server 192.168.1.11 weight=1;\n    server 192.168.1.12 weight=2;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>weight=3:1:2 的实际请求分配比例：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003CChart client:only=\"vue\" type=\"bar\" data={weightedDistData} options={weightedDistOptions} height={200} \u002F>\n\u003Chr>\n\u003Ch3 id=\"4-ip-hash\">4. IP Hash\u003C\u002Fh3>\n\u003Cp>对客户端 IP 取哈希，映射到固定节点。同一 IP 的请求始终路由到同一后端。\u003C\u002Fp>\n\u003Cpre>\u003Ccode>hash(client_ip) % server_count = 目标节点索引\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>优点\u003C\u002Fstrong>：天然实现会话保持（Session Sticky），无需额外 Session 共享\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：节点增减时映射变化，大量 Session 失效；NAT 场景下多用户共享 IP 导致负载不均\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    ip_hash;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch3 id=\"5-url-hash\">5. URL Hash\u003C\u002Fh3>\n\u003Cp>对请求 URL 取哈希，相同 URL 路由到同一节点。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>适用场景\u003C\u002Fstrong>：缓存服务器集群——同一资源固定落在同一节点，提升缓存命中率\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：热点 URL 可能导致某节点过载\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    hash $request_uri consistent;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch3 id=\"6-一致性哈希-consistent-hashing\">6. 一致性哈希（Consistent Hashing）\u003C\u002Fh3>\n\u003Cp>普通哈希的问题：增减节点时，\u003Ccode>hash(key) % N\u003C\u002Fcode> 的 N 变化，几乎所有 key 都需要重新映射。\u003C\u002Fp>\n\u003Cp>一致性哈希将所有节点和 key 映射到同一个圆环（0 ~ 2³²），key 顺时针找到的第一个节点即为目标节点。\u003C\u002Fp>\n\u003Cpre>\u003Ccode>          0\n    ┌─────┼─────┐\n  A(90°)  │   C(270°)\n          │\n        B(180°)\n\nkey_hash=120° → 顺时针 → C(270°)\nkey_hash=200° → 顺时针 → C(270°)\nkey_hash=300° → 顺时针 → A(90° + 360°)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>优点\u003C\u002Fstrong>：增减节点时只影响相邻区间，平均只有 \u003Ccode>1\u002FN\u003C\u002Fcode> 的 key 需要迁移\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：节点少时容易分布不均；引入\u003Cstrong>虚拟节点\u003C\u002Fstrong>（每个物理节点映射多个点）可解决\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"动态负载均衡算法\">动态负载均衡算法\u003C\u002Fh2>\n\u003Ch3 id=\"7-最少连接-least-connections\">7. 最少连接（Least Connections）\u003C\u002Fh3>\n\u003Cp>将新请求发送给当前\u003Cstrong>活跃连接数最少\u003C\u002Fstrong>的节点。\u003C\u002Fp>\n\u003Cpre>\u003Ccode>节点 A: 活跃连接 100  → 不选\n节点 B: 活跃连接 20   → 选择\n节点 C: 活跃连接 55   → 不选\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>优点\u003C\u002Fstrong>：自适应节点处理能力，长连接场景效果好（如 WebSocket）\u003Cbr>\n\u003Cstrong>缺点\u003C\u002Fstrong>：需要维护连接计数，有一定开销\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    least_conn;\n    server 192.168.1.10;\n    server 192.168.1.11;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch3 id=\"8-加权最少连接-weighted-least-connections\">8. 加权最少连接（Weighted Least Connections）\u003C\u002Fh3>\n\u003Cp>综合权重和当前连接数：\u003Ccode>score = connections \u002F weight\u003C\u002Fcode>，选 score 最小的节点。\u003C\u002Fp>\n\u003Chr>\n\u003Ch3 id=\"9-最快响应时间-fastest-response\">9. 最快响应时间（Fastest Response）\u003C\u002Fh3>\n\u003Cp>选择\u003Cstrong>近期平均响应时间最短\u003C\u002Fstrong>的节点。需要负载均衡器持续采集各节点的响应时间。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>适用场景\u003C\u002Fstrong>：节点间网络延迟差异大（如多机房混合部署）\u003C\u002Fp>\n\u003Chr>\n\u003Ch3 id=\"10-预测-predictive\">10. 预测（Predictive）\u003C\u002Fh3>\n\u003Cp>基于历史响应时间和当前趋势\u003Cstrong>预测\u003C\u002Fstrong>节点下一时刻的负载，选择预测负载最低的节点。\u003C\u002Fp>\n\u003Cp>F5 BIG-IP 等商用产品支持此算法。\u003C\u002Fp>\n\u003Chr>\n\u003Ch3 id=\"11-qos-感知调度\">11. QoS 感知调度\u003C\u002Fh3>\n\u003Cp>根据请求的服务等级（优先级）调度，高优先级请求优先发送到性能最好的节点。多用于混合业务场景（在线请求 vs 批处理任务）。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"高级策略\">高级策略\u003C\u002Fh2>\n\u003Ch3 id=\"灰度发布-canary-release\">灰度发布（Canary Release）\u003C\u002Fh3>\n\u003Cp>通过权重或请求头将少量流量（1%~10%）路由到新版本节点，验证无误后逐步扩大。\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-nginx\">upstream backend {\n    server prod.example.com  weight=9;\n    server canary.example.com weight=1;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"版本隔离\">版本隔离\u003C\u002Fh3>\n\u003Cp>按请求头（如 \u003Ccode>X-Version\u003C\u002Fcode>）或 Cookie 将特定用户路由到指定版本，实现 AB 测试或内测。\u003C\u002Fp>\n\u003Ch3 id=\"故障隔离-circuit-breaker\">故障隔离（Circuit Breaker）\u003C\u002Fh3>\n\u003Cp>节点连续失败超过阈值后，临时从轮询中摘除，避免雪崩。常与健康检查配合使用。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"主流框架支持对比\">主流框架支持对比\u003C\u002Fh2>\n\u003Cblockquote>\n\u003Cp>⚠️ Netflix Ribbon 已于 2021 年进入维护模式，Spring Cloud 2020+ 默认切换为 \u003Cstrong>Spring Cloud LoadBalancer\u003C\u002Fstrong>。新项目不建议继续使用 Ribbon。\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>算法\u003C\u002Fth>\n\u003Cth>Nginx\u003C\u002Fth>\n\u003Cth>Dubbo\u003C\u002Fth>\n\u003Cth>Spring Cloud LoadBalancer\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>轮询\u003C\u002Ftd>\n\u003Ctd>✅ 默认\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>RoundRobinLoadBalancer\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>加权轮询\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>weight\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>⚠️ 需自定义\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>随机\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>RandomLoadBalancer\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>IP Hash\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>ip_hash\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>URL Hash\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>hash $uri\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>一致性 Hash\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>consistent\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>最少连接\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>least_conn\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>LeastActiveLoadBalance\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>❌\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>故障重试\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>proxy_next_upstream\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>✅\u003C\u002Ftd>\n\u003Ctd>✅ \u003Ccode>RetryLoadBalancer\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\u003Cp>\u003Cstrong>三大框架算法支持对比：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003CChart client:only=\"vue\" type=\"bar\" data={algoSupportData} options={algoSupportOptions} height={220} \u002F>\n\u003Cblockquote>\n\u003Cp>注：条形高度表示支持程度：满格=支持，半格=需自定义，空=不支持。\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Ch2 id=\"选型建议\">选型建议\u003C\u002Fh2>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>场景\u003C\u002Fth>\n\u003Cth>推荐算法\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>无状态、同质节点\u003C\u002Ftd>\n\u003Ctd>轮询 \u002F 随机\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>节点配置差异大\u003C\u002Ftd>\n\u003Ctd>加权轮询\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>需要 Session 保持\u003C\u002Ftd>\n\u003Ctd>IP Hash 或 一致性 Hash\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>缓存集群\u003C\u002Ftd>\n\u003Ctd>URL Hash + 一致性 Hash\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>长连接、异步任务\u003C\u002Ftd>\n\u003Ctd>最少连接\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>多机房、跨地域\u003C\u002Ftd>\n\u003Ctd>最快响应时间\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n","2023-11-15",[11,12,13,14],"分布式","负载均衡","Nginx","微服务",false,[17,30,41,53,63,70,77,84,91,98,108,117,127,136,144,152,161,170,179,189,196,206,212,219,225,234,241,248,256,266,275,284,294,304,314,322,332,335,345,354,362,368,376,384,392,400,408,415],{"slug":18,"title":19,"description":20,"pub_date":21,"tags":22,"draft":15,"word_count":29},"ide-skills-guide","Agent Skills 完全指南：21 款第三方 Skill 深度评测与使用心得","全面评测 21 款第三方 Agent Skills，涵盖 Vue 生态、前端设计、构建工具、实用工具四大分类。从安装配置到实际使用场景，带你了解每个 Skill 的功能特点、最佳实践与使用心得。","2026-06-15",[23,24,25,26,27,28],"agent","skills","AI","效率工具","前端","Vue",4169,{"slug":31,"title":32,"description":33,"pub_date":34,"tags":35,"draft":15,"word_count":40},"linux-kernel-skeleton-struct-funcptr-container_of","Linux 内核骨架：struct、函数指针与 container_of","读懂 Linux 内核源码的三件套：巨大的 struct 组合代替继承、函数指针表实现虚派发、container_of 宏从嵌入成员找回完整对象。","2026-05-09",[36,37,38,39],"linux","kernel","C","container_of",1369,{"slug":42,"title":43,"description":44,"pub_date":45,"tags":46,"draft":15,"word_count":52},"astro-complete-guide-2025","Astro 5 深度剖析：Islands 架构原理、构建优化与 Cloudflare Workers 边缘部署","从编译器视角解析 Astro 5 的 Islands 架构实现原理，Content Layer API 的 Vite 插件机制，Server Islands 的流式渲染，以及如何在 Cloudflare Workers + D1 边缘环境下榨干性能。","2026-05-08",[47,48,49,50,51],"astro","frontend","cloudflare","performance","architecture",3663,{"slug":54,"title":55,"description":56,"pub_date":57,"tags":58,"draft":15,"word_count":62},"llm-prompt-engineering","Prompt Engineering 实战：让 LLM 真正听话的技巧","System prompt 怎么写、Few-shot 怎么设计、Chain-of-Thought 原理，以及常见失败模式和调试方法。","2026-05-03",[59,60,61],"ai","llm","工程实践",1723,{"slug":64,"title":65,"description":66,"pub_date":57,"tags":67,"draft":15,"word_count":69},"rag-system-design","RAG 系统设计：从 naive 到 production-ready","Retrieval-Augmented Generation 不只是「向量数据库 + LLM」，分块策略、召回质量、重排序、缓存才是工程核心。",[59,68,60,61],"rag",1613,{"slug":71,"title":72,"description":73,"pub_date":57,"tags":74,"draft":15,"word_count":76},"git-advanced-workflow","Git 进阶工作流：rebase、cherry-pick、bisect 的正确使用","merge 会了，但 rebase 总搞错？bisect 找 bug 提交？interactive rebase 整理历史？这篇一次说清楚。",[75,61],"git",1396,{"slug":78,"title":79,"description":80,"pub_date":57,"tags":81,"draft":15,"word_count":83},"docker-practical-guide","Docker 实战：从会用到用好","会 docker run 不够，Dockerfile 最佳实践、多阶段构建、Compose 编排、镜像瘦身才是日常真正需要的。",[82,36,61],"docker",1268,{"slug":85,"title":86,"description":87,"pub_date":57,"tags":88,"draft":15,"word_count":90},"anthropics-skills-guide","anthropics\u002Fskills：Anthropic 官方 Agent Skills 仓库解析","Anthropic 官方开源的 Agent Skills 标准仓库，127k stars，解析 SKILL.md 规范、17 个示例 skill 的设计模式，以及如何在 Claude Code \u002F Claude.ai \u002F API 中使用",[59,89,23,24],"Claude",2090,{"slug":92,"title":93,"description":94,"pub_date":57,"tags":95,"draft":15,"word_count":97},"karpathy-claude-code-guidelines","Karpathy 的 LLM 编码批评与 CLAUDE.md 最佳实践","基于 Andrej Karpathy 对 LLM 编程助手的观察，forrestchang 提炼出一个 CLAUDE.md 文件，4 条原则解决 AI 编码的典型失控问题：乱猜假设、过度设计、乱改代码、目标不清",[59,89,96,61],"Claude Code",2699,{"slug":99,"title":100,"description":101,"pub_date":57,"tags":102,"draft":15,"word_count":107},"typescript-advanced-patterns","TypeScript 高级模式：让类型系统为你工作","基础 TS 会了但类型总是 any？条件类型、映射类型、模板字面量类型、infer 关键字才是 TS 的真正威力。",[103,104,105,106],"typescript","类型系统","前端工程","高级模式",1419,{"slug":109,"title":110,"description":111,"pub_date":57,"tags":112,"draft":15,"word_count":116},"linux-performance-tuning","Linux 性能调优实战：从 top 到 perf 的完整工具链","遇到性能问题不知道从哪下手？这篇建立系统化的排查思路，从 CPU\u002F内存\u002FIO\u002F网络逐层分析。",[36,113,114,115],"性能","运维","系统编程",1524,{"slug":118,"title":119,"description":120,"pub_date":57,"tags":121,"draft":15,"word_count":126},"python-functional-programming","Python 函数式编程：map\u002Ffilter\u002Freduce 之外","Python 不是纯函数式语言，但 functools、itertools、偏函数、闭包这些工具用好了能让代码简洁一个量级。",[122,123,124,125],"python","函数式","闭包","装饰器",1867,{"slug":128,"title":129,"description":130,"pub_date":57,"tags":131,"draft":15,"word_count":135},"python-oop-guide","Python 面向对象：__init__ 之外你需要知道的","Python OOP 不只是 class + __init__，魔术方法、描述符、元类才是真正的武器。",[122,132,133,134],"OOP","面向对象","魔术方法",1792,{"slug":137,"title":138,"description":139,"pub_date":57,"tags":140,"draft":15,"word_count":143},"python-data-structures","Python 内置数据结构深度解析","list、dict、set、tuple 不只是数据容器，搞懂它们的底层实现和时间复杂度，才能写出高性能 Python。",[122,141,113,142],"数据结构","算法",1517,{"slug":145,"title":146,"description":147,"pub_date":57,"tags":148,"draft":15,"word_count":151},"python-basics-quick-start","Python 快速上手：写给有编程基础的人","已经会其他语言，想快速掌握 Python 的语法特性和思维方式，这篇是捷径。",[122,149,150],"入门","基础",1607,{"slug":153,"title":154,"description":155,"pub_date":57,"tags":156,"draft":15,"word_count":160},"python-dataclass-pydantic","Python dataclass vs Pydantic：数据类选型指南","dataclass 是标准库的轻量选择，Pydantic v2 是带验证的重武器，什么时候用哪个，这篇说清楚。",[122,157,158,159],"dataclass","pydantic","数据验证",1323,{"slug":162,"title":163,"description":164,"pub_date":57,"tags":165,"draft":15,"word_count":169},"python-asyncio-practical","Python asyncio 实战：从回调地狱到协程优雅","asyncio 是 Python 异步编程的核心，搞懂 event loop、Task、gather 这些概念才能写出真正高效的异步代码。",[122,166,167,168],"asyncio","并发","网络编程",1258,{"slug":171,"title":172,"description":173,"pub_date":57,"tags":174,"draft":15,"word_count":178},"python-type-hints-guide","Python 类型注解完全指南：从入门到实践","Python 3.5+ 引入类型注解，配合 mypy\u002Fpyright 让 Python 也能享受静态类型检查的好处。",[122,175,176,177],"typescript-style","type-hints","工具链",1102,{"slug":180,"title":181,"description":182,"pub_date":183,"tags":184,"draft":15,"word_count":188},"pwa-install-update-button","PWA 踩坑：为什么安装按钮从来不出现","从 beforeinstallprompt 到 Service Worker waiting，把 PWA 的安装与更新提示真正做对","2026-05-02",[185,186,187],"pwa","javascript","web",1683,{"slug":190,"title":191,"description":192,"pub_date":193,"tags":194,"draft":15,"word_count":195},"openclaw-vs-hermes-agent","OpenClaw vs Hermes Agent：两个本地优先 Agent 的设计差异","OpenClaw（Novita AI）和 Hermes Agent（Nous Research）都是本地运行的个人 AI Agent，但在记忆系统、技能学习、运行环境和模型生态上走了不同的路。深入对比两种架构的核心差异。","2026-05-01",[59,23,60],1679,{"slug":197,"title":198,"description":199,"pub_date":193,"tags":200,"draft":15,"word_count":205},"cpp-random-design-patterns","C++ 设计模式实战：RAII、观察者、工厂","用现代 C++（C++17\u002F20）实现三种高频设计模式：RAII 资源管理、观察者模式事件系统、工厂模式插件架构。每种模式给出问题场景、实现代码和真实工程案例。",[201,202,203,204],"cpp","设计模式","c++17","工程",2613,{"slug":207,"title":208,"description":209,"pub_date":193,"tags":210,"draft":15,"word_count":211},"data-structures-fundamentals","数据结构基础：从数组到红黑树","系统梳理常用数据结构的核心原理、时间复杂度和适用场景。数组、链表、栈、队列、哈希表、二叉树、堆、图，每种结构附实现要点和 C++ 代码片段。",[141,142,201,150],3004,{"slug":213,"title":214,"description":215,"pub_date":216,"tags":217,"draft":15,"word_count":218},"ai-agent-what-is","什么是 AI Agent？从 LLM 到自主执行","LLM 本身是无状态问答机，Agent 是什么让它’动’起来的？本文深入解析 Agent 的四个核心能力、ReAct 框架、工具调用原理，以及主流框架横向对比。","2026-04-30",[59,23,60],2116,{"slug":220,"title":221,"description":222,"pub_date":216,"tags":223,"draft":15,"word_count":224},"ai-agent-memory","AI Agent 的记忆系统：从上下文窗口到长期记忆","深入拆解 AI Agent 的四种记忆类型、上下文窗口压缩策略、RAG 向量检索原理，以及三种典型失败模式和工程选型建议。",[59,23,68],2052,{"slug":226,"title":227,"description":228,"pub_date":216,"tags":229,"draft":15,"word_count":233},"network-proxy-vpn-guide","代理与翻墙技术原理：从 HTTP 代理到现代协议","深入解析代理与 VPN 的本质区别，梳理从 SOCKS5 到 Shadowsocks、V2Ray\u002FXray、Hysteria2 的协议演进，以及机场订阅的技术本质。",[230,231,232],"网络","代理","协议",2148,{"slug":235,"title":236,"description":237,"pub_date":216,"tags":238,"draft":15,"word_count":151},"algorithm-binary-search","二分查找：永远写不对？记住这个模板","彻底搞清楚二分查找的边界问题：闭区间和左闭右开两套模板、三道经典 LeetCode 题目完整 C++ 实现，以及二分答案的进阶思路。",[142,239,240,201],"二分查找","leetcode",{"slug":242,"title":243,"description":244,"pub_date":216,"tags":245,"draft":15,"word_count":247},"algorithm-sliding-window","滑动窗口算法：从暴力到 O(n) 的思维跃迁","系统讲解滑动窗口算法的核心模板、适用题型，配合三道经典 LeetCode 题目的完整 C++ 实现，彻底理解双指针收缩思路。",[142,246,240,201],"滑动窗口",1943,{"slug":249,"title":250,"description":251,"pub_date":216,"tags":252,"draft":15,"word_count":255},"network-clash-config","Clash \u002F Mihomo 配置详解：规则、策略组与分流","深入解析 Clash\u002FMihomo 的核心配置结构，包括代理节点、策略组类型、规则优先级、DNS fake-ip 模式，以及一份实用的完整配置模板。",[230,253,231,254],"clash","配置",1292,{"slug":257,"title":258,"description":259,"pub_date":260,"tags":261,"draft":15,"word_count":265},"hid-hotplug","HID 设备热插拔检测：从 udev 到 node-hid","在 Linux 上用 node-hid + usb 库实现可靠的 USB HID 设备热插拔检测，踩坑记录","2026-04-28",[201,262,36,263,264],"hid","nodejs","electron",2039,{"slug":267,"title":268,"description":269,"pub_date":270,"tags":271,"draft":15,"word_count":274},"electron-ipc-types","Electron IPC 类型安全：从 any 到完全类型化","用 TypeScript 泛型封装 Electron IPC，彻底消灭 any，preload 契约集中管理","2026-04-25",[264,103,272,273],"ipc","vue",1446,{"slug":276,"title":277,"description":278,"pub_date":279,"tags":280,"draft":15,"word_count":283},"element-plus-popover-hide","手动关闭多个 el-popover（不用 v-model:visible）","通过 ref + Reflect.get 调用 hide() 方法手动关闭 Element Plus Popover，解释 Vue3 Proxy 导致无法直接调用实例方法的原因。","2024-10-25",[273,281,282],"element-plus","vue3",1321,{"slug":285,"title":286,"description":287,"pub_date":288,"tags":289,"draft":15,"word_count":293},"vite-vue3-ts-elementplus-pinia","用 Vite+（vp）从零搭建 Vue3 + TypeScript + Element Plus + Pinia + Vue Router","使用 Vite+ 统一工具链（vp）一条命令搭建 Vue3 全家桶，涵盖按需导入、Pinia store、路由配置，以及常见坑的解决方案。","2024-08-27",[273,290,103,281,291,292],"vite","pinia","vite-plus",1960,{"slug":295,"title":296,"description":297,"pub_date":298,"tags":299,"draft":15,"word_count":303},"cef-lnk2038-iterator-debug-level","CEF LNK2038：解决 _ITERATOR_DEBUG_LEVEL 不匹配错误","分析 CEF（Chromium Embedded Framework）集成时出现的 LNK2038 _ITERATOR_DEBUG_LEVEL 链接错误，从根本原因到解决方案的完整指南。","2024-05-07",[201,300,301,302],"CEF","Visual Studio","链接错误",1509,{"slug":305,"title":306,"description":307,"pub_date":308,"tags":309,"draft":15,"word_count":313},"npm-electron-install-fix","彻底解决 npm 安装 Electron 失败的问题","分析 npm install electron 失败的根本原因（下载二进制超时\u002F被墙），通过国内镜像（npmmirror）彻底解决，并介绍多种备选方案和常见错误排查。","2024-03-01",[264,310,311,312],"npm","前端工具链","国内镜像",1494,{"slug":315,"title":316,"description":317,"pub_date":318,"tags":319,"draft":15,"word_count":321},"git-out-of-memory","解决 git 报错：Fatal: Out of memory, malloc failed","分析 git 大仓库操作时出现 Out of memory malloc failed 的根本原因，通过调整 pack.windowMemory、http.postBuffer 和 git repack 彻底解决。","2024-01-31",[75,36,320],"工具",2244,{"slug":323,"title":324,"description":325,"pub_date":326,"tags":327,"draft":15,"word_count":331},"vmware-tools-install","在 VMware 虚拟机中安装 open-vm-tools 完整指南","详解 VMware Tools 的作用、open-vm-tools 与官方 VMware Tools 的区别，以及在 Ubuntu 虚拟机中安装并生效的完整步骤和常见问题排查。","2023-11-21",[328,36,329,330],"VMware","Ubuntu","虚拟机",2523,{"slug":4,"title":5,"description":6,"pub_date":9,"tags":333,"draft":15,"word_count":334},[11,12,13,14],1764,{"slug":336,"title":337,"description":338,"pub_date":339,"tags":340,"draft":15,"word_count":344},"win-cw2a-ca2w","ATL 字符串转换：CW2A 与 CA2W 完全指南","详解 ATL 宏 CW2A\u002FCA2W 在 Unicode 与 ANSI 之间的字符串转换用法、头文件依赖、USES_CONVERSION 宏的作用与常见陷阱。","2023-06-09",[201,341,342,343],"windows","ATL","字符串",1665,{"slug":346,"title":347,"description":348,"pub_date":339,"tags":349,"draft":15,"word_count":353},"csharp-sendmessage-cpp","C# 通过 SendMessage 向 C++ 窗口发送消息与字符串","使用 P\u002FInvoke 调用 user32.dll 的 SendMessage，从 C# 发送自定义 WM_USER 消息及字符串指针给 C++ 原生窗口，并在 C++ 侧正确接收和转换。",[350,201,341,351,352],"C#","互操作","PInvoke",1554,{"slug":355,"title":356,"description":357,"pub_date":358,"tags":359,"draft":15,"word_count":361},"win-postmessage-vector","Windows PostMessage 跨线程传递 std::vector 指针","通过 PostMessage 在 Windows 消息队列中传递 std::vector 指针，使用 reinterpret_cast 将指针装入 LPARAM，并在接收方正确释放内存。","2023-05-26",[201,341,360],"WinAPI",1823,{"slug":363,"title":364,"description":365,"pub_date":358,"tags":366,"draft":15,"word_count":367},"exe-dll-single-package","将 EXE 和 DLL 打包成单一可执行文件","介绍两种将 exe 和依赖 dll 打包成单文件的方案：Enigma Virtual Box 和 WinRAR 自解压，适合发布 Windows 桌面程序时简化分发流程。",[341,201,320],1619,{"slug":369,"title":370,"description":371,"pub_date":358,"tags":372,"draft":15,"word_count":375},"cpp-random-mt19937","C++ 现代随机数生成：用 mt19937 彻底告别 rand()","深入讲解为什么 rand() 不够用，以及如何用 C++11 的 \u003Crandom> 库正确生成高质量随机数，涵盖 mt19937、各种分布和线程安全。",[201,373,374],"c++11","random",1549,{"slug":377,"title":378,"description":379,"pub_date":380,"tags":381,"draft":15,"word_count":383},"win-startup-registry","C++ 实现程序开机自启动：注册表方式详解","通过操作 Windows 注册表 Run 键实现程序开机自启动，包括 HKCU 与 HKLM 区别、完整封装代码、工作目录问题和 UAC 权限处理。","2022-12-26",[341,201,382],"registry",1201,{"slug":385,"title":386,"description":387,"pub_date":388,"tags":389,"draft":15,"word_count":391},"mfc-cstring-wparam","MFC 中 CString 与 WPARAM 之间的转换","详解 MFC 消息传递中 CString 无法直接强转为 WPARAM 的原因，以及两种正确的转换方案，并介绍结构体指针传递的正确姿势。","2022-11-25",[390,201,341],"mfc",1546,{"slug":393,"title":394,"description":395,"pub_date":396,"tags":397,"draft":15,"word_count":399},"duilib-static-build","正确编译 Duilib 静态库：避免 ATL 依赖和链接错误","详解如何用 DuiLib_Static.vcxproj 编译 Duilib 静态库，解决 VARIANT 未定义、Unicode 配置不匹配和 ATL 依赖等常见问题。","2022-08-24",[201,398,341,390],"duilib",2639,{"slug":401,"title":402,"description":403,"pub_date":404,"tags":405,"draft":15,"word_count":407},"mfc-dpi-adaptive","MFC 界面自适应不同分辨率","MFC 对话框程序实现控件和字体随分辨率自动缩放的完整方案，附 DPI Awareness 配置说明","2022-08-17",[390,201,341,406],"dpi",1414,{"slug":409,"title":410,"description":411,"pub_date":412,"tags":413,"draft":15,"word_count":414},"mfc-drag-window","MFC 无标题栏窗口客户区拖动：三种方法对比","MFC 对话框去掉标题栏后如何实现拖动移动窗口，三种方案完整实现与适用场景分析","2022-08-16",[390,201,341],1633,{"slug":416,"title":417,"description":418,"pub_date":419,"tags":420,"draft":15,"word_count":422},"algorithm-number-complement","整数的补数：位运算掩码解法","LeetCode 476 题，用掩码 XOR 实现整数补数，附 C++\u002FPython\u002FJava 三种实现及补数与补码的区别","2021-03-08",[142,421,240],"位运算",1374,[]]