Redis, Memcache, MongoDb advantages and differences

to sum up:

Redis memcached What are the advantages compared to?

 

All values (1) memcached are simple strings, redis as its replacement, support richer data types

(2) redis is much faster than memcached

(3) redis can persistent data

(4) Redis supports the backup data, i.e., data backup master-slave mode .

(5) using a different underlying model

Application protocol for communication between them and between the underlying implementations of the client are not the same.

Redis VM build their own direct mechanism, because most of the system call system function, it will waste some time to move and requests.

  

(6) value Size: Redis can be up to 1GB, while memcache only 1MB

 

  

Redis

advantage

1. To support a variety of data structures, such as a string (string), List (doubly linked list), dict (hash table), SET (set), zset (ordered set), hyperloglog (base estimated)

2. Support persistence operations, and can be aof rdb data persistence to disk, data backup or data recovery operations, better means of preventing data loss.

3. Support for data replication via Replication,, can be synchronized copy data in real time via master-slave mechanism to support multi-level replication and incremental replication, master-slave mechanism is an important means to carry out Redis HA.

4. threaded request, all commands executed serially without requiring concurrent the data consistency problem.

5. Support pub / sub messages subscribe mechanism, it can be used for the notification message subscription.

6. Support simple transaction needs, but rarely used in the industry scene, is not mature.

Shortcoming

1.Redis can only use single-threaded, performance is limited by CPU performance, it was the highest single-instance CPU may reach 5-6wQPS per second (depending on the data structure, data size and server hardware performance, everyday environment QPS peak of about 1 -2w around).

2. Support simple transaction needs, but rarely used in the industry scene, not mature, both advantage and a disadvantage.

3.Redis on the string type will consume more memory, may be used dict (hash table) stores compressed to reduce memory consumption.

 

 

Memcache

advantage

1.Memcached can use the advantages of multi-core, high throughput single instance, can reach hundreds of thousands of QPS (depending on the key, value byte size and server hardware performance, everyday environment QPS peak in about 4-6w). Apply to the maximum extent carry amount.

2. Support directly configured session handle.

Shortcoming

It supports a simple key / value data structure can not support rich Redis data types.

2. not be persistent, backup data can not only use for caching, and restart all the data is lost.

3. Failure to data synchronization, data can not migrate to other MC in MC instances.

4.Memcached memory allocation using Slab Allocation mechanism of memory management, value size distribution differs considerably between cause reduced memory utilization, and cause other issues are still kicked out when utilization is low. Users need to pay attention to the design value.

 

 

MongoDB

advantage

1. The higher the write load, MongoDB has a higher insertion rate.

2. Process the great size of a single table, when the data table is too big when you can easily partition table.

3. high availability, set up MS not only convenient and fast, MongoDB can also be fast, secure and automated implementation node (data center) failover.

4. Fast query, MongoDB supports a two-dimensional spatial index, such as pipes, so you can quickly and accurately obtain data from the specified location. MongoDB data in the database will start after the way the document is loaded into memory mapped. If memory is quite rich, it would greatly improve query speed of the database.

The explosive growth of unstructured data, locking the entire database columns may increase in some cases, or increasing the load resulting in performance degradation, due to the weak data structure MongoDB, and add a new field will not have any impact on the old table The whole process will be very fast.

Shortcoming

1. does not support transactions.

2.MongoDB space is too large.

3.MongoDB no sophisticated maintenance tools.

 

 

Difference Redis, Memcache and the MongoDB

1. Performance

Three are high performance, in general: Memcache and Redis almost, than MongoDB.

2. Convenience

Memcache single data structure.

redis richer, data manipulation aspects, redis better, a smaller number of network IO.

mongodb supports rich expression data, index, similar to most relational database query language supported by very rich.

3, storage space

After redis version 2.0 adds VM own characteristics, to break out of physical memory; you can set the expiration time for the key value (similar memcache).

memcache may modify the maximum available memory using an LRU algorithm.

mongoDB suitable for large volume data storage , depending on the operating system memory management VM to do, eat memory is also more powerful, do not service and other services together.

 

4. Availability

Redis, rely on the client to implement a distributed read and write; master copy from each node from the master node must rely reconnected entire snapshot, no incremental replication, due to the performance and efficiency, the problem is more complicated single point; not It supports automatic sharding, need to rely on the program to set a consistent hash mechanism. An alternative is without redis own replication mechanisms, using their own active replication (multiple storage), or change the way of incremental copies (needs its own implementation), consistency and performance trade-offs.

 

Memcache does not have data redundancy, it is not necessary; for failure prevention, use or cyclic dependency mature hash algorithm to solve the jitter problem caused by a single point of failure.

 

mongoDB support master-slave, replicaset (internal use paxos election algorithm, automatic failover), auto sharding mechanism to shield the client failover and segmentation mechanism.

 

5. Reliability

redis support (snapshots, AOF): dependent snapshot persistence, aof the same time enhancing the reliability, have an impact on performance.

memcache does not support, usually done in the cache to improve performance.

MongoDB version 1.8 from the start binlog way to support the use of persistent reliability.

 

6. Consistency

Memcache in concurrency scenarios, with cas ensure consistency.

redis transaction support is relatively weak, only to ensure that each successive execution of operations in the transaction.

mongoDB does not support transactions.

 

7. Data Analysis

mongoDB built-in data analysis functionality (mapreduce), the other two do not.

 

8. scenarios

redis: a smaller amount of data and operate more performance computing.

memcache: system for reducing the dynamic load on the database, to improve performance; as cache to improve performance (less suitable for reading and writing, to a greater amount of data can be used sharding).

MongoDB: mainly to solve the problem of massive data access efficiency.

Published 55 original articles · won praise 43 · views 70000 +

Guess you like

Origin blog.csdn.net/qq_21137441/article/details/100940764