Twemproxy-based redis cluster Solution

Source: Internet
Author: User
Tags benchmark redis cluster
概述

由于单台redis服务器的内存管理能力有限,使用过大内存redis服务器的性能急剧下降,且服务器发生故障将直接影响大面积业务。为了获取更好的缓存性能及扩展型,我们将需要搭建redis集群来满足需求。因redis 3.0 beta支持的集群功能不适合生产环境的使用,所以我们采用twitter正在使用的twemproxy来搭建redis缓存服务器集群,目前用户包括Pinterest、Tumblr、Twitter、Vine、Kiip、Wuaki.tv、Wanelo、Kontera、Wikimedia、Bright、56.com、Snapchat、Digg、Gawkermedia、3scale.net等。

Twemproxy是memcached和redis协议的代理服务器,并能有效减少大量连接对redis服务器的性能影响,它提供的主要特性如下:

 

 

集群架构

 

安装Redis

有三台服务器,一台COS1安装twemproxy,另外两台COS2,COS3安装redis。

 

  1. 下载最新安装包:redis-2.8.9.tar.gz , tcl-8.5.7-6.el6.x86_64.rpm ,nutcracker-0.3.0.tar.gz
  2. 安装必要组件rpm:
    [[email protected] redis-2.8.9]# yum install gcc[[email protected] src]# rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm
  3. 安装Redis:
    [[email protected] src]# tar xvf redis-2.8.9.tar.gz[[email protected] src]# cd redis-2.8.9[[email protected] redis-2.8.9]# make…Hint: To run ‘make test‘ is a good idea ;)make[1]: Leaving directory `/usr/local/src/redis-2.8.9/src‘[root@COS2 redis-2.8.9]# make testAll tests passed without errors!Cleanup: may take some time... OKmake[1]: Leaving directory `/usr/local/src/redis-2.8.9/src‘[root@COS2 redis-2.8.9]# make install[[email protected] redis-2.8.9]# cd /usr/local/bin/[[email protected] bin]# lltotal 13908-rwxr-xr-x. 1 root root 4170264 Apr 26 11:51 redis-benchmark-rwxr-xr-x. 1 root root   22185 Apr 26 11:51 redis-check-aof-rwxr-xr-x. 1 root root   45419 Apr 26 11:51 redis-check-dump-rwxr-xr-x. 1 root root 4263471 Apr 26 11:51 redis-cli-rwxr-xr-x. 1 root root 5726791 Apr 26 11:51 redis-server
  4. 编辑redis配置文件:
    [[email protected] redis-2.8.9]# cp redis.conf /etc/[[email protected] redis-2.8.9]# vim /etc/redredhat-release  redis.conf      [root@COS2 redis-2.8.9]# vim /etc/redis.conf把里面的daemonize no  修改成 daemonize yes
  5. 启动redis服务:
    [[email protected] redis-2.8.9]# redis-server /etc/redis.conf
  6. 测试redis服务:
    [[email protected] redis-2.8.9]# redis-cli 127.0.0.1:6379> set kin kinOK127.0.0.1:6379> get kin
  7. 同样的步骤安装其他redis服务器。

 

 

安装twemproxy
  1. 安装twemproxy:
    [[email protected] src]# tar xvf nutcracker-0.3.0.tar.gz[[email protected] nutcracker-0.3.0]# cd nutcracker-0.3.0[[email protected] src]#./configure [[email protected] nutcracker-0.3.0]# make && make install
  2. 编辑配置文件:
    [[email protected] conf]# cd /usr/local/src/nutcracker-0.3.0/conf[[email protected] conf]# cp nutcracker.yml /etc/[[email protected] conf]# vim /etc/nutcracker.ymlalpha:  listen: 0.0.0.0:22121  hash: fnv1a_64  distribution: ketama  auto_eject_hosts: true  redis: true  server_retry_timeout: 2000  server_failure_limit: 1  servers: --两台redis服务器的地址和端口   - 10.23.22.240:6379:1      - 10.23.22.241:6379:1
  3. 测试配置文件:
    [[email protected] nutcracker-0.3.0]# nutcracker -t /etc/nutcracker.yml nutcracker: configuration file ‘conf/nutcracker.yml‘ syntax is ok
  4. 启动twemproxy:
    [[email protected] nutcracker-0.3.0]# nutcracker  --helpThis is nutcracker-0.3.0Usage: 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)[root@COS1 nutcracker-0.3.0]# nutcracker -d -c /etc/nutcracker.yml[[email protected] nutcracker-0.3.0]# ps -ef|grep nutcrackerroot     15358     1  0 02:40 ?        00:00:00 nutcracker -d -c /etc/nutcracker.yml
  5. 测试twemproxy:
    [[email protected] ~]# redis-cli -p 22121127.0.0.1:22121> get kin"kin"127.0.0.1:22121> set kin kingOK127.0.0.1:22121> get kin"king"

 

 

 

 

性能测试

这里使用redis自带的redis-benchmark进行简单的性能测试,测试结果如下:

  1. Set测试:
    1. 通过twemproxy测试:
      [[email protected] src]# redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t set -d 100 -l –q
      SET: 38167.94 requests per second
    2. 直接对后端redis测试:
      [[email protected] ~]# redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t set -d 100 -l –q
      SET: 53191.49 requests per second
  2. Get测试:
    1. 通过twemproxy测试:
      [[email protected] src]# redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t get -d 100 -l -qGET: 37453.18 requests per second
    2. 直接对后端redis测试:
      [[email protected] ~]# redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t get -d 100 -l -qGET: 62111.80 requests per second
  3. 查看键值分布:
    [[email protected] ~]# redis-cli info|grep db0db0:keys=51483,expires=0,avg_ttl=0[root@COS3 ~]# redis-cli info|grep db0db0:keys=48525,expires=0,avg_ttl=0

测试结果:以基本的set get命令通过twemproxy性能有所下降;通过twemproxy分布基本平均。测试数据以业务测试为准。

基于Twemproxy的Redis集群方案

Related Article

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.