Automatically routes read traffic to closest AZ to reduce cost & latency, with weight%.
2.2K
Fork of twemproxy built for AWS ElastiCache:
it resolves a reader endpoint's DNS continuously, discovers every replica behind it, measures
per-replica latency and routes reads to the fastest healthy set — writes go straight to the
primary. Multi-arch image: linux/amd64 + linux/arm64 (glibc, debian bookworm base).
2.3.0 — perf/CPU release: async DNS resolution off the event loop, deferred client send
flush (−91% epoll_ctl), per-request RTT feeding replica weights, release-build logging cost
removed. Measured: −35% CPU/op and +35–65% throughput pipelined; ~2 syscalls/op (was ~5).2.2.x — latency-weighted read distribution across discovered replicas.2.1.x — zone-aware routing, dynamic ElastiCache endpoint discovery.services:
twemproxy:
image: bobbymaher/twemproxy:2.3.0
ports:
- "6379:6379" # write pool -> primary endpoint
- "6378:6378" # read pool -> reader endpoint (replica discovery)
- "22222:22222" # stats (HTTP JSON)
environment:
WRITE_HOST: "my-cluster.abc123.euw1.cache.amazonaws.com:6379"
READ_HOST: "my-cluster-ro.abc123.euw1.cache.amazonaws.com:6379"
DYNAMIC_SERVER_CONNECTIONS: "true"
Point clients' writes at :6379 and reads at :6378. Stats: curl localhost:22222/stats.
| Variable | Default | Meaning |
|---|---|---|
WRITE_HOST | redis-write:6379 | Primary endpoint (write pool) |
READ_HOST | redis-read:6379 | Reader endpoint (read pool, DNS-discovered replicas) |
DNS_RESOLVE_INTERVAL | 30 | Seconds between reader-endpoint re-resolves |
DNS_HEALTH_CHECK_INTERVAL | 30 | Seconds between replica health checks |
DNS_EXPIRATION_MINUTES | 5 | Drop replicas unseen in DNS for this long |
SERVER_CONNECTIONS | 1 | Connections per server (static sizing) |
DYNAMIC_SERVER_CONNECTIONS | false | Size connections from the healthy replica set |
MAX_SERVER_CONNECTIONS | 10 | Cap for dynamic sizing |
CONNECTION_MAX_LIFETIME | 30 | Seconds before a server connection is recycled |
LATENCY_BAND_FACTOR | 3 | Replicas within factor x fastest stay in the read set |
CROSS_AZ_SURCHARGE_US | 0 | Effective-latency penalty for cross-AZ replicas (µs) |
A full nutcracker.yml is generated at startup from these; mount your own at
/etc/twemproxy/nutcracker.yml to bypass templating entirely.
worker_processes: auto is set in the generated config (SO_REUSEPORT workers). On small
hosts (≤2 cores) a single worker often measures better.Content type
Image
Digest
sha256:3730fc325…
Size
6.9 MB
Last updated
over 1 year ago
docker pull bobbymaher/twemproxy