The difference between REDIS,MEMCACHED,MONGODB

Source: Internet
Author: User
Tags data structures memcached mongodb support

Redis Advantages of Redis:

Support for multiple data structures, such as String (string), list (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimation) support persistence operations, can be aof and RDB data persisted to disk, So the data backup or data recovery, and other operations, a better way to prevent data loss. Support the data replication through replication, through the master-slave mechanism, can be in real-time synchronous replication of data, support multi-level replication and incremental replication, master-slave mechanism is an important means of Redis ha. Single-threaded requests, all commands are executed serially, and there is no need to consider data consistency issues in the concurrency scenario. Support PUB/SUB Message subscription mechanism, can be used for message subscription and notification. Supports simple transaction 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.

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 keys pattern, a matching operation, is a disaster for redis performance.

Memcached Advantages of memcached:

The memcached can take advantage of multicore advantages, with a very high single-instance throughput of hundreds of thousands of QPS (depending on key, the byte size of value, and server hardware performance, which is around 4-6w in the daily environment). Suitable for maximum carrying capacity. Supports direct configuration for session handle.

limitations of memcached:

Only simple KEY/VALUE data structures are supported, unlike Redis, which supports rich data types.
Cannot be persisted, data cannot be backed up, it can only be used for cache use, and data is lost after reboot.
Data synchronization cannot be performed and data in the MC cannot be migrated to another instance of MC.
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.

MongoDB

MongoDB 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.

MongoDB stores JSON-formatted data.

Suitable for scenarios: event logging, content management or blogging platforms, such as commenting systems.

principle of 1.mongodb persistence

MongoDB and MySQL different, every update of MySQL will be written directly to the hard disk, but MONGO not, as a memory database, data operations will be written to memory, and then persist to the hard disk, then MONGO is how to persist?
When MongoDB starts, it initializes a thread that is constantly looping (unless the app crash) to fetch the data to be persisted from the defer queue for a certain time period and write to the journal (log) and Mongofile (data) of the disk. Of course, because it's not written to disk when the user adds a record, as the MongoDB developer says, it does not cause performance loss because it has seen code discovery, and when the cud operation is logged (record type) are put into the defer queue for delay batch (GROUPCOMMIT) commit write, but believe that the time period parameter is a parameter to be carefully considered, the system is 90 milliseconds, if the value is low, it may cause frequent disk operation, too high will cause system downtime data loss.

2. What is a NoSQL database? What is the difference between NoSQL and RDBMS? Under what circumstances to use and not use NoSQL databases

NoSQL is a non-relational database, NoSQL = not-only SQL.
Relational databases use structured data that NoSQL uses to store data in the form of key-value pairs.
NoSQL databases are a priority when dealing with unstructured/semi-structured big data, when scaling horizontally, and when dealing with dynamically increasing data items.
When considering the maturity of the database, support, analysis and business intelligence, management and professional issues, priority should be given to relational databases.

What is the most basic difference between 3.MySQL and MongoDB?

The difference between a relational database and a non-relational database is that the data storage structure is different.

What is the characteristic of 4.MongoDB?

(1) Document-oriented (2) High performance (3) highly available (4) easy to expand (5) Rich query Language

does 5.MongoDB support stored procedures? How do I use it if I support it?

MongoDB supports stored procedures, which are written by JavaScript and saved in the Db.system.js table.

6. How to understand the Gridfs mechanism in MongoDB, why does MongoDB use Gridfs to store files?

Gridfs is a file specification that stores large files in MongoDB. Gridfs can be used to separate large files into multiple small documents, so that we can effectively save large documents, and solve the problem that the Bson object is limited.

7. Why is MongoDB data file very large?

MongoDB uses a pre-allocated space way to prevent file fragmentation.

8. What happens when you update a document on a block (Chunk) that is being migrated?

The update operation occurs immediately on the old block (Chunk) before the change is replicated to the new shard before the transfer of ownership.

9.MongoDB Index on A:{b,c}, query A:{b,c} and A:{c,b} will use the index?

No, the index is only used on a:{b,c}.

10. What happens if a shard (Shard) stops or is very slow, initiating a query?

If a shard is stopped, the query returns an error unless the query has the "Partial" option set. If a shard responds slowly, MongoDB waits for its response.

the difference between Redis, memcache, and MongoDB

From the following dimensions, the Redis, Memcache, MongoDB are compared,

1. Performance

are relatively high, performance is not a bottleneck for us

In general, the TPS is about the same as Redis and Memcache, more than MongoDB

2, the convenience of the operation

Memcache Data Structure Single

Redis is rich, data manipulation, Redis better, less network IO times

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 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)

Memcache can modify the maximum available memory, using the LRU algorithm

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

4. Availability (single point of issue)

For a single point of problem,

Redis, which relies on clients for distributed reads and writes, and master-slave replication relies on the entire snapshot every time the primary node is reconnected from the node, without incremental replication, due to performance and efficiency issues,

Therefore, the single point problem is more complicated, the automatic sharding is not supported, and the dependent program is required to set the consistent hash mechanism.

An alternative is to use your own proactive replication (multiple storage) instead of Redis's own replication mechanism, or change to incremental replication (you need to implement it yourself), consistency issues and performance tradeoffs

Memcache itself has no data redundancy mechanism, it is not necessary, for fault prevention, relying on mature hash or ring algorithm to solve the single point of failure caused by the jitter problem.

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.

5. Reliability (persistent)

For data persistence and data recovery,

Redis Support (snapshot, AOF): dependent on snapshots for persistence, AOF enhances reliability while impacting performance

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

MongoDB supports persistent reliability from the 1.8 release with the binlog approach

6. Data consistency (transactional support)

Memcache in concurrent scenarios, with CAS to ensure consistency

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

MongoDB does not support transactions

7. Data analysis

MongoDB has built-in data analysis capabilities (MapReduce), others do not support

8. Application Scenario

Redis: More performance operations and calculations with smaller data volumes

Memcache: 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

The difference between REDIS,MEMCACHED,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.