You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

1. 介绍

本也描述了一个针对 Redis的适配器实现.
2. 相关文档
Redis 网站: http://redis.io/
Redis 数据类型 - http://redis.io/topics/data-types
3. 术语
Redis - 一个开源的, 网络化, 内存级, 键值数据存储

4. 需求



5. 架构描述 Description

本适配器, 称为GemFireRedisServer, 与 Redis 协议兼容, 但是使用 Geode 作为底层的数据存储引擎. 它允许 Redis 客户端无缝地切换到 Geode 上, 允许它们拥有和以前一样相同的功能, 但是是分布式系统. 这个服务器适配器的重点是处理所有的数据类型, 正常在 Redis 服务器上实现的. 这包括 Strings, Lists, Hashes, Sets, SortedSets 和 HyperLogLogs. 这些术语都是 Redis 特定的, 服务器的数据类型处理也相同. 每个类型的规范详细描述如下.

5.1 Strings
Redis Strings 是数据字符串. 它是二进制安全型, 暗示着它们能够保存任意类型的数据, 最大的大小可以是 512MB. 一个 Cache 所有的字符串都可以使用一个Geode region来保存.
已支持的 Redis 字符串命令: APPEND, BITCOUNT, BITOP, BITPOS, DECR, DECRBY, GET, GETBIT, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, MGET, MSET, MSETNX, PSETEX, SET, SETBIT, SETEX, SETNX, STRLEN

5.2 Lists
Redis Lists 是一个字符串的Linked Lists,  此列表的操作被设计成可以进行达到 List 极限的重度访问. Lists 保存在 Geode 中, 通过松耦合的索引进行保存, 通过Query 进行查询. 理解 List 限制就显得十分重要. Geode 没有 Lists 的内隐观念, 因此 List 是在 Regions 中模拟出来的. 由于这个原因, lists 是数据弹性扩展的, 以增加延时为代价. 与Sets 或 Hashes相反, 它是无序的, Lists 需要格外地小心排序和一致性问题,  在性能上会有很大代价. 举个例子, LPUSH 命令需要确定 List 最左边的索引, 追加到 List 起始处, 同时更新 List 索引. 而在 Redis 中, lists 并不是可扩展的, 因此这些任务是不重要的, 但是在 Geode 中, 在分布式 List 中, 一个简单的 pop/push 操作都能够引入多个网络跳. 因为索引被映射到 List 元素中, 移动 list elements 是不现实的, LINSERT 是不支持的.

Supported Redis Lists commands: LINDEX, LLEN, LPOP, LPUSH, LPUSHX, LRANGE, LREM, LSET, LTRIM, RPOP, RPUSH, RPUSHX
5.3 Hashes
Redis Hashes 是字符串到字符串的映射. 是 Group 最直接的实现, 因为一个 Region 就是一个 Map, 因此数据能够被添加进去, 不需要任何重新配置.
Supported Hashes commands: HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HMGET, HMSET, HSCAN, HSETNX, HLEN, HSET, HVALS
5.4 Sets
Redis Sets 是无序的字符串集合. 它将在 Geode 中实现, 通过保存 set data 作为 keys, 在这个 region 中将执行必要的动作来模拟一个 set.
Supported Sets commands: SADD, SCARD, SDIFF, SDIFFSTORE, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SREM, SPOP, SRANDMEMBER, SSCAN, SUNION, SUNIONSTORE
5.5 SortedSets
Redis SortedSets 是一个 Sets , 通过一个显式的 "score" 来进行排序. 排序不考虑帐号排序, 例如 lexicographical 或 hashing 功能, 而不是使用"score" 评分. SortedSet 的成员是唯一的, 但是评分不是唯一的, 因此在Geode中,  sorted sets 是成员的评分映射.

Supported SortedSets commands: ZADD, ZCARD, ZCOUNT, ZINCRBY, ZLEXCOUNT, ZRANGE, ZRANGEBYLEX, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYLEX, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE

5.6 HyperLogLogs
Redis HyperLogLog 是 C语言实现的数据结构, 而在 Geode 中通过 Java 来实现这个. 唯一的区别是对于小基数, Geode 实现并没有利用稀疏实现.

Supported HyperLogLog commands: PFADD, PFCOUNT, PFMERGE
5.6 额外的信息
GemFire Redis 服务器也实现了其他的命令成为了逐渐丰满的 Redis 服务器. 而 Redis 有160+ 个命令, 不用全部实现, GemFireRedisServer 将支持大约110左右. 这些将覆盖所有的基本命令, 而其他的命令也不能忽略. 对于服务器配置, Redis 有许多命令, 在 Geode 中以不同的方式来设置, 脚本不支持.
另外一个值得注意的事情是 keys 是在GemFireRedisServer所支持的key, 与 Redis 不相同. 而所有的值是二进制安全的, 大多数 keys 不是, 它们有自己的 Regions. Region 命令空间通过 Java Strings来定义, 同时 Geode's OQL 引擎不支持所有的字符. 因此一些 keys 可能会导致失败, 如果使用创建一个key (使用非打印字符如 UTF-8 0x01, 0x02,等).
对于每个 key, 后面的 Regions 默认情况下是分区的, 但是默认的 region 类型能够通过系统属性来配置. 如果不同的 keys 被要求有不同的 Region 类型, 这些Regions 必须被定义在 cache.xml中. 其他配置需要考虑应用场景 定义了 worker 线程的数量为 Redis客户端使用. This is also defined by system property and more information can be found in the GemFireRedisServer javadoc. To put it all together, this adapter can be instantiated through invoking com.gemstone.gemfire.redis.GemFireRedisServer independently or programmatically, or through GFSH when the property redis-port is set.
Supported Key commands: DEL, DBSIZE, EXISTS, EXPIRE, EXPIREAT, FLUSHALL, FLUSHDB, KEYS, PERSIST, PEXPIRE, PEXPIREAT, PTTL, SCAN, TTL
Supported Server commands: AUTH, ECHO, PING, QUIT
Supported Transaction commands: DISCARD, EXEC, MULTI

6. Comparison to Redis
The following points are the main differentiators between Geode/GemFireRedisServer and Redis: 
6.1 Concurrency
  • Redis is a single-threaded server. It is not designed to benefit from multiple CPU cores. People are supposed to launch several Redis instances to scale out on several cores if needed. It is not really fair to compare one single Redis instance to a multi-threaded data store.
We have leveraged the highly concurrent nature of Geode to make GemFireRedisServer concurrent. Each server instance will start 4 * (number of processor cores) threads for processing client requests,  but this can be configured by system property where either one thread per connection can be created or a specific number of client handler threads can be requested.
6.2 Scalability
In Redis, a single data structure cannot scale beyond the memory available on a single box. From: http://redis.io/topics/partitioning
  • The partitioning granuliary is the key, so it is not possible to shard a dataset with a single huge key like a very big sorted set.
(In Redis, key is the name of the data structure, so a hashmap.get() take the form HGET key field)
This limitation is not expected to go away even with the introduction of redis-cluster (which is going to partition the key space i.e. data structure name space). So, with Redis cluster you can scale up the number of data structures, not the data structures themselves.
In GemFireRedisServer, all Redis data structures are backed by PartitionedRegions, so each Redis data structure is horizontally scalable. 
6.3 Replication
In Redis, you can have any number of slaves for a master server. Replication from master to slave is always asynchronous, which may lead to data loss when master crashes before replicating.
When a slave is started, it gets entire data set from the master (even though the salve was persistent). It does, however, support a "Partial resynchronization" from master to slave, if the link between master and slave goes down.
Slaves can be used for scaling read operations.
In Geode, you can have upto 3 redundant copies (for partitioned regions). When persistent, these replicas will first recover from local disk and only get the delta from the primary.  These copies can be used for read operations. 
6.4 Persistence
Redis supports Snapshots as well as AOF (Append Only) persistence. AOF is a log of all the operations, which needs to be rebuilt on re-starts. AOF is automatically re-written when it gets too large.
Geode persistence is also append only, however keys and values are kept in separate files on disk. On restarts, only the key's file needs to be read.
6.5 HA
Redis uses Sentinel for managing HA. User starts a number of sentinel processes by providing them a list of all the masters (the slaves are automatically detected). When a primary crashes, the sentinels gossip and elect a new primary from among the slaves.
In Geode, all members are connected to all other members, failover is automatic. (no need to provide a list of all members, which is error prone)
6.6 Network Partition
With the sentinel approach, there is no real protection from network partition. The documentation mentions that write quorum should be used to guard against writing to a primary on the loosing side, however, since the replication is asynchronous, there will still be some amount of data loss. (This will be fixed with redis-cluster, no more need of sentinels for partition detection)
Geode has network partition detection built in. The loosing side servers will shutdown/fence themselves, so that clients cannot connect to them.
7. Performance and Scalability
These are some performance numbers acquired using the redis-benchmark utility. All these tests are run using separate bare metal machines for each node and client.
Run using no pipelining and 1KB payloads

Redis

SET: 100894.94 requests per second

GET: 103504.02 requests per second

INCR: 99662.14 requests per second

SADD: 99559.35 requests per second 

GemFireRedisServer

SET: 87627.06 requests per second

GET: 102988.52 requests per second

INCR: 92251.61 requests per second

SADD: 92254.50 requests per second

 

Pipelining 16 requests at a time

SET: 109277.91 requests per second

GET: 113583.70 requests per second

INCR: 1061300.75 requests per second

SADD: 989119.69 requests per second

GemFireRedisServer

SET: 109109.55 requests per second

GET: 113523.87 requests per second

INCR: 575023.25 requests per second

SADD: 644678.81 requests per second

Scalability is not within the framework of this specification as Geode handles the scaling independently of this implementation.
8. Testing
TBD
9. Documentation
TBD

 

  • No labels