Redis, memcached, mongoDB contrast

Source: Internet
Author: User
Tags memcached mongodb

MongoDB and memcached are not something within a category. MongoDB is a document-type non-relational database, its advantage is that the query function is more powerful, can store massive data. Mongodb and memcached do not exist who replace who's problem.

Memcached and Redis are both memory-based databases, where data is stored in memory and directly accessed via TCP, with the advantage of being fast and high concurrency.

Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It provides a dynamic, database-driven site speed by caching data and objects in memory to reduce the number of times the database is read.

Memcached distribution is not implemented on the server side, but in the client application, that is, through the built-in algorithm to develop the target data node, Memcached distributed is based on the client's key hash to do the equalization, is a pseudo-distributed system.

Redis is a key-value storage system. Similar to Memcached, it supports storing more value types, including string (string), list (linked list), set (set), and Zset (ordered collection). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with Memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to the disk or writes the modification to the appended record file.






1. Performance

In general, TPS is about the same as Redis and Memcache, more than Mongodb.
Redis supports high concurrency, and official propaganda supports 100,000 levels of concurrent read and write.

2, the convenience of the operation

MEMCACHED Data Structure single (Key-value).
Redis supports more data types, data manipulation, Redis, or direct data enrichment on the server side, which reduces network IO times and data volumes, while also providing string, Hash, List, set, and sorted Storage of data structures such as set.
Mongodb supports rich data expression, index, most similar relational database, support query language is very rich.

3. Size of memory space and amount of data

Redis added its own VM features after the 2.0 release, breaking the limits of physical memory, can limit the size of memory, when the data exceeds the threshold, the most infrequently used data in memory is saved to the paging file of the hard disk by an algorithm similar to LRU; you can set the expiration time for key value (similar to Memcached); Redis One value supports 512MB maximum.
Memcached can modify the maximum available memory, using the LRU algorithm, Memcached a single key-value size is limited, a value is only supported 1MB.
MongoDB is suitable for large data storage, relying on operating system VMs to do memory management, eating memory is also more severe, services do not and other services together.

4. Reliability (persistent)

Redis has a persistence mechanism that can periodically persist in-memory data to the hard disk, Redis support (snapshot, AOF), snapshot-dependent persistence, AOF enhanced reliability, and performance impact.
Memcached does not support data persistence, data loss after power outages or reboots, and is typically used for caching to improve performance.
MongoDB has been using the Binlog approach to support persistent reliability from version 1.8.

6. Data consistency (transactional support)

Memcached in concurrent scenarios, using CAS to ensure consistency of REDIS transaction support is weaker, and can only guarantee that each operation in a transaction executes continuously.
MongoDB does not support transactions.

7. Data analysis

MongoDB has built-in data analysis capabilities (MapReduce), others are not supported.

8. Application Scenario

Redis: It is suitable for the system with high requirement of reading and writing efficiency, complicated data processing business and high security requirements; more performance operations and operations with smaller data volumes, Redis uses only single cores, and Memcached can use multicore So on average, Redis has a higher performance than memcached for storing small data on each core.
Memcached: Used to reduce database load in dynamic system, improve performance, 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.


Summarize:

? There is no need to focus too much on performance, as both are already high enough to perform. Because Redis uses only single cores, and memcached can use multicore, the two are compared on average, and Redis has a higher performance than memcached when storing small data on each core. In more than 100k of data, memcached performance is higher than Redis. Although Redis has also recently been optimized for the performance of storing big data, it is slightly less than memcached. Having said so much, the conclusion is that no matter which one you use, the number of requests per second will not be a bottleneck.

? In terms of memory efficiency, memcached memory utilization is higher if simple key-value storage is used. If Redis uses a hash structure to do key-value storage, its memory utilization will be higher than memcached due to its combined compression. Of course, this is related to your application scenario and data characteristics.

? If you have requirements for data persistence and data synchronization, it is recommended that you choose Redis. Because neither of these features is memcached. Choosing Redis is also wise, even if you just want the cached data to be not lost after upgrading or rebooting the system.

? And, of course, you have to talk about your specific application needs in the end. Redis has more data structures and supports richer data operations than memcached. Usually in memcached, you need to get the data to the client to make similar changes and set it back. This greatly increases the number of network IO and the volume of data. In Redis, these complex operations are often as efficient as the general get/set. So, if you need caching to support more complex structures and operations, Redis is a good choice.

Redis, memcached, mongoDB contrast

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.