Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 19, 2026·3 min de lecture

Twemproxy — Fast Lightweight Proxy for Memcached and Redis

Twemproxy (nutcracker) is a fast, lightweight proxy for Memcached and Redis developed by Twitter. It reduces the number of direct connections to cache servers and enables automatic sharding across a cluster.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Twemproxy Overview
Commande CLI universelle
npx tokrepo install 67cd36dd-5318-11f1-9bc6-00163e2b0d79

Introduction

Twemproxy (also called nutcracker) is a proxy created by Twitter to sit between application clients and pools of Memcached or Redis servers. It multiplexes thousands of client connections into a small number of backend connections, reducing resource usage while automatically distributing keys across shards.

What Twemproxy Does

  • Proxies requests to multiple Memcached or Redis instances transparently
  • Automatically shards data using consistent hashing or other distribution strategies
  • Multiplexes many client connections into fewer backend connections to reduce load
  • Detects failed backends and temporarily ejects them from the pool
  • Supports pipelining of requests and responses for higher throughput

Architecture Overview

Twemproxy runs as a single-threaded event-driven process using epoll or kqueue. Incoming client connections are accepted on a listening socket and each request is parsed, hashed to a backend server, and forwarded. Responses travel back through the same proxy connection. The consistent hashing ring can be configured with ketama, modula, or random distribution modes.

Self-Hosting & Configuration

  • Build from source using autoconf and make, or install via package managers on some distributions
  • Define server pools in a YAML configuration file specifying listen address, hash function, and backend list
  • Set the hash algorithm (fnv1a_64, murmur, md5, crc32, etc.) and distribution mode (ketama, modula, random)
  • Configure server_retry_timeout and server_failure_limit to control automatic ejection of unhealthy backends
  • Enable stats collection on a dedicated port for monitoring via tools like collectd or Prometheus exporters

Key Features

  • Extremely low overhead with single-threaded epoll-based architecture
  • Zero-copy proxying keeps latency minimal even at high throughput
  • Supports both Memcached ASCII and Redis protocols in the same binary
  • Connection multiplexing reduces the total number of TCP connections to backends
  • Production-proven at Twitter-scale handling millions of requests per second

Comparison with Similar Tools

  • Redis Cluster — Native sharding built into Redis, but requires Redis 3.0+ and cluster-aware clients
  • ProxySQL — Focused on MySQL protocol proxying, not cache stores
  • Envoy — General-purpose L4/L7 proxy that can front Redis, but heavier and more complex
  • mcrouter — Meta's Memcached proxy with richer routing, but Memcached-only
  • KeyDB — Multi-threaded Redis fork with built-in active replication, but not a proxy

FAQ

Q: Does Twemproxy support Redis Cluster commands? A: No. Twemproxy predates Redis Cluster and implements its own sharding. Multi-key commands that span shards are not supported.

Q: Can Twemproxy handle Redis Pub/Sub? A: No. Pub/Sub, blocking commands, and scripting are not proxied because they require stateful server affinity.

Q: How does Twemproxy handle a backend going down? A: It ejects the server from the hash ring after a configurable number of failures and re-adds it after a timeout.

Q: Is Twemproxy still maintained? A: The repository receives occasional updates. It remains widely deployed in production but new features are infrequent.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires