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

Compare with Current View Page History

« Previous Version 2 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 are String to String maps. This is the most straightforward implementation of the group because a region in a Geode cache is a map so the data can be added without any reconfiguration.
Supported Hashes commands: HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HMGET, HMSET, HSCAN, HSETNX, HLEN, HSET, HVALS
5.4 Sets
Redis Sets are unordered sets of Strings. This will be implemented in Geode by holding the set data as keys in the region which will implicitly perform the necessary actions to simulate a set.
Supported Sets commands: SADD, SCARD, SDIFF, SDIFFSTORE, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SREM, SPOP, SRANDMEMBER, SSCAN, SUNION, SUNIONSTORE
5.5 SortedSets
Redis SortedSets are Sets that are ordered by an explicit "score". The ordering does not take into account ordering such as lexicographical or hashing functionality but instead uses the score for sorting. Members of the SortedSet are unique but scores are not, therefore sorted sets are member to score mappings in Geode.

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's are C implementations of the data structure, whereas this implementation is done in Java within Geode. The only difference is that Geode implementation does not utilize the sparse implementation for small cardinalities but is otherwise the same.

Supported HyperLogLog commands: PFADD, PFCOUNT, PFMERGE
5.6 Additional Information
The GemFire Redis Server will also implement other commands to be a full fledged Redis server. However it is worth noting that while Redis has 160+ commands in their protocol, the GemFireRedisServer will support roughly 110 of them. These will cover all basic commands as well and other practical ones that should not be left out. Redis has many commands for server configurations that are set up differently for Geode as well as scripting that isn't supported.
Another important note about keys is that key support within GemFireRedisServer is not the same as Redis. While all values are binary safe, most keys are not as they will have their own Regions in Geode. The Region namespace is defined by Java Strings, and Geode's OQL engine does not support all characters. Therefore some keys may cause failures with Geode if attempting to create a key using non printable characters such as UTF-8 0x01, 0x02, etc.
The backing Regions for each key are partitioned by default, but the default region type can be configured by system property. If different keys are desired to have different types of Regions, these Regions must be defined in cache.xml. The other configuration to strongly consider per use case is defining the number of worker threads to use for Redis clients. 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