Giter VIP home page Giter VIP logo

twemproxy-163's Introduction

twemproxy (nutcracker) Build Status

twemproxy (pronounced "two-em-proxy"), aka nutcracker is a fast and lightweight proxy for memcached and redis protocol. It was built primarily to reduce the number of connections to the caching servers on the backend. This, together with protocol pipelining and sharding enables you to horizontally scale your distributed caching architecture. http://www.bitstech.net/2016/04/05/supportredishatwemproxy/

NEW FEATURE

We modified the twemproxy to supports redis-server failover by communicating with redis-sentinel^_^

image

Build

To build twemproxy from source with debug logs enabled and assertions enabled:

$ apt-get install automake
$ apt-get install libtool
$ git clone https://github.com/helifu/twemproxy-163.git
$ cd twemproxy
$ autoreconf -fvi
$ ./configure --enable-debug=full
$ make
$ src/nutcracker -h

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, --verbose=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)

For example:
  nutcracker -d -v 5 -o nutcracker.log -c nutcracker.yml -i 10000 -p nutcracker.pid

Configuration

Twemproxy 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 twemproxy manages. The configuration files parses and understands the following keys:

  • listen: The listening address and port (name:port or ip:port) or an absolute path to sock file (e.g. /var/run/nutcracker.sock) for this server pool.
  • client_connections: The maximum number of connections allowed from redis clients. Unlimited by default, though OS-imposed limitations will still apply.
  • 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)
  • 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 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.
  • tcpkeepalive: A boolean value that controls if a server pool set keepalive on every connection. Defaults to false.
  • redis_auth: Authenticate to the Redis server on connect.
  • redis_db: The DB number to use on the pool servers. Defaults to 0. Note: Twemproxy will always present itself to clients as DB 0.
  • server_connections: The maximum number of connections that can be opened to each server. By default, we open at most 1 server connection.
  • groups: A list of server groups, that are used for partition. At the same time, they are monitored in redis-sentinels.
  • sentinel_heartbeat: The beat interval for redis-sentinel. Defaults to 1.
  • sentinels: A list of redis-sentinel address, port and name (ip:port or ip:port name) for this server pool.

For example

alpha:
  listen: 0.0.0.0:6379
  hash: murmur
  hash_tag: "{}"
  distribution: ketama
  timeout: 400
  redis_auth: 123456
  groups:
   - groups_helf_0
   - groups_helf_1
   - groups_helf_2
   - groups_helf_3
  sentinel_heartbeat: 2000
  sentinels:
   - 10.164.97.188:26379 sentinel0
   - 10.164.97.189:26379 sentinel1
   - 10.164.97.190:26379 sentinel2

twemproxy-163's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

twemproxy-163's Issues

ROLE rsp format error

nutcracker.log

[2018-05-12 13:23:45.576] [05] nc_request.c:816 sent 'sentinel get-master-addr-by-name groups_helf_0' req to '10.43.1.244:26400'
[2018-05-12 13:23:45.576] [05] nc_request.c:816 sent 'sentinel get-master-addr-by-name groups_helf_1' req to '10.43.1.244:26400'
[2018-05-12 13:23:45.576] [05] nc_sentinel.c:195 recv 'get-master-addr-by-name' rsp from '10.43.1.244:26400'
[2018-05-12 13:23:45.576] [05] nc_sentinel.c:250 master of group 'groups_helf_0' is the same: '10.43.1.81:6400'
[2018-05-12 13:23:45.576] [05] nc_sentinel.c:195 recv 'get-master-addr-by-name' rsp from '10.43.1.244:26400'
[2018-05-12 13:23:45.576] [05] nc_sentinel.c:250 master of group 'groups_helf_1' is the same: '10.43.1.81:6401'
[2018-05-12 13:23:45.576] [05] nc_redis.c:2984 sent 'ROLE' req to alpha | 10.43.1.81:6400
[2018-05-12 13:23:45.576] [05] nc_redis.c:2984 sent 'ROLE' req to alpha | 10.43.1.81:6401
[2018-05-12 13:23:45.577] [05] nc_server.c:630 recv 'ROLE' rsp from redis
[2018-05-12 13:23:45.577] [01] nc_server.c:658 ROLE rsp format error on alpha | 10.43.1.81:6400
[2018-05-12 13:23:45.577] [05] nc_server.c:630 recv 'ROLE' rsp from redis
[2018-05-12 13:23:45.577] [01] nc_server.c:658 ROLE rsp format error on alpha | 10.43.1.81:6401

twemproxy-163.yaml
###################
alpha:
listen: 0.0.0.0:6379
hash: murmur
hash_tag: "{}"
distribution: ketama
timeout: 400
groups:
- groups_helf_0
- groups_helf_1
sentinel_heartbeat: 2000
sentinels:
- 10.43.1.81:26400 sentinel0
- 10.43.1.83:26400 sentinel1
- 10.43.1.244:26400 sentinel2

Redis version 2.8.3
sentinel.conf
#################
daemonize yes
port 26400
dir "/data/redis/redis_sentinels"
pidfile "/var/run/sentinel6400.pid"
logfile "/data/redis/redis_sentinels/sentinel6400.log"

sentinel monitor groups_helf_0 10.43.1.81 6400 2
sentinel down-after-milliseconds groups_helf_0 5000
sentinel parallel-syncs groups_helf_0 1
sentinel config-epoch groups_helf_0 0

sentinel monitor groups_helf_1 10.43.1.81 6401 2
sentinel down-after-milliseconds groups_helf_1 5000
sentinel parallel-syncs groups_helf_1 1
sentinel config-epoch groups_helf_1 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.