`
gaojingsong
  • 浏览: 1182016 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【twemproxy 介绍】

阅读更多

twemproxy,也叫nutcraker。是一个twtter开源的一个redis和memcache代理服务器。 redis作为一个高效的缓存服务器,非常具有应用价值。但是当使用比较多的时候,就希望可以通过某种方式 统一进行管理。避免每个应用每个客户端管理连接的松散性。同时在一定程度上变得可以控制。

 

Twemproxy是一种代理分片机制,由Twitter开源。Twemproxy作为代理,可接受来自多个程序的访问,按照路由规则,转发给后台的各个Redis服务器,再原路返回。该方案很好的解决了单个Redis实例承载能力的问题。当然,Twemproxy本身也是单点,需要用Keepalived做高可用方案。通过Twemproxy可以使用多台服务器来水平扩张redis服务,可以有效的避免单点故障问题。虽然使用Twemproxy需要更多的硬件资源和在redis性能有一定的损失(twitter测试约20%),但是能够提高整个系统的HA也是相当划算的。不熟悉twemproxy的同学,如果玩过nginx反向代理或者mysql proxy,那么你肯定也懂twemproxy了。其实twemproxy不光实现了redis协议,还实现了memcached协议,什么意思?换句话说,twemproxy不光可以代理redis,还可以代理memcached,官方说明:

twemproxy (pronounced "two-em-proxy"), aka nutcracker is a fast and lightweight proxy for memcachedand redis protocol. It was built primarily to reduce the number of connections to the caching servers on the backend. This, together with protocol pipeling and sharding enables you to horizontally scale your distributed caching architecture.

 

Features

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 across 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 via stats exposed on the stats monitoring port.

Works with Linux, *BSD, OS X and SmartOS (Solaris)

 

 

twemproxy

  • 支持失败节点自动删除

    • 可以设置重新连接该节点的时间
    • 可以设置连接多少次之后删除该节点
    • 该方式适合作为cache存储
  • 支持设置HashTag

    • 通过HashTag可以自己设定将两个KEYhash到同一个实例上去。
  • 减少与redis的直接连接数

    • 保持与redis的长连接
    • 可设置代理与后台每个redis连接的数目
  • 自动分片到后端多个redis实例上

    • 多种hash算法(部分还没有研究明白)
    • 可以设置后端实例的权重
  • 避免单点问题

    • 可以平行部署多个代理层.client自动选择可用的一个
  • 支持redis pipelining request

  • 支持状态监控

    • 可设置状态监控ip和端口,访问ip和端口可以得到一个json格式的状态信息串
    • 可设置监控信息刷新间隔时间
  • 高吞吐量

    • 连接复用,内存复用。
    • 将多个连接请求,组成reids pipelining统一向redis请求。

Zero Copy

In twemproxy, all the memory for incoming requests and outgoing responses is allocated in mbuf. Mbuf enables zero-copy because the same buffer on which a request was received from the client is used for forwarding it to the server. Similarly the same mbuf on which a response was received from the server is used for forwarding it to the client.

Furthermore, memory for mbufs is managed using a reuse pool. This means that once mbuf is allocated, it is not deallocated, but just put back into the reuse pool. By default each mbuf chunk is set to 16K bytes in size. There is a trade-off between the mbuf size and number of concurrent connections twemproxy can support. A large mbuf size reduces the number of read syscalls made by twemproxy when reading requests or responses. However, with a large mbuf size, every active connection would use up 16K bytes of buffer which might be an issue when twemproxy is handling large number of concurrent connections from clients. When twemproxy is meant to handle a large number of concurrent client connections, you should set chunk size to a small value like 512 bytes using the -m or --mbuf-size=N argument.

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.
  • preconnect: A boolean value that controls if twemproxy should preconnect 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.
  • 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.
  • auto_eject_hosts: A boolean value that controls if server should be ejected temporarily when it fails consecutively server_failure_limit times. See liveness recommendations for information. Defaults 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. Defaults to 30000 msec.
  • 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.
  • servers: A list of server address, port and weight (name:port:weight or ip:port:weight) for this server pool.
0
0
分享到:
评论

相关推荐

    第 5 章: Redis 多机功能介绍.rar

    本章将详细介绍Redis 的多机功能,包括集群、复制与Sentinel系统以及twemproxy。 **1. 集群(Cluster)** Redis 集群是实现多机功能的关键,它允许将数据分布在多个节点上,提供高可用性和水平扩展性。在Redis ...

    Redis集群_实际使用自己整理的版本.docx

    本文将详细介绍几种常见的Redis集群方案,包括客户端分片、Twemproxy、Codis以及Redis 3.0集群。 #### 一、客户端分片 **概念**: 客户端分片是一种将分片逻辑置于客户端实现的策略。该方案通过客户端预先定义好的...

    藏经阁-Uber,SRE,缓存以及微服务.pdf

    本文将详细介绍 Uber 的技术架构、SRE 实践、缓存机制以及微服务架构。 Uber 的技术架构 Uber 的技术架构是基于微服务架构的,使用多种编程语言,如 Go、Java、Node.js、Python、C/C++ 等。其技术栈包括: * 存储...

    藏经阁-Uber SRE以及Cache服务在微服务环境下的演进.pdf

    下面,我们将详细地介绍这个知识点。 Uber 的增长历史 Uber 从一个小的出租车公司发展成为一个全球性的技术公司,拥有多个业务线,包括消费者出行、商务出行、餐饮配送等。这个增长过程中,Uber 面临着越来越...

    开涛高可用高并发-亿级流量核心技术

    21.4.2 商品介绍SSDB集群配置 413 21.4.3 其他信息Redis配置 417 21.4.4 集群测试 418 21.4.5 Twemproxy配置 419 21.5 动态服务实现 422 21.5.1 项目搭建 422 21.5.2 项目依赖 422 21.5.3 核心代码 423 21.5.4 基本...

    高可用Redis服务架构设计.docx

    下面介绍两种常见的实现方式: 1. 单机版Redis Server:简单易部署,但存在单点故障风险,一旦服务器或进程出现问题,服务就会中断,数据可能丢失。 2. 主从同步+Sentinel:在两台服务器上分别部署主Redis(master...

    跟我学Nginx + Lua开发

    例如第三章介绍了Redis/SSDB和Twemproxy的安装与使用,第五章介绍了常用的Lua开发库,第六章和第七章分别通过Web开发实战1——HTTP服务和Web开发实战2——商品详情页来展示实际应用。第八章介绍了流量复制、AB测试和...

    Redis的改造与实践

    然而,官方提供的解决方案以及开源社区中的分布式实现如Twemproxy,并不能完全满足这些新需求。 **Twemproxy存在的问题**: 1. **缺乏集群管理功能**:对于大规模集群而言,缺少有效的集群管理机制会导致运维工作变...

    Redis持久化以及集群部署

    通过本文的介绍,我们可以了解到 Redis 持久化机制的选择以及集群部署方案的重要性。不同场景下应综合考虑各种因素来做出最佳决策。同时,在实际部署过程中还需要关注一些细节问题,如客户端兼容性、数据一致性保障...

    redis Sentinel模式详解.docx

    5. Redis 高可用性服务的解决方案:包括 Keepalived、Codis、Twemproxy 和 Redis Sentinel 等,其中 Redis Sentinel 是官方的解决方案,可以监控 Redis Server 服务是否正常,并自动地将备份(slave)Redis Server ...

    跟我学Nginx+Lua开发.pdf

    - **第三章**: Redis/SSDB+Twemproxy安装与使用。学习如何利用这些工具优化性能。 - **第四章**(未提及): 可能涵盖更高级的主题,例如性能调优或最佳实践。 - **第五章**: 常用Lua开发库3-模板渲染。介绍常用的Lua...

    藏经阁-瓜子后端技术架构的变迁.pdf

    本文将详细介绍瓜子后端技术架构的变迁,包括架构的演进过程、技术选型、问题解决方案等。 一、架构V0.1(quick but dirty work) * 主要精力集中在业务上,快速迭代,实时响应业务需求 * 周边服务尽量通过外部...

    京东商品详情页Nginx+Lua的大规模应用.pdf

    - 利用本地Twemproxy进行分片,减少了与分布式Redis服务的连接数。 - 数据静态化和模板动态化方面,通过对各系统数据进行异构存储和聚合,以及支持随时变更模板需求,实现了前端展示的灵活性和响应速度。 七、面临...

    荔枝FM异地多活方案

    在荔枝FM的异地多活架构中,采用的数据库模型包括MySQL Cluster集群、Redis客户端哈希/Twemproxy集群和Cassandra集群。每种数据库模型在CAP三要素的权衡上各有侧重,例如MySQL Cluster更偏重AC模型,Redis偏重CP模型...

    Windows环境下搭建Redis集群所需资源及其文档

    下面将详细介绍在Windows上构建Redis集群的关键步骤和相关知识点。 首先,你需要下载Redis的Windows版本。Redis官方并不直接支持Windows,但社区提供了兼容版本,如MSOpenTech的Redis或Redis Labs的Windows版。确保...

    亿级流量电商详情页系统实战-缓存架构+高可用服务架构+微服务架构

    9、基础设施技术涵盖了大型系统中常用的各种技术,包括了:LVS+KeepAlived、Nginx+Lua、Twemproxy+SSDB+Redis(磁盘+内存的分布式与读写分离双KV集群)、RabbitMQ消息中间件 10、直接可以二次开发的代码:本次升级...

    分布式redis储存方式

    下面将详细介绍分布式Redis的几种常见储存方式以及它们在Java中的应用。 1. **主从复制** (Master-Slave Replication) 主从复制是最基础的分布式Redis方案,一个Redis实例作为主节点负责写操作,多个从节点通过...

Global site tag (gtag.js) - Google Analytics