Mcrouter acts as a router for the memcache services. This is a component of the cache infrastructure at Facebook and Instagram, which processes close to 5 billion requests per second. Mcrouter is developed and maintained by Facebook.
Installation Instructions
See this document: https://github.com/facebook/mcrouter
Sharded pools setup
Write the setup file to the json file Then run the command: mcrouter file.json -p port(s) -f config
Memcached protocol router for scaling memcached deployments with:
- Multiple hashing schemas -> hash table
- Multi-cluster support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | { "pools": { "A": { "servers": [ /* hosts of pool A */ ] }, "B": { "servers": [ /* hosts of pool B */ ] } }, "routes": [ { "aliases": [ "/a/a/", "/A/A/" ], "route": "PoolRoute|A" }, { "aliases": [ "/b/b/" ], "route": "PoolRoute|B" } ] } |
- Prefix routing -> config with json
- Flexible routing -> config with json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | { "pools": { "workload1": { "servers": [ /* list of cache hosts for workload1 */ ] }, "workload2": { "servers": [ /* list of cache hosts for workload2 */ ] }, "workload3": { "servers": [ /* list of cache hosts for workload3 */ ] }, "common_cache": { "servers": [ /* list of cache hosts for common use */ ] } }, "route": { "type": "PrefixSelectorRoute", "policies": { "a": "PoolRoute|workload1", "b": "PoolRoute|workload2", "ab": "PoolRoute|workload3" }, "wildcard": "PoolRoute|common_cache" } } |
Explanation : requests with key prefix “a” will be sent to pool ‘workload1’, requests with key prefix “b” will be sent to pool ‘workload2’, requests with key prefix “ab” will be sent to pool ‘workload3’. Other requests will be sent to pool ‘common_cache’. So key “acd” will be sent to ‘workload1’; “abcd” to ‘workload3’; “bar” to ‘workload2’; “zzz” to ‘common_cache’.
- Sharded pools
1 2 3 4 5 6 7 8 9 10 11 12 13 | { "pools": { "A": { "servers": [ // your destination memcached boxes here, e.g.: "127.0.0.1:12345", "[::1]:12346" ] } }, "route": "PoolRoute|A" } |
- Replicated pools
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | { "pools": { "A": { "servers": [ // hosts of replicated pool, e.g.: "127.0.0.1:12345", "[::1]:12346" ] } }, "route": { "type": "OperationSelectorRoute", "operation_policies": { "add": "AllSyncRoute|Pool|A", "delete": "AllSyncRoute|Pool|A", "get": "LatestRoute|Pool|A", "set": "AllSyncRoute|Pool|A" } } } |
Note: number of retries is 5.
- Broadcast operations
- Production traffic shadowing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | { "pools": { "production": { "servers": [ /* production hosts */ ] }, "test": { "servers": [ /* test hosts */ ] } }, "route": { "type": "PoolRoute", "pool": "production", "shadows": [ { "target": "PoolRoute|test", // shadow traffic that would go to first and second hosts in 'production' pool // note that the endpoint is non-inclusive "index_range": [0, 2], // shadow requests for 10% of keys based on key hash "key_fraction_range": [0, 0.1] } ] } } |
- Cold cache warm up
1 2 3 4 5 6 7 8 9 10 11 12 | { "pools": { "cold": { "servers": [ /* cold hosts */ ] }, "warm": { "servers": [ /* warm hosts */ ] } }, "route": { "type": "WarmUpRoute", "cold": "PoolRoute|cold", "warm": "PoolRoute|warm" } } |
- ** Memcached ASCII protocol **
- Reliable delete stream
- Large values
- Muti-level caches
- Quality of service
- Destination health monitoring / automatic failover
- Rich stats counters, Stats commands and debug commands
- Online reconfiguration
- Ipv6 support
- SSL support