Skip to content

Commit ed4f7ad

Browse files
committed
Merge pull request ifwe#3 from ifwe/ha_with_sentinel_rebase_new
Merge latest andyqzb patch
2 parents 74af2fb + 131712c commit ed4f7ad

29 files changed

+1509
-41
lines changed

README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ Twemproxy can be configured through a YAML file specified by the -c or --conf-fi
111111
+ **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.
112112
+ **server_failure_limit**: The number of consecutive failures on a server that would lead to it being temporarily ejected when auto_eject_host is set to true. Defaults to 2.
113113
+ **servers**: A list of server address, port and weight (name:port:weight or ip:port:weight) for this server pool.
114+
+ **sentinels**: A list of redis sentinel address, port and weight (name:port:weight or ip:port:weight) for this server pool. Weight of sentinel is not used.
114115

115116

116-
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 the redis protocol, while pool gamma, deta and omega speak memcached protocol.
117+
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, pool alpha, beta and sigma can speak the redis protocol, while pool gamma, deta and omega speak memcached protocol.
117118

118119
alpha:
119120
listen: 127.0.0.1:22121
@@ -183,6 +184,22 @@ For example, the configuration file in [conf/nutcracker.yml](conf/nutcracker.yml
183184
- 127.0.0.1:11214:100000
184185
- 127.0.0.1:11215:1
185186

187+
sigma:
188+
listen: 127.0.0.1:22125
189+
hash: fnv1a_64
190+
distribution: ketama
191+
auto_eject_hosts: false
192+
redis: true
193+
server_retry_timeout: 2000
194+
server_failure_limit: 1
195+
servers:
196+
- 127.0.0.1:6379:1 server1
197+
- 127.0.0.1:6380:1 server2
198+
sentinels:
199+
- 127.0.0.1:26379:1
200+
- 127.0.0.1:26380:1
201+
- 127.0.0.1:26381:1
202+
186203
Finally, to make writing a syntactically correct configuration file easier, twemproxy provides a command-line argument -t or --test-conf that can be used to test the YAML configuration file for any syntax error.
187204

188205
## Observability

conf/nutcracker.yml

+16
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@ omega:
6565
servers:
6666
- 127.0.0.1:11214:100000
6767
- 127.0.0.1:11215:1
68+
69+
sigma:
70+
listen: 127.0.0.1:22125
71+
hash: fnv1a_64
72+
distribution: ketama
73+
auto_eject_hosts: false
74+
redis: true
75+
server_retry_timeout: 2000
76+
server_failure_limit: 1
77+
servers:
78+
- 127.0.0.1:6379:1 server1
79+
- 127.0.0.1:6380:1 server2
80+
sentinels:
81+
- 127.0.0.1:26379:1
82+
- 127.0.0.1:26380:1
83+
- 127.0.0.1:26381:1

notes/redis.md

+24
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,28 @@
460460
+ *MUST* set all redis with a same passwd, and all twemproxy with the same passwd
461461
+ Length of password should less than 256
462462

463+
## redis-sentinel feature
464+
465+
+ You can configure sentinel for a pool with 'sentinels' to let twemproxy works with sentinel:
466+
467+
sigma:
468+
listen: 127.0.0.1:22125
469+
hash: fnv1a_64
470+
distribution: ketama
471+
auto_eject_hosts: false
472+
redis: true
473+
server_retry_timeout: 2000
474+
server_failure_limit: 1
475+
servers:
476+
- 127.0.0.1:6379:1 server1
477+
- 127.0.0.1:6380:1 server2
478+
sentinels:
479+
- 127.0.0.1:26379:1
480+
- 127.0.0.1:26380:1
481+
- 127.0.0.1:26381:1
482+
483+
+ notice:
484+
+ You should configure all the sentinels you used. Twemproxy will connect to the alive sentinels when some are down
485+
+ Weight of sentinel is not used. Twemproxy keep it because of server load code reuse
486+
463487

src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ nutcracker_SOURCES = \
3838
nc_connection.c nc_connection.h \
3939
nc_client.c nc_client.h \
4040
nc_server.c nc_server.h \
41+
nc_sentinel.c nc_sentinel.h \
4142
nc_proxy.c nc_proxy.h \
4243
nc_message.c nc_message.h \
4344
nc_request.c \

0 commit comments

Comments
 (0)