Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Overview of NoSQL and Memcached, Redis, MongoDB

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Introduction of NoSQL

Non-relational databases (while mysql, oracle, sqlserver are all relational databases)

1. Characteristics

There is no relationship between the data. Expand at will.

Data storage is simple, can be stored in memory, and fast reading and writing speed.

There is no need to build tables and fields. Custom format

two。 classification

a. Key value (Key-Value) database: redis, memcached, riak

Redis/memcached is suitable for storing user information, such as sessions, configuration files, parameters, shopping carts, etc., which is generally linked to ID (key)

b. Document-Oriented-oriented databases: MongoDB, CouchDB, RavenDB

MongoDB stores data as documents, each document is a collection of a series of data items, each data item has a name and a corresponding value, the value can be either simple data types, such as text, strings, numbers and dates, or complex types, such as ordered lists and associated objects. The smallest unit of data storage is the document. The document properties stored in the same table can be different, and the data can be in many forms such as XML, JSON or JSONB.

c. Column storage (Wide Column Store/Column-Family) database: Cassandra, HBase

d. Figure (Graph-Oriented) database: Neo4J, Infinite Graph, OrientDB

II. Introduction to Memcached

Developed by foreign Live Journal teams, the database query results are cached to reduce the number of database visits (writes can not be reduced), so as to improve the performance of dynamic Web sites. The data is stored in memory, and the data disappears when you restart the server.

1. Characteristics

Based on CMARS architecture, the protocol is simple.

Event handling based on libevent

Autonomous memory storage processing (slab allocation)

Data expiration methods: Lazv Expiration and LRU

2. Memcationed flow chart

3. Slab allocation principle

The allocated memory is divided into blocks of various sizes (chunk), and those of the same size are divided into groups, that is, sets of chunk, each set is called slab

The memory allocation of Memcached is in Page, and the default value of page is 1m, which can be specified with the parameter-l at startup.

Slab consists of multiple Page

A Chunk cannot exceed 1m in maximum, that is, a Page

A Slab may have more than one Page

Schematic:

4. Growth factor

Memcached can specify the Growth Factor factor (the growth ratio between Chunk) through the-f parameter at startup. The default is 1.25. You can view the actual different slab status of the specified memcached through memcached-tool.

Command: memcached-tool 127.0.0.1 11211 display

5. Memcached data expiration method

Lazy Expiration:memcached does not monitor whether it expires internally. Instead, it looks at the timestamp of the record during get to check whether the record is out of date. This technique is called lazy expiration. Pros: memcached does not waste CPU time on expiration monitoring

LRU:memcached gives priority to the timed-out record space, and there will be insufficient space for new records to be appended. Search for recently unused records and allocate their space to new records (that is, a mechanism for deleting the least recently used records). From the point of view of the use of cache, this model is ideal.

III. Introduction to Redis

Belongs to the key-value storage system, similar to memcached, but supports data persistence (restart the server, the data still exists)

A. value type:

String, hash, lists (linked list), sets (set), sorted sets (ordered set)

b. File format:

RDB (full data) writes the data in memory to disk and loads it the next time the file is read.

Aof (incremental request) data in memory is sequenced into operation requests, which are used to read files and replay to get data, which is equivalent to the binary log of mysql.

c. Storage method:

Memory storage, disk storage, log files

IV. Introduction to MongoDB

Written by C++ language, it is an open source database system based on distributed file storage and belongs to NoSQL.

In the case of high load, more nodes can be added to ensure server performance.

Designed to provide scalable, high-performance data storage solutions for Web applications

The data is stored as a document, the data structure consists of key-value pairs (key= > value), and the document type is JSON object. Field values can contain other documents, arrays, and document arrays

Compared with relational databases:

SQL description MongoDB description database table table collection collection row record row document document column field field index table joins table join

Primary key primary key primary automatically sets the _ id field as the primary key

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report