In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the advantages, disadvantages and differences of Redis and Memcache as well as MongoDb. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Memcache, redis and MongoDB are all non-relational databases. NoSQL is a non-relational database, NoSQL = Not Only SQL. Redis is similar to memcache, but completely different from MongoDB, with little comparability. Let's take a look at the advantages, disadvantages and differences of the three.
Redis
Advantages:
1. Supports multiple data structures, such as string (string), list (two-way linked list), dict (hash table), set (collection), zset (sorting set),
two。 Support persistence operation, aof and rdb data can be persisted to disk, thus data backup or data recovery and other operations, a better means to prevent data loss.
3. Support data replication through Replication, through master-slave mechanism, real-time synchronous data replication, support multi-level replication and incremental replication. Master-slave mechanism is an important means for Redis to carry out HA.
4. Single-thread request, all commands are executed serially, and data consistency does not need to be considered in the case of concurrency.
5. Support pub/sub message subscription mechanism, which can be used for message subscription and notification.
6. Simple transaction requirements are supported, but the industry uses few scenarios and is not mature.
Disadvantages:
1.Redis can only use single thread, and its performance is limited by CPU performance, so the maximum CPU of a single instance can reach 5-6wQPS per second (depending on data structure, data size and server hardware performance, the peak of QPS in daily environment is about 1-2w).
two。 Simple transaction requirements are supported, but the industry uses few scenarios and is immature, which is both an advantage and a disadvantage.
3.Redis consumes more memory on the string type, so you can use dict (hash Table) compressed storage to reduce memory consumption.
Memcache
Advantages:
1.Memcached can take advantage of multi-cores, and the throughput of a single instance is extremely high, reaching hundreds of thousands of QPS (depending on the byte size of key and value and the hardware performance of the server, the peak QPS in daily environment is about 4-6w). Suitable for maximum carrying capacity.
two。 Direct configuration of session handle is supported.
Disadvantages:
1 only supports simple key/value data structures, unlike Redis, which supports rich data types.
two。 Cannot be persisted, data cannot be backed up, it can only be used for cache use, and all data is lost after restart.
3. Data synchronization cannot be performed and data from MC cannot be migrated to another MC instance.
4.Memcached memory allocation uses Slab Allocation mechanism to manage memory. When there is a large difference in value size distribution, the memory utilization will be reduced, and problems such as kicking out will still occur when the utilization rate is low. Users are required to pay attention to value design.
MoMongoDBngoDB
Advantages:
1. The higher the write load, the higher the insertion speed of MongoDB.
two。 Dealing with large-scale single tables, when the data table is too large, you can easily split the table.
3. High availability, setting up Mmurs is not only convenient but also fast, and MongoDB can also realize node (data center) failover quickly, securely and automatically.
4. Fast query, MongoDB supports two-dimensional spatial indexes, such as pipes, so you can quickly and accurately retrieve data from specified locations. MongoDB loads the data from the database into memory as a file map after startup. If there are plenty of memory resources, this will greatly improve the query speed of the database.
5. The explosive growth of unstructured data, the increase in columns may in some cases lock the entire database, or increase the load, resulting in performance degradation, due to MongoDB's weak data structure pattern, adding a new field will not have any impact on the old table, the whole process will be very fast.
Disadvantages:
1. Transactions are not supported.
2.MongoDB takes up too much space.
3.MongoDB does not have mature maintenance tools.
The difference between Redis, Memcache and MongoDB
1. Performance
The performance of the three is relatively high, generally speaking: Memcache is similar to Redis, but higher than MongoDB.
two。 Convenience
The data structure of memcache is single.
Redis is richer, redis is better in terms of data manipulation, and there are fewer network IO times.
Mongodb supports rich data representation, indexing, most similar to relational databases, and supports a wide range of query languages.
3, storage space
Redis has added its own VM feature since version 2.0 to break the physical memory limit; 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 a large amount of data storage, rely on the operating system VM to do memory management, eat memory is also more powerful, services do not be together with other services.
4. Usability
Redis relies on the client to achieve distributed read and write; in master-slave replication, each time the slave node reconnects the master node, it depends on the entire snapshot, and there is no incremental replication. Due to performance and efficiency problems, the single point problem is more complex; automatic sharding is not supported, and it needs to rely on the program to set a consistent hash mechanism. One alternative is to use your own active replication (multiple copies of storage) or incremental replication (which requires your own implementation) instead of redis's own replication mechanism, a tradeoff between consistency and performance.
Memcache itself has no data redundancy mechanism and is not necessary. For fault prevention, we use mature hash or ring algorithm to solve the jitter problem caused by single point of failure.
MongoDB supports master-slave,replicaset (internal paxos election algorithm, automatic fault recovery), auto sharding mechanism, and shields the client from the failover and segmentation mechanism.
5. Reliability.
Redis support (snapshot, AOF): relying on snapshots for persistence, aof enhances reliability while having an impact on performance.
Memcache is not supported and is usually used for caching to improve performance.
MongoDB has adopted binlog since version 1.8 to support the reliability of persistence.
6. Consistency
Memcache uses cas to ensure consistency in concurrent scenarios.
Redis transaction support is weak and can only guarantee the continuous execution of each operation in the transaction.
MongoDB does not support transactions.
7. Data analysis
MongoDB has built-in data analysis function (mapreduce), and the other two are not supported.
8. Application scenario
Redis: more performance operations and operations with small amounts of data.
Memcache: used to reduce database load and improve performance in dynamic systems; do caching to improve performance (suitable for reading more and writing less; for large amounts of data, you can use sharding).
Mongodb: mainly solve the problem of access efficiency of massive data.
The advantages and disadvantages and differences of Redis and Memcache as well as MongoDb are shared here. I hope the above content can be helpful to you and you can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.