Memcached, Redis, Mongodb

Source: Internet
Author: User
Tags memcached redis redis cluster

Memcached(Memory Cache)

Memcached is a high-performance distributed memory object caching system. By maintaining a unified, huge hash table in memory, it can be used to store data in a variety of formats, including images, videos, files, and the results of database retrieval. The simple thing is to call the data into memory and then read it from memory to reduce the load on the database.

The Memcache workflow is as follows:

    • First check whether the client's request data is in memcached, if so, directly return the request data, no longer do anything to the database;
    • If the requested data is not in memcached, go to the database, the data obtained from the database to the client, while the data cached in the memcached (memcached client is not responsible, need the program explicitly implemented);
    • Keep the "freshness" of the cache, whenever the database changes (for example, if the data has been modified or deleted), to synchronize the update cache information to ensure that the user does not cache the old data;
    • When the allocated memcached memory space is exhausted, the LRU (Least recently used, least recently used) policy is combined with the expiry expiration policy, and the failed data is replaced first, and then replaced with the most recently unused data.
Redis(In-memory database)

Redis is a key-value storage System (in-fabric cache, high-performance Key-value database). Similar to memcached, it supports storing more value types , including string (string), list (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimation). 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 disk or writes the modified operation to the appended record file, and implements the Master-slave(Master-slave) data synchronization backup on this basis.

One of the important features of Redis is that it can implement persistent data , which can be persisted in two ways: using an Rdb snapshot to keep data in-memory written to disk, or using a MySQL-like aof log method to record the log for each update. The former performance is high, but may cause some degree of data loss; the latter is the opposite. Redis supports synchronizing data to multiple slave databases, a feature that is useful for improving read performance.

MongoDB(NoSQL database)

is a product between a relational database and a non-relational database (a database based on Distributed file storage), which is the most versatile and most like relational database in a non-relational database. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.

The advantage of MongoDB is that it can store huge amounts of data and have powerful query functions, so it is not suitable for caching data scenarios.

Redis, Memcache, mongoDB Contrast performance performance is excellent, specific to the details, because Redis only use single core, and memcached can use multicore, so on average every core redis in the storage of small data more than memcached performance. In more than 100k of data, Memcached performance is higher than Redis, although Redis has recently been optimized for the performance of storing big data, but it is slightly inferior to Memcached. In general, the TPS is about the same as Redis and memcache, more than the MongoDB memory space and data volume size

Memcache can modify the maximum available memory, using the LRU algorithm
Redis has added its own VM features after the 2.0 release, breaking the limits of physical memory; You can set the expiration time for key value (similar to memcache); Redis when physical memory runs out, you can swap some long-unused value to disk
MongoDB is suitable for large data storage, depends on operating system VM to do memory management, eat memory is also very bad, service not with other services together

Convenient operation

Memcache data structure is single and only used to cache data
The data types supported by Redis are rich, and Redis is better at data manipulation, and can be manipulated directly on the server side to reduce network IO times and data volume
MongoDB supports rich data expression, index, most similar relational database, support query language is very rich

Reliability (Persistence)

Memcached does not support data persistence, which is usually used to improve performance in caching, and data disappears after power outages or reboots, but its stability is guaranteed.
Redis supports data persistence (snapshots, AOF) and data recovery, allowing single points of failure, but also at the cost of performance.
MongoDB has been using the Binlog approach to support persistent reliability from version 1.8.

Distributed (single point of issue)

Memcache itself does not have the data redundancy mechanism, in fact not necessary; If you want to do, because Memcached does not have built-in distributed functionality, need to do ha, through the magent cache proxy, to prevent a single point of vulnerability.

Memcached's distribution is not implemented on the server side, but is implemented in the client application, which is the node that uses the built-in algorithm to make the target data, as shown in:


Redis supports data persistence (snapshots, AOF) and data recovery, allowing single points of failure, but also at the cost of performance.

2.8 Previous versions: Consistent with memcached, can be implemented either on the client or using proxies, Twitter has developed a proxy twemproxy for Redis and memcached.

3.0 later versions: compared to memcached can only implement distributed storage with clients, Redis builds distributed storage on the server side. Redis cluster is an advanced version of Redis that implements distributed and allows single points of failure, has no central node, has a consistent status of nodes, and features linear scalability. The distributed storage architecture of Redis cluster is given, in which the nodes communicate with the nodes through the binary protocol, and the communication between the node and the client is through the ASCII protocol. On the data placement strategy, Redis cluster divides the numeric field of the entire key into 16,384 hash slots, each of which can store one or more hash slots, which means that the maximum number of nodes currently supported by Redis cluster is 16384.

MongoDB supports Master-slave,replicaset (internal using Paxos election algorithm, automatic fault recovery), auto sharding mechanism, blocking the failover and segmentation mechanism to the client.

Application Scenarios

Memcache: The dynamic system to reduce database load, improve performance, cache, suitable for read less write, Big data volume (such as Renren large query user information, friend information, article information, etc.)
Redis: For systems that require high read and write efficiency, complex data processing services, and high security requirements (such as the count of Sina Weibo and a partial system of Weibo releases, high data security and read/write requirements)
MongoDB: The main solution to the massive data access efficiency problem

Reference: https://www.cnblogs.com/work115/p/5584646.html

Https://www.cnblogs.com/457248499-qq-com/p/7392653.html

Memcached, Redis, 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.