Introduction to Redis/Memcache proxy service Twemproxy

Source: Internet
Author: User
Tags crc32
Introduction twemproxy, also known as nutcracker, is an open-source Redis and Memcache proxy server of twtter. Function Fast. Lightweight. Maintainspersistentserverconnections. Keepsconnectioncountonthebackendcachingserverslow. Enablespipeliningofrequestsandrespon

Introduction twemproxy, also known as nutcracker, is an open-source Redis and Memcache proxy server of twtter. Function Fast. Lightweight. Maintains persistent server connections. Keeps connection count on the backend caching servers low. Enables pipelining of requests and respon

Introduction

Twemproxy, also known as nutcracker, is an open-source Redis and Memcache proxy server of twtter.

Feature 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 implements SS multiple servers.
Implements the complete memcached ascii and redis 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) Installation

Download the installation package from the official website to compile and install distribution tarball:

[root@~/software/nutcracker-0.3.0]# ./configure --prefix=/usr/local/nutcracker-0.3.0[root@~/software/nutcracker-0.3.0]# make[root@~/software/nutcracker-0.3.0]# make install[root@~/software/nutcracker-0.3.0]# cp -R conf /usr/local/nutcracker-0.3.0[root@~/software/nutcracker-0.3.0]# ln -s /usr/local/nutcracker-0.3.0 /usr/local/nutcracker[root@~/software/nutcracker-0.3.0]# ln -s /usr/local/nutcracker/sbin/nutcracker /usr/local/bin/nutcracker
Configuration

Twemproxy supports YAML syntax configuration. The supported instruction sets are as follows:

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)
Crc32a (correct crc32 implementation as per the spec)
Fnv000064
Fnv1a_64
Fnv000032
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 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 maid 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 shocould be ejected temporarily when it fails consecutively server_failure_limit times. See liveness recommendations for information. ults 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. ults to 30000 msec.
Server_failure_limit: The number of conseutive failures on a server that wocould leads to it being temporarily ejected when auto_eject_host is set to true. ults to 2.
Servers: A list of server address, port and weight (name: port: weight or ip: port: weight) for this server pool.

Take this article as an example. configure a Redis proxy and a Memcache proxy service as follows:

[root@~/software/nutcracker-0.3.0]# cat /usr/local/nutcracker/conf/nutcracker.ymlalpha:  listen: 127.0.0.1:22121  hash: fnv1a_64  hash_tag: "{}"  distribution: ketama  auto_eject_hosts: false  timeout: 400  redis: true  servers:   - 127.0.0.1:6379:1beta:  listen: 127.0.0.1:22122  hash: fnv1a_64  distribution: ketama  timeout: 400  backlog: 1024  preconnect: true  auto_eject_hosts: true  server_retry_timeout: 2000  server_failure_limit: 3  servers:   - 127.0.0.1:11211:1   - 127.0.0.1:11212:1

Among them, Redis instance 127.0.0.1: 6379 and Memcache instance 127.0.0.1: 11211 127.0.0.1: 11212 should be started in advance.

/etc/init.d/redis_6379 start/usr/local/memcached-1.4.20/bin/memcached -d -m 64 -l 127.0.0.1 -p 11211 -u root/usr/local/memcached-1.4.20/bin/memcached -d -m 64 -l 127.0.0.1 -p 11212 -u root
Test

Https://github.com/billfeller/billfeller.github.io/blob/master/code/twenproxyTest.php

Start the service:

[root@/usr/local/nutcracker/conf]# nutcracker -c nutcracker.yml[Sun Dec 14 20:59:04 2014] nc.c:187 nutcracker-0.3.0 built for Linux 2.6.32-431.23.3.el6.x86_64 x86_64 started on pid 14359[Sun Dec 14 20:59:04 2014] nc.c:192 run, rabbit run / dig that hole, forget the sun / and when at last the work is done / don't sit down / it's time to dig another one

Run the test script:

[root@~/wade/git/billfeller.github.io/code]# /usr/local/php/bin/php twenproxyTest.php bool(true)string(1) "1"int(1)bool(false)bool(true)int(2)bool(true)int(3)bool(true)bool(false)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.