Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 156 lines (121 sloc) 7.658 kB
3ca2e51 Initial commit
Manju Rajashekhar authored
1 # twemproxy (nutcracker) #
2
3 **twemproxy** (pronounced "two-em-proxy"), aka **nutcracker** is a fast and lightweight proxy for memcached protocol. It was primarily built to reduce the connection count on the backend caching servers.
4
5 ## Build ##
6
7 To build nutcracker from distribution tarball:
8
9 $ ./configure
10 $ make
11 $ sudo make install
12
13 To build nutcracker from distribution tarball in _debug mode_:
14
15 $ CFLAGS="-ggdb3 -O0" ./configure --enable-debug=full
16 $ make
17 $ sudo make install
18
19 To build nutcracker from source with _debug logs enabled_ and _assertions disabled_:
20
21 $ git clone git@github.com:twitter/twemproxy.git
22 $ cd twemproxy
23 $ autoreconf -fvi
24 $ ./configure --enable-debug=log
25 $ make
26 $ src/nutcracker -h
27
28 ## Features ##
29
30 + Fast.
31 + Lightweight.
32 + Maintains persistent server connections.
33 + Keeps connection count on the backend caching servers low.
34 + Enables pipelining of memcached requests and responses.
35 + Supports proxying to multiple servers.
36 + Supports multiple server pools simultaneously.
37 + Implements the complete memcached ASCII protocol.
38 + Easy configuration of server pools through a YAML file.
39 + Supports multiple hashing modes including consistent hashing and distribution.
40 + Observability through stats exposed on stats monitoring port.
41
42 ## Help ##
43
44 Usage: nutcracker [-?hVdt] [-v verbosity level] [-o output file]
45 [-c conf file] [-s stats port] [-i stats interval]
46 [-p pid file]
47
48 Options:
49 -h, --help : this help
50 -V, --version : show version and exit
51 -t, --test-conf : test configuration for syntax errors and exit
52 -d, --daemonize : run as a daemon
53 -v, --verbosity=N : set logging level (default: 5, min: 0, max: 11)
54 -o, --output=S : set logging file (default: stderr)
55 -c, --conf-file=S : set configuration file (default: conf/nutcracker.yml)
56 -s, --stats-port=N : set stats monitoring port (default: 22222)
57 -i, --stats-interval=N : set stats aggregation interval in msec (default: 30000 msec)
58 -p, --pid-file=S : set pid file (default: off)
59
60 ## Configuration ##
61
62 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:
63
64 + **listen**: The listening address and port (name:port or ip:port) for this server pool.
65 + **hash**: The name of the hash function. Possible values are: one_at_a_time, md5, crc32, fnv1_64, fnv1a_64, fnv1_32, fnv1a_32, hsieh, murmur, and jenkins.
66 + **distribution**: The key distribution mode. Possible values are: ketama, modula and random.
67 + **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.
68 + **backlog**: The TCP backlog argument. Defaults to 512.
69 + **preconnect**: A boolean value that controls if nutcracker should preconnect to all the servers in this pool on process start. Defaults to false.
70 + **server_connections**: The maximum number of connections that can be opened to each server. By default, we open at most 1 server connection.
71 + **auto_eject_hosts**: A boolean value that controls if server should be ejected temporarily when it fails consecutively server_failure_limit times. Defaults to false.
72 + **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.
73 + **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.
74 + **servers**: A list of server address, port and weight (name:port:weight or ip:port:weight) for this server pool.
75
76 For example, the configuration file in conf/nutcracker.yml, also shown below, configures 4 server pools with names - _alpha_, _beta_, _gamma_ and _delta_. Clients that intend to send requests to one of the 10 servers in pool gamma connect to port 22123 on 127.0.0.1. Clients that intend to send request to one of 2 servers in pool delta connect to unix path /tmp/gamma. Requests sent to pool alpha and delta have no timeout and might require timeout functionality to be implemented on the client side. On the other hand, requests sent to pool beta and gamma timeout after 400 msec and 100 msec respectively when no response is received from the server. Of the 4 server pools, only pools alpha, beta and gamma are configured to use server ejection and hence are resilient to server failures. All the 4 server pools use ketama consistent hashing for key distribution with the key hasher for pools alpha, beta and gamma set to fnv1a_64 while that for pool delta set to hsieh.
77
78 alpha:
79 listen: 127.0.0.1:22121
80 hash: fnv1a_64
81 distribution: ketama
82 auto_eject_hosts: true
83 server_retry_timeout: 2000
84 server_failure_limit: 1
85 servers:
86 - 127.0.0.1:11211:1
87
88 beta:
89 listen: 127.0.0.1:22122
90 hash: fnv1a_64
91 distribution: ketama
92 timeout: 400
93 backlog: 1024
94 preconnect: true
95 auto_eject_hosts: true
96 server_retry_timeout: 2000
97 server_failure_limit: 3
98 servers:
99 - 127.0.0.1:11212:1
100 - 127.0.0.1:11213:1
101
102 gamma:
103 listen: 127.0.0.1:22123
104 hash: fnv1a_64
105 distribution: ketama
106 timeout: 100
107 auto_eject_hosts: true
108 server_retry_timeout: 2000
109 server_failure_limit: 1
110 servers:
111 - 127.0.0.1:11214:1
112 - 127.0.0.1:11215:1
113 - 127.0.0.1:11216:1
114 - 127.0.0.1:11217:1
115 - 127.0.0.1:11218:1
116 - 127.0.0.1:11219:1
117 - 127.0.0.1:11220:1
118 - 127.0.0.1:11221:1
119 - 127.0.0.1:11222:1
120 - 127.0.0.1:11223:1
121
122 delta:
123 listen: /tmp/gamma
124 hash: hsieh
125 distribution: ketama
126 auto_eject_hosts: false
127 servers:
128 - 127.0.0.1:11214:100000
129 - 127.0.0.1:11215:1
130
131 Finally, to make writing syntactically correct configuration file easier, nutcracker provides a command-line argument -t or --test-conf that can be used to test the YAML configuration file for any syntax error.
132
133 ## Observability ##
134
135 Observability in nutcracker is through logs and stats.
136
137 Nutcracker exposes stats at the granularity of server pool and servers per pool through the stats monitoring port. The stats are essentially JSON formatted key-value pairs, with the keys corresponding to counter names. By default stats are exposed on port 22222 and aggregated every 30 seconds. Both these values can be configured on program start using the -c or --conf-file and -i or --stats-interval command-line arguments respectively.
138
139 Logging in nutcracker is only available when nutcracker is built with logging enabled. By default logs are written to stderr. Nutcracker can also be configured to write logs to a specific file through the -o or --output command-line argument. On a running nutcracker, we can turn log levels up and down by sending it SIGTTIN and SIGTTOU signals respectively and reopen log files by sending it SIGHUP signal.
140
141 ## Issues and Support ##
142
143 Have a bug or a question? Please create an issue here on GitHub!
144
145 https://github.com/twitter/twemproxy/issues
146
147 ## Contributors ##
148
149 * Manju Rajashekhar (@manju)
150
151 ## License ##
152
153 Copyright 2012 Twitter, Inc.
154
155 Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
Something went wrong with that request. Please try again.