Memcached, Redis and Mongodb differences in storage performance
Memcached
Memcached advantages:
1: Memcached can take advantage of multi-core, single instance throughput is very high, can reach hundreds of thousands of QPS (depending on the key, value byte size and server hardware performance, QPS peak in the daily environment is about 4-6w). Suitable for maximum carrying capacity.
2: Supports direct configuration as session handle.
Limitations of Memcached:
1: Only supports simple key / value data structures. Unlike Redis, it can support rich data types.
It cannot be persisted, data cannot be backed up, it can only be used for cache use, and all data is lost after restart.
Data cannot be synchronized, and data in the MC cannot be migrated to other MC instances.
2: Memcached memory allocation uses the Slab Allocation mechanism to manage memory. When the value size distribution is significantly different, it will cause memory utilization to decrease, and problems such as kick-out will still occur at low utilization. Users need to pay attention to value design.
Redis
Redis advantages:
1: Support a variety of data structures, such as string (string), list (double linked list), dict (hash table), set (set), zset (sorted set), hyperloglog (cardinality estimation)
Supports persistence operations. AOF and RDB data can be persisted to disk to perform operations such as data backup or data recovery. It is a better way to prevent data loss.
2: Supports data replication through Replication. Through the master-slave mechanism, data can be synchronized and replicated in real time. Multi-level replication and incremental replication are supported. The master-slave mechanism is an important means of HA for Redis.
3: Single-threaded request, all commands are executed serially, and data consistency need not be considered in the case of concurrency.
Supports pub / sub message subscription mechanism, which can be used for message subscription and notification.
Supports simple transaction requirements, but the industry has few use cases and is not mature.
Limitations of Redis:
1: Redis can only use a single thread, the performance is limited by the CPU performance, so the single instance CPU can reach a maximum of 5-6wQPS per second (depending on the data structure, data size, and server hardware performance, the QPS peak in the daily environment is about 1 -2w or so).
2: Supports simple transaction requirements, but the industry has few usage scenarios and is immature, both advantages and disadvantages.
3: Redis consumes more memory on the string type. You can use dict (hash table) to compress storage to reduce memory consumption.
4: Mc and Redis are both Key-Value types. They are not suitable for establishing relationships between different data sets, and are not suitable for query searches. For example, the matching operation of redis keys pattern is a disaster for the performance of redis.
mongoDB
mongoDB is a documentary database. First explain the database of the document, that is, it can store xml, json, bson type data.
The data is self-describing and presents a hierarchical tree-like data structure. Redis can use hash to store simple relational data.
mongoDB stores data in json format.
Suitable scenarios: event recording, content management, or blogging platforms, such as comment systems.
1: mongodb persistence principle
mongodb is different from mysql, every update operation of mysql will be directly written to the hard disk, but mongo will not, as a memory database, data operations will be written to memory first, and then will be persisted to the hard disk, then how is mongo persistent How about
When mongodb is started, it specifically initializes a thread to continuously loop (unless the application crashes). It is used to obtain the data to be persisted from the defer queue and write to the journal (log) and mongofile (data) in a certain period of time. ), Of course, because it is not written to disk when the user adds a record, so according to the mongodb developers, it will not cause a loss in performance, because after reading the code, it is found that when the CUD operation is performed, the record (Record type ) Are put into the defer queue for delayed batch commit (groupcommit) submission and writing, but I believe that the time period parameter is a parameter to be carefully considered, the system is 90 milliseconds, if the value is lower, it may cause frequent Disk operations are too high and data will be lost when the system is down.
2: What is a NoSQL database? What is the difference between NoSQL and RDBMS? Under what circumstances is a NoSQL database used and not?
NoSQL is a non-relational database, NoSQL = Not Only SQL.
Relational databases use structured data. NoSQL uses key-value pairs to store data.
When processing unstructured / semi-structured big data; when expanding in the horizontal direction; when responding to dynamically increasing data items at any time, you can give priority to the use of NoSQL databases.
When considering the maturity of the database; support; analysis and business intelligence; management and professional issues, priority should be given to relational databases.
3. What is the most basic difference between MySQL and MongoDB?
The difference between a relational database and a non-relational database is the difference in data storage structure.
4.What are the characteristics of MongoDB?
(1) Document-oriented (2) High performance (3) High availability (4) Easy to expand (5) Rich query language
5. Does MongoDB support stored procedures? If yes, how to use it?
MongoDB supports stored procedures, which are written in javascript and stored 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. Using GridFS can separate large files into multiple small documents for storage, so that we can effectively save large documents, and solve the problem of BSON object limitations.
7. Why is MongoDB's data file large?
MongoDB uses pre-allocated space to prevent file fragmentation.
8. What happens when updating a document on a chunk that is being migrated?
The update operation happens immediately on the old chunk, and then the changes are copied to the new shard before ownership transfer.
9. MongoDB builds an index on A: {B, C}. Will queries A: {B, C} and A: {C, B} use indexes?
No, the index will only be used on A: {B, C}.
10. What happens if a shard stops or is slow?
If a shard is stopped, the query returns an error unless the query has the "Partial" option set. If a shard responds slowly, MongoDB will wait for its response.
Difference between Redis, Memcache and MongoDB
Compare the redis, memcache, and mongoDB from the following dimensions.
1.Performance
Are relatively high, and performance should not be a bottleneck for us
In general, redis and memcache are similar in TPS, which is larger than mongodb
2. Convenience of operation
single memcache data structure
Redis is richer. In terms of data manipulation, redis is better and has fewer network IOs.
mongodb supports rich data expressions, indexes, most similar to relational databases, and a very rich query language
3.The size of the memory space and the amount of data
Redis added its own VM features after version 2.0, breaking the limit of physical memory; you can set an expiration time for key value (similar to memcache)
memcache can modify the maximum available memory, using the LRU algorithm
mongoDB is suitable for storage of large amounts of data. It depends on the operating system VM for memory management. It is also very powerful to eat memory. Do not serve with other services.
4. Availability (single point of problem)
For single points,
Redis, relying on the client to achieve distributed read and write; each time the slave node reconnects to the master node, the master node depends on the entire snapshot during master-slave replication.
Therefore, the single point problem is more complicated; automatic sharding is not supported, and it is necessary to rely on the program to set a consistent hash mechanism.
An alternative is not to use redis's own replication mechanism, but to do the active replication itself (multiple storage), or change to the incremental replication method (need to implement it yourself).
Memcache itself does not have a data redundancy mechanism, nor is it necessary; for fault prevention, a mature hash or ring algorithm is used to solve the problem of jitter caused by a single point of failure.
mongoDB supports master-slave, replicaset (internal use of paxos election algorithm, automatic failure recovery), auto sharding mechanism, shielding the client from failover and sharding mechanism.
5. Reliability (persistent)
For data persistence and data recovery,
Redis support (snapshot, AOF): rely on snapshots for persistence, while aof enhances reliability and affects performance
memcache does not support it, usually used as a cache to improve performance;
MongoDB uses binlog to support persistent reliability since version 1.8
6, data consistency (transaction support)
Memcache uses cas to ensure consistency in concurrent scenarios
Redis transaction support is relatively weak and can only guarantee that each operation in the transaction is performed continuously
mongoDB does not support transactions
Data analysis
mongoDB has built-in data analysis function (mapreduce), other does not support
8.Application scenarios
redis: more performance operations and operations on smaller amounts of data
memcache: used to reduce database load and improve performance in dynamic systems; cache, improve performance (suitable for read more, write less, for larger amounts of data, you can use sharding)
MongoDB: mainly solves the problem of accessing massive data
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.