You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置mcrouter使用wch3哈希函数并设置两节点50/50均衡权重?

Configuring mcrouter with wch3 Hashing and Equal Node Weights

Got it, let's walk through exactly how to set up mcrouter to use the wch3 hashing function with two nodes split 50/50. I know it's frustrating when the docs don't have explicit examples for less common hash functions, so here's a concrete working config and explanation:

Step 1: Modify Your mcrouter Configuration File

mcrouter uses JSON-based config files (typically something like mcrouter.json). Here's a complete, valid config that implements what you need:

{
  "pools": {
    "weighted_redis_pool": {
      "servers": [
        {
          "address": "your-first-node:11211",
          "weight": 1
        },
        {
          "address": "your-second-node:11211",
          "weight": 1
        }
      ],
      "hash_function": "wch3",
      "pool_type": "async"
    }
  },
  "route": {
    "type": "PoolRoute",
    "pool": "weighted_redis_pool"
  }
}

Key Config Details Explained

  • "hash_function": "wch3": This line replaces the default ch3 hash with the weighted version (wch3), which is specifically designed to respect node weights when distributing traffic.
  • Node Weights: Setting "weight": 1 for both nodes ensures exactly 50/50 traffic distribution. Weights are relative—if you ever wanted to adjust to, say, 70/30, you'd set weights to 7 and 3 respectively.
  • pool_type: "async": This is the standard asynchronous pool type for mcrouter, suitable for most production use cases where you want non-blocking operations.
  • Route Setup: The PoolRoute type tells mcrouter to route all traffic directly to your configured weighted pool.

Step 2: Validate and Apply the Config

Before restarting mcrouter, validate your config to catch any syntax errors:

mcrouter --validate-config /path/to/your/mcrouter.json

If validation passes, restart mcrouter to apply the changes (command depends on your init system):

# For systemd-based systems
systemctl restart mcrouter

# For upstart
service mcrouter restart

Quick Verification

To confirm the hash function and weights are working as expected, you can use mcrouter's built-in stats or test with a set of keys—wch3 should distribute keys evenly between the two nodes given equal weights.

内容的提问来源于stack exchange,提问作者The Georgia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:30:06