# twemproxy (nutcracker) [![Build Status](https://secure.travis-ci.org/twitter/twemproxy.png)](http://travis-ci.org/twitter/twemproxy)
**twemproxy** (pronounced "two-em-proxy"), aka **nutcracker** is a fast and lightweight proxy for [memcached](http://www.memcached.org/) and [redis](http://redis.io/) protocol. It was primarily built to reduce the connection count on the backend caching servers.
## Build
To build nutcracker from [distribution tarball](http://code.google.com/p/twemproxy/downloads/list):
$ ./configure
$ make
$ sudo make install
To build nutcracker from [distribution tarball](http://code.google.com/p/twemproxy/downloads/list) in _debug mode_:
$ CFLAGS="-ggdb3 -O0" ./configure --enable-debug=full
$ make
$ sudo make install
To build nutcracker from source with _debug logs enabled_ and _assertions disabled_:
$ git clone git@github.com:twitter/twemproxy.git
$ cd twemproxy
$ autoreconf -fvi
$ ./configure --enable-debug=log
$ make
$ src/nutcracker -h
## Features
+ Fast.
+ Lightweight.
+ Maintains persistent server connections.
+ Keeps connection count on the backend caching servers low.
+ Enables pipelining of requests and responses.
+ Supports proxying to multiple servers.
+ Supports multiple server pools simultaneously.
+ Shard data automatically across multiple servers.
+ Implements the complete [memcached ascii](notes/memcache.txt) and [redis](notes/redis.md) protocol.
+ Easy configuration of server pools through a YAML file.
+ Supports multiple hashing modes including consistent hashing and distribution.
+ Can be configured to disable nodes on failures.
+ Observability through stats exposed on stats monitoring port.
+ Works with Linux, *BSD, OS X and Solaris (SmartOS)
## Help
Usage: nutcracker [-?hVdDt] [-v verbosity level] [-o output file]
[-c conf file] [-s stats port] [-a stats addr]
[-i stats interval] [-p pid file] [-m mbuf size]
Options:
-h, --help : this help
-V, --version : show version and exit
-t, --test-conf : test configuration for syntax errors and exit
-d, --daemonize : run as a daemon
-D, --describe-stats : print stats description and exit
-v, --verbosity=N : set logging level (default: 5, min: 0, max: 11)
-o, --output=S : set logging file (default: stderr)
-c, --conf-file=S : set configuration file (default: conf/nutcracker.yml)
-s, --stats-port=N : set stats monitoring port (default: 22222)
-a, --stats-addr=S : set stats monitoring ip (default: 0.0.0.0)
-i, --stats-interval=N : set stats aggregation interval in msec (default: 30000 msec)
-p, --pid-file=S : set pid file (default: off)
-m, --mbuf-size=N : set size of mbuf chunk in bytes (default: 16384 bytes)
## Zero Copy
In nutcracker, all the memory for incoming requests and outgoing responses is allocated in mbuf. Mbuf enables zero-copy because the same buffer on which a request was received from the client is used for forwarding it to the server. Similarly the same mbuf on which a response was received from the server is used for forwarding it to the client.
Furthermore, memory for mbufs is managed using a reuse pool. This means that once mbuf is allocated, it is not deallocated, but just put back into the reuse pool. By default each mbuf chunk is set to 16K bytes in size. There is a trade-off between the mbuf size and number of concurrent connections nutcracker can support. A large mbuf size reduces the number of read syscalls made by nutcracker when reading requests or responses. However, with large mbuf size, every active connection would use up 16K bytes of buffer which might be an issue when nutcracker is handling large number of concurrent connections from clients. When nutcracker is meant to handle a large number of concurrent client connections, you should set chunk size to a small value like 512 bytes using the -m or --mbuf-size=N argument.
## Configuration
nutcracker can be configured through a YAML file specified by the -c or --conf-file command-line argument on process start. The configuration file is used to specify the server pools and the servers within each pool that nutcracker manages. The configuration files parses and understands the following keys:
+ **listen**: The listening address and port (name:port or ip:port) for this server pool.
+ **hash**: The name of the hash function. Possible values are:
+ one_at_a_time
+ md5
+ crc16
+ crc32 (crc32 implementation compatible with [libmemcached](http://libmemcached.org/))
+ crc32a (correct crc32 implementation as per the spec)
+ fnv1_64
+ fnv1a_64
+ fnv1_32
+ fnv1a_32
+ hsieh
+ murmur
+ jenkins
+ **hash_tag**: A two character string that specifies the part of the key used for hashing. Eg "{}" or "$$". [Hash tag](notes/recommendation.md#hash-tags) enable mapping different keys to the same server as long as the part of the key within the tag is the same.
+ **distribution**: The key distribution mode. Possible values are:
+ ketama
+ modula
+ random
+ **timeout**: The timeout value in msec that we wait for to establish a connection to the server or receive a response from a server. By default, we wait indefinitely.
+ **backlog**: The TCP backlog argument. Defaults to 512.
+ **preconnect**: A boolean value that controls if nutcracker should preconnect to all the servers in this pool on process start. Defaults to false.
+ **redis**: A boolean value that controls if a server pool speaks redis or memcached protocol. Defaults to false.
+ **server_connections**: The maximum number of connections that can be opened to each server. By default, we open at most 1 server connection.
+ **auto_eject_hosts**: A boolean value that controls if server should be ejected temporarily when it fails consecutively server_failure_limit times. See [liveness recommendations](notes/recommendation.md#liveness) for information. Defaults to false.
+ **server_retry_timeout**: The timeout value in msec to wait for before retrying on a temporarily ejected server, when auto_eject_host is set to true. Defaults to 30000 msec.
+ **server_failure_limit**: The number of conseutive failures on a server that would leads to it being temporarily ejected when auto_eject_host is set to true. Defaults to 2.
+ **servers**: A list of server address, port and weight (name:port:weight or ip:port:weight) for this server pool.
For example, the configuration file in [conf/nutcracker.yml](conf/nutcracker.yml), also shown below, configures 5 server pools with names - _alpha_, _beta_, _gamma_, _delta_ and omega. Clients that intend to send requests to one of the 10 servers in pool delta connect to port 22124 on 127.0.0.1. Clients that intend to send request to one of 2 servers in pool omega connect to unix path /tmp/gamma. Requests sent to pool alpha and omega have no timeout and might require timeout functionality to be implemented on the client side. On the other hand, requests sent to pool beta, gamma and delta timeout after 400 msec, 400 msec and 100 msec respectively when no response is received from the server. Of the 5 server pools, only pools alpha, gamma and delta are configured to use server ejection and hence are resilient to server failures. All the 5 server pools use ketama consistent hashing for key distribution with the key hasher for pools alpha, beta, gamma and delta set to fnv1a_64 while that for pool omega set to hsieh. Also only pool beta uses [nodes names](notes/recommendation.md#node-names-for-consistent-hashing) for consistent hashing, while pool alpha, gamma, delta and omega use 'host:port:weight' for consistent hashing. Finally, only pool alpha and beta can speak redis protocol, while pool gamma, deta and omega speak memcached protocol.
alpha:
listen: 127.0.0.1:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
没有合适的资源?快使用搜索试试~ 我知道了~
twemproxy应用包
5星 · 超过95%的资源 需积分: 12 10 下载量 46 浏览量
2014-12-18
16:17:05
上传
评论
收藏 1.74MB GZ 举报
温馨提示
twemproxy,也叫nutcraker。是一个twtter开源的一个redis和memcache代理服务器。 redis作为一个高效的缓存服务器,非常具有应用价值。但是当使用比较多的时候,就希望可以通过某种方式 统一进行管理。避免每个应用每个客户端管理连接的松散性。同时在一定程度上变得可以控制。 搜索了不少的开源代理项目,知乎实现的python分片客户端。node的代理中间层,还有各种restfull的开源代理
资源推荐
资源详情
资源评论
收起资源包目录
twemproxy应用包 (149个子文件)
nutcracker.8 2KB
configure.ac 6KB
configure.ac 2KB
Makefile.am 1KB
Makefile.am 482B
Makefile.am 414B
Makefile.am 359B
Makefile.am 294B
Makefile.am 279B
Makefile.am 269B
Makefile.am 242B
Makefile.am 53B
scanner.c 96KB
emitter.c 64KB
nc_redis.c 57KB
parser.c 44KB
example-deconstructor.c 43KB
nc_conf.c 40KB
api.c 36KB
nc_memcache.c 34KB
example-deconstructor-alt.c 32KB
nc_stats.c 27KB
nc_message.c 22KB
nc_server.c 21KB
reader.c 16KB
nc_request.c 15KB
nc.c 14KB
run-emitter.c 13KB
nc_util.c 12KB
test-reader.c 12KB
loader.c 11KB
nc_connection.c 11KB
nc_evport.c 11KB
run-dumper.c 10KB
nc_kqueue.c 10KB
dumper.c 10KB
nc_md5.c 9KB
nc_response.c 9KB
nc_proxy.c 9KB
nc_rbtree.c 8KB
nc_ketama.c 8KB
nc_core.c 8KB
nc_epoll.c 7KB
nc_jenkins.c 7KB
nc_mbuf.c 7KB
example-reformatter-alt.c 6KB
nc_log.c 5KB
example-reformatter.c 5KB
nc_modula.c 5KB
nc_crc32.c 5KB
nc_random.c 5KB
nc_client.c 5KB
writer.c 4KB
nc_array.c 4KB
nc_signal.c 3KB
nc_crc16.c 3KB
nc_string.c 3KB
nc_hsieh.c 2KB
nc_murmur.c 2KB
nc_fnv.c 2KB
nc_one_at_a_time.c 1KB
run-loader.c 1KB
run-scanner.c 1KB
run-parser.c 1KB
test-version.c 592B
doxygen.cfg 8KB
ChangeLog 4KB
configure 587KB
configure 378KB
depcomp 20KB
depcomp 18KB
config.guess 45KB
config.guess 44KB
yaml-0.1.4.tar.gz 880KB
yaml.h 53KB
nc_queue.h 38KB
yaml_private.h 28KB
nc_message.h 10KB
nc_stats.h 10KB
nc_proto.h 8KB
nc_util.h 6KB
nc_server.h 6KB
nc_conf.h 5KB
nc_log.h 5KB
nc_connection.h 4KB
nc_core.h 4KB
nc_hashkit.h 3KB
nc_string.h 3KB
nc_event.h 3KB
nc_mbuf.h 2KB
nc_array.h 2KB
nc_rbtree.h 2KB
nc_proxy.h 1KB
nc_signal.h 931B
nc_client.h 926B
Makefile.in 27KB
Makefile.in 24KB
Makefile.in 22KB
Makefile.in 22KB
Makefile.in 17KB
共 149 条
- 1
- 2
资源评论
- joyloveit2017-09-29已经下载了,先测下
cjldxx
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 5G SRM815模组原理框图.jpg
- T型3电平逆变器,lcl滤波器滤波器参数计算,半导体损耗计算,逆变电感参数设计损耗计算 mathcad格式输出,方便修改 同时支持plecs损耗仿真,基于plecs的闭环仿真,电压外环,电流内环
- 毒舌(解锁版).apk
- 显示HEX、S19、Bin、VBF等其他汽车制造商特定的文件格式
- 8bit逐次逼近型SAR ADC电路设计成品 入门时期的第三款sarADC,适合新手学习等 包括电路文件和详细设计文档 smic0.18工艺,单端结构,3.3V供电 整体采样率500k,可实现基
- 操作系统实验 ucorelab4内核线程管理
- 脉冲注入法,持续注入,启动低速运行过程中注入,电感法,ipd,力矩保持,无霍尔无感方案,媲美有霍尔效果 bldc控制器方案,无刷电机 提供源码,原理图
- Matlab Simulink#直驱永磁风电机组并网仿真模型 基于永磁直驱式风机并网仿真模型 采用背靠背双PWM变流器,先整流,再逆变 不仅实现电机侧的有功、无功功率的解耦控制和转速调节,而且能实
- 157389节奏盒子地狱模式第三阶段7.apk
- 操作系统实验ucore lab3
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功