This article focuses on some of the things that are nosql, and the difference between the three databases of NoSQL, Memchache, MongoDB, and the ones that are more popular in the series. Here is the reading directory of this article, a NoSQL introduction
1.Nosql Introduction
The difference between the characteristics of 2.Nosql and relational database
Characteristics and differences of 3.REDIS,MEMCACHE,MONGODB
4. Reference Articles
NoSQL IntroductionThe full name of NoSQL is not-only Sql, a concept that has been raised early in the morning, compared to fire in the 09. NoSQL refers to a non-relational database, and we often use relational databases. Like our usual mysql,sqlserver, these databases are typically used to store important information, and there's no problem with normal business. However, with the rapid development of the Internet, the traditional relational database in dealing with ultra-large-scale, ultra-large traffic and high concurrency when the time is inadequate. And just at this time, NoSQL gets to tell the development.
the difference between NoSQL and relational databases1. Storage relational databases are tabular and therefore stored in table rows and columns. They are easily associated with collaborative storage, and extracting data is easy. The NoSQL database, in contrast, is a chunk of the combination. It is usually stored in a dataset, like a document, a key-value pair, or a graph structure.
2. The storage structure relational database is the structure data, the data table has defined the structure (the column definition), the structure describes the data form and the content. This is critical for data modeling, although the predefined structures bring reliability and stability, but it is difficult to modify the data. and NoSQL databases are based on dynamic structures, using and unstructured data. Because NoSQL databases are dynamic structures, it is easy to adapt to changes in data types and structures.
3. Storage of canonical relational database data storage for higher standards, the data is divided into minimal relational tables to avoid duplication and to obtain streamlined space utilization. While the management is clear, data management is a bit cumbersome when a single operation is designed into multiple tables. While NoSQL data is stored in a flat dataset, data can often be duplicated. A single database is rarely separated, but stored as a whole, so that the whole piece of data is easier to read and write
4. Storage extensions This may be the biggest difference between the two, the relational database is scaled up, that is, you want to improve processing power, to use a faster computer. Because data is stored in relational tables, performance bottlenecks for operations can involve multiple tables that need to be overcome by improving computer performance. Although there is a lot of room for expansion, it will eventually reach the upper limit of vertical expansion. The NoSQL database is scale-out, its storage is distributed naturally, and the load can be shared by adding more ordinary database servers to the resource pool.
5. Query mode relational databases manipulate databases through Structured query languages (which is what we typically call SQL). The SQL Support Database curd operation is very powerful and is a standard usage in the industry. NoSQL queries manipulate data in blocks as units, using unstructured query Language (UNQL), which is not standard. The concept of a primary key in a relational database table corresponds to the ID of the document stored in NoSQL. Relational databases use predefined optimizations, such as indexes, to speed up query operations, while NoSQL is simpler and more accurate in data access patterns.
6. Transactional relational databases follow acid rules (Atomicity (atomicity), consistency (consistency), isolation (isolation), persistence (durability)), NoSQL databases Follow the base principle (basic availability (basically availble), soft/Flexible transactions (soft-state), and eventual consistency (eventual consistency). Because of the strong consistency of the data in the relational database, the support for the transaction is very good. Relational databases support fine-grained control of transactional atomicity and are easy to roll back transactions. The NoSQL database is a choice of two items in the CAP (consistency, availability, partition tolerance), because the node-based distributed system is difficult to fully satisfy, so the support for the transaction is not very good, although the transaction can also be used, but not the flash point of NoSQL.
7. Performance-relational database to maintain the consistency of the data paid a great price, poor read and write performance. In the face of high concurrency read and write performance is very poor, the face of massive data when the efficiency is very low. The NoSQL storage format is key-value type, and stored in memory, very easy to store, and the consistency of the data is weak requirements. NoSQL eliminates the need for SQL parsing and improves read and write performance.
8. Licensing mode relational databases typically have SQL Server,mysql,oracle. The mainstream NoSQL database has redis,memcache,mongodb. Most relational databases are paid and expensive and costly, and NoSQL databases are usually open source.
characteristics and differences of Redis,memcache,mongodb
Redis Benefits 1. Supports multiple data structures such as String (string), list (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimation)
2. Support persistent operation, AOF and RDB data can be persisted to disk, so as to carry out data backup or data recovery operations, and better prevent data loss means.
3. 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.
4. Single-threaded requests, all commands are executed serially, and there is no need to consider data consistency issues in the concurrency scenario.
5. Support Pub/sub Message subscription mechanism, can be used for message subscription and notification.
6. Support Simple transaction requirements, but industry usage scenarios are rare and immature. Disadvantage 1. 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).
2. Support simple transaction requirements, but the industry use of the scene is very small, immature, both advantages and disadvantages.
3.Redis consumes more memory on string types, and can use Dict (hash table) to compress storage to reduce memory consumption.
Memcache advantages 1.Memcached can take advantage of multicore advantages, with a single instance throughput of up to hundreds of thousands of QPS (depending on key, the byte size of value, and server hardware performance, the QPS peak in daily environments around 4-6w). Suitable for maximum carrying capacity.
2. Support Direct configuration for session handle. Disadvantage 1 only supports simple KEY/VALUE data structures, unlike Redis, which can support a wide variety of types.
2. Cannot be persisted, data cannot be backed up, can only be used for cache use, and data is lost after reboot.
3. Data synchronization cannot be performed and data in the MC cannot be migrated to other MC instances.
4.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 Advantage 1. Higher write load, MongoDB has a higher insertion speed.
2. Deal with a large scale of a single table, when the data table is too large to easily split the table.
3. High availability, setting up M-s is not only convenient and fast, MongoDB can also implement node (data center) failover quickly, safely and automatically.
4. Fast queries, MongoDB supports two-dimensional spatial indexes, such as pipelines, so that data can be obtained quickly and accurately from a specified location. MongoDB loads the data in the database into memory as a file map after it is started. This will greatly increase the query speed of the database if the memory resources are quite abundant.
5. The explosion of unstructured data increases, the column may lock the entire database in some cases, or increase the load to cause performance degradation, because the weak data structure mode of MongoDB, adding 1 new fields will not have any effect on the old table, the whole process will be very fast. Pros 1. Transactions are not supported.
2.MongoDB occupies too much space.
3.MongoDB does not have a mature maintenance tool.
The difference between Redis, Memcache, and MongoDB 1. Performance of the three are relatively high, overall: Memcache and Redis almost, higher than MongoDB. 2. Convenience memcache data Structure single.
Redis is rich in data manipulation, Redis is better and less network IO times.
MongoDB supports rich data expression, index, most similar relational database, support query language is very rich. 3, storage space 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 (like Memcache).
Memcache can modify the maximum available memory, using the LRU algorithm.
MongoDB is suitable for large data storage, relying on operating system VMs to do memory management, eating memory is also more severe, services do not and other services together. 4. The availability of Redis, relying on the client to achieve distributed read and write; master-slave replication, every time from the node reconnect to the main node to rely on the entire snapshot, no incremental replication, because of performance and efficiency problems, so the single point of the problem is more complex, does not support automatic sharding, need to rely on programs 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 it 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 Redis Support (snapshot, AOF): dependent on snapshots for persistence, AOF enhances reliability while impacting performance.
Memcache is not supported, usually used in cache, to improve performance.
MongoDB has been using the Binlog approach to support persistent reliability from version 1.8. 6. Consistency Memcache in concurrent scenarios, the CAS guarantees consistency.
Redis transaction support is weaker and can only guarantee that each operation in a transaction executes continuously.
MongoDB does not support transactions. 7. Data Analysis MongoDB has built-in data analysis function (MapReduce), the other two does not support. 8. Application Scenario Redis: More performance operations and operations 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.
Reference ArticlesThe difference between Redis, memcache, and MongoDB
Introduction to NoSQL redis,memchche,mongodb differences