mongoDB보다 Redis가 얼마나 빠릅니까?
Redis는 "Blazing Fast"이고 mongoDB도 빠르다고 널리 언급되어 있습니다. 그러나 두 결과를 비교하는 실제 숫자를 찾는 데 문제가 있습니다. 비슷한 구성, 기능 및 작동 (및 다른 구성 및 작동에 따라 요소가 어떻게 변하는지를 보여주는 등) 등이있을 경우 Redis는 10 배 빨라 졌습니까? 2 배 빨라 졌습니까? 5 배 빨라 졌습니까?
나는 단지 성능에 대해서만 말하고 있습니다. mongoDB는 다른 도구이며 더 풍부한 기능 세트가 있음을 이해합니다. 이것은 " Redis보다 mongoDB가 더 낫다 "라는 논쟁 이 아니다 . Redis가 mongoDB를 능가하는 한계는 무엇입니까?
이 시점에서 저렴한 벤치 마크조차 벤치 마크가없는 것보다 낫습니다.
다음 벤치 마크에서 거친 결과 : 배 쓰기, 읽기 3 배 .
다음은 파이썬에서 목표에 맞게 조정할 수있는 간단한 벤치 마크입니다. 각 값이 단순히 설정 / 검색 값이 얼마나 잘 수행되는지보고있었습니다.
#!/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의 결과 :
$ ./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
물론 소금 한 알갱이로 결과를 얻으십시오! 다른 클라이언트 / 다른 구현 등을 사용하여 다른 언어로 프로그래밍하는 경우 결과가 크게 달라질 수 있습니다. 말할 것도없이 사용법은 완전히 다릅니다! 최선의 방법은 정확하게 사용하려는 방식으로 직접 벤치마킹하는 것입니다. 결과적으로 당신은 아마도 각각을 사용 하는 가장 좋은 방법을 알아낼 것입니다 . 항상 자신을 위해 벤치마킹하십시오!
Redis 및 MongoDB 삽입 성능 분석에 대한 이 게시물을 확인하십시오 .
Up to 5000 entries mongodb $push is faster even when compared to Redis RPUSH, then it becames incredibly slow, probably the mongodb array type has linear insertion time and so it becomes slower and slower. mongodb might gain a bit of performances by exposing a constant time insertion list type, but even with the linear time array type (which can guarantee constant time look-up) it has its applications for small sets of data.
Good and simple benchmark
I tried to recalculate the results again using the current versions of redis(2.6.16) and mongo(2.4.8) and here's the result
Completed mongo_set: 100000 ops in 5.23 seconds : 19134.6 ops/sec
Completed mongo_get: 100000 ops in 36.98 seconds : 2703.9 ops/sec
Completed redis_set: 100000 ops in 6.50 seconds : 15389.4 ops/sec
Completed redis_get: 100000 ops in 5.59 seconds : 17896.3 ops/sec
Also this blog post compares both of them but using node.js. It shows the effect of increasing number of entries in the database along with time.
Numbers are going to be hard to find as the two are not quite in the same space. The general answer is that Redis 10 - 30% faster when the data set fits within working memory of a single machine. Once that amount of data is exceeded, Redis fails. Mongo will slow down at an amount which depends on the type of load. For an insert only type of load one user recently reported a slowdown of 6 to 7 orders of magnitude (10,000 to 100,000 times) but that report also admitted that there were configuration issues, and that this was a very atypical working load. Normal read heavy loads anecdotally slow by about 10X when some of the data must be read from disk.
Conclusion: Redis will be faster but not by a whole lot.
Here is an excellent article about session performance in the Tornado framework about 1 year old. It has a comparison between a few different implementations, of which Redis and MongoDB are included. The graph in the article states that Redis is behind MongoDB by about 10% in this specific use case.
Redis comes with a built in benchmark that will analyze the performance of the machine you are on. There is a ton of raw data from it at the Benchmark wiki for Redis. But you might have to look around a bit for Mongo. Like here, here, and some random polish numbers (but it gives you a starting point for running some MongoDB benchmarks yourself).
I believe the best solution to this problem is to perform the tests yourself in the types of situations you expect.
In my case, what has been a determining factor in performance comparison, is the MongoDb WriteConcern that is used. Most mongo drivers nowadays will set the default WriteConcern to ACKNOWLEDGED which means 'written to RAM' (Mongo2.6.3-WriteConcern), in that regards, it was very comparable to redis for most write operations.
But the reality is depending on your application needs and production environment setup, you may want to change this concern to WriteConcern.JOURNALED (written to oplog) or WriteConcern.FSYNCED (written to disk) or even written to replica sets (back-ups) if it is needed.
Then you may start seeing some performance decrease. Other important factors also include, how optimized your data access patterns are, index miss % (see mongostat) and indexes in general.
I think that the 2-3X on the shown benchmark are misleading, since if you it also depends on the hardware you run it on - from my experience, the 'stronger' the machine is, the bigger the gap (in favor of Redis) will be, probably by the fact that the benchmark hits the memory bounds limit pretty fast.
As for the memory capacity - this is partially true, since there are also ways to go around that, there are (commercial) products that writes back Redis data to disk, and also cluster (multi-sharded) solutions that overcome the memory-size limitation.
참고URL : https://stackoverflow.com/questions/5252577/how-much-faster-is-redis-than-mongodb
'Programming' 카테고리의 다른 글
어떤 스칼라 웹 프레임 워크를 사용할 수 있습니까? (0) | 2020.05.10 |
---|---|
HTML 양식 중첩 제한을 어떻게 극복합니까? (0) | 2020.05.10 |
AngularJS에서 지시문에서 지시문 추가 (0) | 2020.05.10 |
helper와 helper_method는 무엇을합니까? (0) | 2020.05.10 |
간단한 파이썬 루프를 어떻게 병렬화합니까? (0) | 2020.05.10 |