MySQL, Redis, MongoDB, Memcached contrast

Copyright: https://blog.csdn.net/zhydream77/article/details/85275781

table of Contents

 

characteristic:

Features:

Usage scenarios :

 


characteristic:

mysql (relational database)

Is mainly used to store persistent data , the hard disk, the read data is stored slow . mysql persistent storage as relational databases, relatively weak areas that each request to access the database, there are I / O operation is repeated frequent access to the database. mysql data stored to the hard drive for persistence, powerful, but slow speed.

First: spend a lot of time on repeated database link, resulting in operating efficiency is too slow;

Second: repeated access to the database will result in the database load is too high, then the time caching concept on derivative out. Cache is a data exchange buffer (cache), when the browser execution request will first look in the cache, if present, will get; otherwise access the database. Benefit of caching is to read fast.

 

Redis (memory database)

  It is a key-value storage system (the distributed cache, key-value high-performance database). It supports the stored value relatively more types, including string (string), List (list), SET (set), zset (sorted set - ordered set) and hash (hash type). These data types are supported push / pop, add / remove and on the intersection and union, and difference richer operation, and these operations are atomic. On this basis, Redis supports a variety of different ways of sorting. In order to ensure efficiency, data is cached in memory. redis will periodically update the data written to disk or to modify the operation of writing additional log file, and on this basis realize the master-slave (master and slave) synchronization.

 

MongoDB (NoSQL database)

   Is a product between (between relational databases and non-relational database based on a distributed file storage database ), non-relational database among the most feature-rich, like most relational databases. He supported data structure is very loose, so you can store more complex data types. Mongo biggest feature is the query language supported by his very powerful, its syntax is somewhat similar to the object-oriented query language, most of the functionality can be achieved almost single-table queries similar to a relational database, but also support for data indexing.

Memcached (Memory Cache)

  It is a high-performance distributed memory object caching system , for dynamic Web applications to reduce database load. It is by the number of cached in memory. In order to speed up file access speed and provide multiple users, you need to establish a management memory for caching data in memory to reduce the number of updates and ensure data disk read and write, because of the need to use cache buffer.

 

 

Features:


MySQL 1-1:
1. Use c and c ++ to write and use a variety of compilers tested to ensure source code portability
2. support multiple operating systems
3. The API provides a variety of programming languages
4. Support multi-threaded, CPU resources, make full use of
optimized SQL query algorithm, effectively improve query speed
5. To provide multi-language support, common coding such as: GB2312, BIG5, UTF8
6. provide TCP / IP, ODBC and JDBC database connectivity and other way to
provide for management, inspection and management tools to optimize database operations
7. large databases. Can handle tens of millions of records have large databases
8. Support multiple storage engines
9. MySQL software uses a dual licensing policy, divided communities and commercial versions, due to their small size, high speed, low cost of ownership, in particular, this feature is open source, development of small and medium websites have chosen MySQL as the site database
10. MySQL data using standard SQL language form
11. Mysql can be customized, under a GPL license, you can modify the source code to develop their own MySQL system
12. the function of the online DDL changes
13. copy global transaction identifier
14. the copy machine without collapse from
copying machine 15 from a multithreaded

 


1-2 Redis:.
Persistence 1. Redis support of data, data in memory can be saved to disk, reboot to load when you can be reused.
2. Redis not only support simple key-value data types, while also providing list, set, stored set, hash and other data structures.
3. Redis support backup data, i.e., data backup master-slave mode,
high performance 4. - Redis can be read speed of 110,000 times / s, write speed is 81000 times / S
5. The rich data types supported -Redis binary cases Strings, Lists, Hashes, Setes and Ordered Sets the data type of the operation.
6. atom - Redis all operations are atomic, while performing atomic Redis supports full and after several operations.
7. The feature-rich - Redis also supports publish / subscribe, notification, key expiration and so on characteristics. 

8. supports a variety of data structures, such as a string (string), List (doubly linked list), dict (hash table), SET (set), zset (ordered set), hyperloglog (base estimate);
9. Support persistence operations , and can be aof rdb data persistence to disk, data backup or data recovery operations, means better prevent data loss;
10. support for data replication via replication,, can be real-time data via master-slave mechanism synchronous replication, multi-level replication and incremental replication, master-slave mechanism is an important means of Redis carried HA;
11 single-threaded requests, all commands executed serially, concurrent data consistency without the need to consider the issue;
12. support pub / sub messaging subscribe mechanism, it can be used for subscriptions and message notification;
13. support simple transaction needs, but rarely used in the industry scene, is not mature.

14.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);

15. support simple transaction needs, but rarely used in the industry scene, not mature, both advantage and a disadvantage;

16. Support (snapshots, AOF): dependent snapshot persistence, AOF enhanced reliability at the same time, have an impact on performance;

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

  18.MC and Redis Key-Value types are not suitable for building relationships between different sets of data, not suitable for query search. Redis this example the keys pattern matching operation, performance is redis disaster;

 19.Redis after version 2.0 adds VM own characteristics, to break out of physical memory; you can set the expiration time (similar memcache) on the key value;

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


MongoDB 1-3:.
1. free mode: You can store different structure of the document in the same database
2. The set-oriented storage: a form suitable for storage JSON-style documents
3. Complete indexing support for any property index
4 Reproduction and high availability: support data replication between servers, the main support - are copied from each other between the patterns and the server. The main purpose is to provide redundant replication and automatic failover
5. Automatic fragmented: the level of support database cluster, can dynamically add additional machine
6. rich query: support a rich query expressions, query instruction form using JSON amount mark can easily query object and an array of built-in document
7. Quick-place update: query optimizer analyzes the query expression, and generate an efficient query plan
8. efficient way of traditional storage: support for binary data and large object

9. 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;

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

11. supports master-slave, replicaset (internal use paxos election algorithm, automatic failover), auto sharding mechanism, the client and the failover shield slicing mechanism;

12. From the start version 1.8 supports persistent manner using binlog reliability;

13.MongoDB does not support transactions;

14.MongoDB built-in data analysis functionality (mapreduce), others do not support

15. From the 1.8 version began to use binlog way to support persistence of reliability;

 

1.4 Memcached

  1. You can use the advantages of multi-core, high throughput single instance, you 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.

        3. supports only simple key / value data structure can not support rich Redis data types;
  4 can not persist, the backup data can not only be used for caching, and restart after all data is lost;
  5. Unable ; data synchronization, data can not migrate to other MC in MC instances
  still occur 6. Slab allocation memory allocation using memory management mechanism, value size distribution differs considerably between cause reduced memory utilization, and lead to low utilization kicked out of other issues. Users need to pay attention to the design value.

  7.Memcached may modify the maximum available memory using an LRU algorithm.

 

scenes to be used


Use different scenarios: 
MongoDB scenarios:
① site data: for real-time insert, update and query, and have needed to replicate and highly scalable real-time data storage site;
② cache: Due to high performance, also suitable as information ; infrastructure caching layer, after a system restart, build persistent cache to avoid overloading the underlying data source
may be time ③ large size, low-value data is the best choice for MongoDB, using some traditional relational database to store data expensive, before a lot of programmers tend to choose again the traditional file storage
④ highly scalable scene, is a very tens or hundreds of servers for database
storage objects and ⑤ for json data, MongoDB data format of bson document format is ideal for storage and query.


mysql scenarios:
① transactional system height. Such as banking or accounting system, traditional relational database is still more practical applications that require a large number of atomic complex transaction
② traditional business intelligence applications , will generate highly optimized for BI query database-specific issues, for such application, data warehouse may be a more appropriate choice

The main problem to solve massive data access efficiency.

Redis scenarios:
in memory 1. When all of the data used for the cache -redis
2. alternative to traditional database in certain scenarios - such as Application of social class
3. In larger systems, a clever the realization of some specific features: the session sharing, shopping cart

4. For reading and writing efficiency requirements are high, complex data processing operations and require a higher security system (e.g. Xinlang counting micro-Bo and parts of the system, data security, are required to read and write high) .

Memcached scenarios: 

 1. Dynamic system to reduce the database load, improve performance; as cache for read more write less, a large amount of data situation (such as a large number of inquiries for all network user information, friend information, articles, information, etc.);

 2. A 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).

 

 

 

Guess you like

Origin blog.csdn.net/zhydream77/article/details/85275781