Redis比mongoDB快多少? [英] How much faster is Redis than mongoDB?

查看:364
本文介绍了Redis比mongoDB快多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们广泛提到Redis是"Blazing Fast",而mongoDB也很快.但是,我很难找到比较两者结果的实际数字.给定相似的配置,功能和操作(并可能显示因素如何随着不同的配置和操作而变化)等,Redis的速度快10倍吗?快2倍吗?快5倍吗?

It's widely mentioned that Redis is "Blazing Fast" and mongoDB is fast too. But, I'm having trouble finding actual numbers comparing the results of the two. Given similar configurations, features and operations (and maybe showing how the factor changes with different configurations and operations), etc, is Redis 10x faster?, 2x faster?, 5x faster?

我只说表演.我知道mongoDB是另一种工具,具有更丰富的功能集.这不是"MongoDB比Redis更好".我问,Redis的性能要比mongoDB好多少?

I'm ONLY speaking of performance. I understand that mongoDB is a different tool and has a richer feature set. This is not the "Is mongoDB better than Redis" debate. I'm asking, by what margin does Redis outperform mongoDB?

在这一点上,即使是便宜的基准也比没有基准要好.

At this point, even cheap benchmarks are better than no benchmarks.

推荐答案

来自以下基准的粗略结果: 2倍写入,3倍读取.

Rough results from the following benchmark: 2x write, 3x read.

这是python中的一个简单基准,您可以适应您的目的,我正在研究每个参数在简单地设置/检索值方面的表现如何:

Here's a simple benchmark in python you can adapt to your purposes, I was looking at how well each would perform simply setting/retrieving values:

#!/usr/bin/env python2.7
import sys, time
from pymongo import Connection
import redis

# connect to redis & mongodb
redis = redis.Redis()
mongo = Connection().test
collection = mongo['test']
collection.ensure_index('key', unique=True)

def mongo_set(data):
    for k, v in data.iteritems():
        collection.insert({'key': k, 'value': v})

def mongo_get(data):
    for k in data.iterkeys():
        val = collection.find_one({'key': k}, fields=('value',)).get('value')

def redis_set(data):
    for k, v in data.iteritems():
        redis.set(k, v)

def redis_get(data):
    for k in data.iterkeys():
        val = redis.get(k)

def do_tests(num, tests):
    # setup dict with key/values to retrieve
    data = {'key' + str(i): 'val' + str(i)*100 for i in range(num)}
    # run tests
    for test in tests:
        start = time.time()
        test(data)
        elapsed = time.time() - start
        print "Completed %s: %d ops in %.2f seconds : %.1f ops/sec" % (test.__name__, num, elapsed, num / elapsed)

if __name__ == '__main__':
    num = 1000 if len(sys.argv) == 1 else int(sys.argv[1])
    tests = [mongo_set, mongo_get, redis_set, redis_get] # order of tests is significant here!
    do_tests(num, tests)

mongodb 1.8.1和redis 2.2.5以及最新的pymongo/redis-py的结果:

Results for with mongodb 1.8.1 and redis 2.2.5 and latest pymongo/redis-py:

$ ./cache_benchmark.py 10000
Completed mongo_set: 10000 ops in 1.40 seconds : 7167.6 ops/sec
Completed mongo_get: 10000 ops in 2.38 seconds : 4206.2 ops/sec
Completed redis_set: 10000 ops in 0.78 seconds : 12752.6 ops/sec
Completed redis_get: 10000 ops in 0.89 seconds : 11277.0 ops/sec

当然要加一点盐!如果您使用另一种语言进行编程,使用其他客户端/不同的实现方式等,则结果将大相径庭.更不用说您的用法将完全不同!最好的选择是按照自己打算使用它们的方式对它们进行基准测试.当然,您可能会想出最好的方式来使用它们.永远为自己做基准测试!

Take the results with a grain of salt of course! If you are programming in another language, using other clients/different implementations, etc your results will vary wildy. Not to mention your usage will be completely different! Your best bet is to benchmark them yourself, in precisely the manner you are intending to use them. As a corollary you'll probably figure out the best way to make use of each. Always benchmark for yourself!

这篇关于Redis比mongoDB快多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆