如何配置mcrouter使用wch3哈希函数并设置两节点50/50均衡权重?
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 defaultch3hash with the weighted version (wch3), which is specifically designed to respect node weights when distributing traffic.- Node Weights: Setting
"weight": 1for 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 to7and3respectively. 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
PoolRoutetype 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

