I. The introduction of NoSQL
Non-relational database (MySQL, Oracle, SQL Server are relational databases)
1. Features
No relationship between data, arbitrary expansion
Data storage is simple, can exist in memory, read and write fast
You do not need to build tables, fields. Custom formats
2. Classification
A. Key value (key-value) database :redis, memcached, Riak
Redis/memcached is suitable for storing user information, such as sessions, profiles, parameters, shopping carts, etc., which are generally linked to the ID (key)
B. Document-oriented (document-oriented) database:MongoDB, CouchDB, RavenDB
MongoDB stores data as documents, each of which is a collection of data items, each with a name and corresponding value, which can be a simple data type, such as text, string, number, date, and so on, or complex types, such as ordered tables and associated objects. The smallest unit of data storage is a document, and document properties stored in the same table can be different, and data can be used in many forms, such as XML, JSON, or JSONB.
C. Columnstore (Wide column store/column-family) database:Cassandra, HBase
D. Figure (graph-oriented) database:neo4j, Infinite graph, Orientdb
Ii. introduction of Memcached
The foreign Live journal team developed to improve dynamic Web site performance by caching database query results and reducing the number of accesses to the database (write reduction). Data is present in memory, restarting the server i.e. data disappears
1. Features
Simple protocol based on C/s architecture
Libevent-based event handling
Autonomic memory storage processing (slab allocation)
Data expiration methods: Lazv Expiration and LRU
2. memcationed flowchart
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8F/6A/wKioL1jdx7yiX7nXAAJE4ZWruR8668.png "title=" 1.png "alt=" Wkiol1jdx7yix7nxaaje4zwrur8668.png "/>
3. Slab allocation principle
Divide the allocated memory into blocks of various sizes (chunk), dividing the same dimensions into groups, that is, the chunk collection, each of which is called slab
The memory allocation for memcached is in page, with the page default of 1M, which can be specified at startup by the parameter-l
Slab is made up of multiple page
A chunk maximum cannot exceed 1M, that is, a page
A slab may have multiple page
Schematic diagram:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/8F/6C/wKiom1jdx8-D-uERAAKOh3dD0-A042.png "title=" 3.png "alt=" Wkiom1jdx8-d-ueraakoh3dd0-a042.png "/>
4. Growth factor
Memcached can be specified by the-f parameter at startup to specify the growth factor factor (that is, the growth ratio between chunk), the default is 1.25, the memcached-tool can be used to view the actual memcached state slab
Command:memcached-tool 127.0.0.1:11211 Display
5. Memcached Data Expiration method
Lazy Expiration:memcached internal does not monitor whether the expiration, but the get when the time stamp to view the record, check whether the record is out of date. This technique is called the lazy expiration. Pros: memcached does not consume CPU time on outdated monitoring
LRU: memcached takes precedence over the time-out record space, and there is a situation where additional new record space is not available. Search from records that have not been used recently and allocate their space to new records (that is, the mechanism to delete the least recently used records). From the perspective of cache usage, the model is ideal
Iii. introduction of Redis
belongs to Key-value storage System, similar to memcached, but supports data persistence (restart server, data is still present)
A. Value type:
String, hash, lists (linked list), sets (collection), sorted sets (ordered collection)
B. File format:
The RDB (full data) writes the in-memory data to disk and loads the next time the file is read
AOF (incremental request) The data in memory is ordered into an operation request, used to read the file for replay to get data, equivalent to the MySQL binary log
C. Storage mode:
Memory storage, disk storage, log files
Iv. introduction of MongoDB
Written by the C + + language, a set of open source database systems based on distributed file storage, is a NoSQL
With high load, more nodes can be added to ensure server performance
Designed to deliver scalable, high-performance data storage solutions for Web applications
The data is stored as a document, which consists of a key-value pair (Key=>value) and a document type in a JSON object. Field values can contain other documents, arrays, and document arrays
Comparison with relational databases:
Sql |
Description |
Mongodb |
Description |
Database |
Database |
Database |
Database |
Table |
Table |
Collection |
Collection |
Row |
Record line |
Document |
Document |
Column |
Field |
Field |
Domain |
Index |
Index |
Index |
Index |
Table joins |
Table Connection |
|
|
Primary key |
Primary key |
Primary |
Automatically set the _id field as the primary key |
This article is from "A horse on the Plains" blog, please be sure to keep this source http://huangzp.blog.51cto.com/12434999/1912030
NoSQL and Memcached, Redis, MongoDB overview