LightCloud adds support for Redis

Plurk's open-source cloud database LightCloud got a bit more powerful by supporting Redis.

Redis is yet another key-value database, but with some nice and curly twists:

  • it's persistent (but one has to hold the dataset in the memory)
  • it supports unique datatypes such as lists and sets
  • it can do some very interesting stuff like union and intersection between sets
  • it's very fast since everything is kept in memory

How does it compare to Tokyo Tyrant?

LightCloud was initially built around Tokyo Tyrant, so a comparison between these two is inevitable.

On my first benchmarks it seemed that Redis was 7 to 10 times faster than Tokyo Tyrant, but doing more tests I have found out that it's slightly faster. My benchmarks can be read in a section below. The bottom line thought is that Redis is faster than Tokyo Tyrant.

The thing that makes Redis interesting is the extra data types such as sets and lists. It should be stated thought that Tokyo Tyrant supports Lua scripting which enables one to create custom datatypes (for example a list extension in Lua). Lua scripting is really powerful, but Redis's list operations are also nice to have. It's clear thought, that Tokyo Tyrant's Lua scripting offers more freedom.

In the database layer it's important to note that Redis has to keep the data in memory - - while Tokyo Tyrant does not. This enables Redis to do some powerful features - such as intersection between sets. A major problem with Redis's approach is that one must have all the data in the memory (which means that Redis it not a good choice if you have lots of data).

On scalability side Redis is weaker than Tokyo Tyrant as Redis only supports master-slave replication, while Tokyo Tyrant supports master-master replication.

The last remark is that Redis is a new product and there are some rough edges. Tokyo Tyrant is an old and well tested product. Both products are under active development thought.

You can read more about Redis in the README file.

Benchmarks

The benchmark program outputs following stats:

Finished "Tyrant set" 10000 times in 5.71 sec [1750.8 operations pr.sec]
Finished "Redis set" 10000 times in 3.64 sec [2749.5 operations pr.sec]
------
Finished "Tyrant get" 10000 times in 2.06 sec [4842.8 operations pr.sec]
Finished "Redis get" 10000 times in 1.75 sec [5701.0 operations pr.sec]
------
Finished "Tyrant list_add" 10000 times in 6.50 sec [1538.8 operations pr.sec]
Finished "Redis list_add" 10000 times in 5.41 sec [1849.3 operations pr.sec]
------
Finished "Tyrant delete" 10000 times in 15.88 sec [629.7 operations pr.sec]
Finished "Redis delete" 10000 times in 8.86 sec [1128.5 operations pr.sec]

It's clear that Redis is faster - sometimes even 2x faster. One should note thought that Redis does not hit disk, so it's really expected to be faster :-)

How to use it with LightCloud?

import lightcloud

LIGHT_CLOUD = {
    'lookup1_A': [ '127.0.0.1:10000' ],
    'storage1_A': [ '127.0.0.1:12000']
}
lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD)
lightcloud.init(lookup_nodes, storage_nodes, node_type=lightcloud.RedisNode)

def test_set_get():
    lightcloud.set('hello', 'world')
    assert lightcloud.get('hello') == 'world'

Are memory databases the future?

High Scalability has written some interesting pieces on memory databases, they are worth a read:

Conclusion

Redis offers another take on a database and Salvatore Sanfilippo seems to be driven by passion - - which is important for any project.

It's clear that Redis is faster than Tokyo Tyrant, but currently I think that Tokyo Tyrant is a more mature product - - so unless you need sets, then Tokyo Tyrant seems to be a safer choice.

Personally, I really welcome the development of both products and a big kudos goes to Salvatore Sanfilippo and Mikio Hirabayashi for their amazing work.

10. Jun 2009 Announcements · Code · Python
© Amir Salihefendic