A comparison of Redis, Memcache, and MongoDB

Source: Internet
Author: User
Tags memcached redis

1 , Performance

are relatively high, performance is not a bottleneck for us

Generally speaking, TPS Aspect Redis and the memcache almost, more than MongoDB

2 , the convenience of Operation

memcache Single Data structure

Redis enrich some, data manipulation aspect, Redis a little better, less network IO number of

MongoDB support rich data expression, index, most similar relational database, support query language is very rich

3 , the size of the memory space, and the size of the data volume

Redis in the 2.0 after the version has added its own VMS limits of physical memory, which can be Key Value Set the expiration time (similar memcache )

memcache maximum available memory can be modified , Adopt LRU algorithm

MongoDB suitable for storage of large data volumes, dependent on operating system VMS do memory management, eat memory is also very bad, service not with other services together

4 , availability (single point of issue)

For a single point of problem,

Redis , relies on the client to implement distributed read-write; master-slave replication relies on the entire snapshot every time the primary node is reconnected from the node , no incremental replication, due to performance and efficiency issues,

so the single point problem is more complex; sharding, need to rely on program setting consistency Hash mechanism.

an alternative is to not Redis Its own replication mechanism, using its own proactive replication (multiple storage), or change the way to incremental replication (need to implement), consistency issues and performance tradeoffs

Memcache There is no data redundancy mechanism, nor is it necessary; for fault prevention, rely on mature Hash or a ring-shaped algorithm to solve the jitter problem caused by a single point of failure.

MongoDB Support Master-slave,replicaset (Internal use Paxos election algorithm, automatic failure recovery) , Auto sharding mechanism to shield the client from the failover and segmentation mechanisms.

5 , Reliability (Persistence)

For data persistence and data recovery,

Redis Support (Snapshots, AOF ): Dependent on the snapshot for persistence, aof increased reliability while impacting performance

memcache not supported, usually used in cache , improve performance;

MongoDB from 1.8 version starts with Binlog Way to support persistent reliability

6 , data consistency (transactional support)

Memcache in concurrent scenarios, use the CAs Consistency Assurance

Redis transaction support is weaker and can only guarantee continuous execution of each operation in a transaction

MongoDB Transaction not supported

7 , data analysis

MongoDB built-in features for data analysis (MapReduce), others do not support

8 , Application Scenarios

Redis : More performance operations and calculations with smaller data volumes

memcache : Used to reduce the database in a dynamic system load, improve performance ; do cache, improve performance (suitable for read and write less, for a large amount of data, you can use sharding )

MongoDB: The main solution to the massive data access efficiency problem

Memcached

memcached:
Memcached can take advantage of multicore advantage, single instance throughput is extremely high, can reach hundreds of thousands of QPS (depending on key, value byte size and server hardware performance, The peak of the QPS in the daily environment is around 4-6w). Suitable for maximum carrying capacity. The
supports direct configuration for session handle.
Pits are small. Limitations of
memcached:
supports only simple KEY/VALUE data structures, unlike Redis, which supports rich data types. The
cannot be persisted, data cannot be backed up, it can only be used for cache use, and data is lost after a reboot. The
cannot synchronize data, and data in the MC cannot be migrated to another instance of MC. The
memcached memory allocation uses the slab allocation mechanism to manage memory, which causes memory utilization to decrease when the value size distribution is large, and causes problems such as kicking out when low utilization occurs. Users need to focus on value design.

Redis
Benefits of Redis:
supports a variety of data structures, such as String, list (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimation)
supports persistent operations, can be aof and RDB data persisted to disk, so as to perform data backup or data recovery operations, better prevent data loss means. The
supports data replication through replication, master-slave mechanism enables synchronous replication of data in real time, supports multi-level replication and incremental replication, and the Master-slave mechanism is an important means for Redis to perform ha.
Single-threaded requests, all commands are executed serially, and there is no need to consider data consistency issues in the concurrency scenario. The
supports the PUB/SUB message subscription mechanism, which can be used for message subscription and notification. The
supports simple transactional requirements, but industry usage scenarios are rare and immature.

Limitations of Redis:
Redis can only use a single thread and performance is limited to CPU performance, so the single instance CPU can reach 5-6wqps per second (depending on data structure, data size and server hardware performance, and the QPS peak in daily environments is around 1-2w).
Support simple transaction requirements, but the industry use of the scene is very small, immature, both advantages and disadvantages.
Redis consumes more memory on string types, and can use Dict (hash table) to compress storage to reduce memory consumption.

:) Here is my personal supplement
Both MC and Redis are key-value types, are not suitable for establishing relationships between different datasets, and are not suitable for query search. For example, Redis's keyspattern , a matching operation, is a disaster for redis performance.

Mogodb
Mogodb is a document-type database. First explain the database of the document, that is, you can store XML, JSON, Bson type of data. These data are self-describing (self-describing), presenting hierarchical tree-like data structures. Redis can store simple relational data in hash.
MOGODB Store JSON-formatted data.
Suitable for scenarios: event logging, content management or blogging platforms, such as commenting systems.

NOSQ's products are currently many, the architect's choice of guidance mainly has the following two factors:
1) Suitable for the application of the use of the scene, such as the comment system is more appropriate to use MOGODB, and MC can also be implemented (the application to convert data into JSON, but some data update inconvenient)
2) The team develops familiar technologies, such as a team that has been using MC for a limited selection of MC rather than Redis.
In the middle of a serious situation, the development team has been using MOGODB to continue to select Mogodb in a scenario suitable for KV nosq.

A book recommended to you: <nosql essence >

Memcache and Redis are key-value storage systems, whereas Redis may be more adaptable than memcache, storing more value types, and Redis supports master-slave synchronization. And MONGO is a document-based database.
1. Memcache can be used primarily as a caching system for caching files, database query results, etc. because it reads in memory and improves the performance of Web services. can be used for Web site data caching, to reduce the direct query of the database, reduce stress.
2, Redis Of course can also be used as a cache, but you look at the Weibo, many scenarios are applications of Redis.
3, MongoDB is a document-based database. Its query speed is very fast, it is very suitable for real-time inserts, updates and queries, such as logging, message logging and so on.

Get more information about your study address

A comparison of Redis, Memcache, and MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.