21.2 memcached Introduction; 21.2 memcached introduction; 21.3 installation memcached

Source: Internet
Author: User
Tags memcached mysql query

21.2 memcached Introduction

What is NoSQL?

1. Non-relational database is NoSQL, relational database represents MySQL

2. For a relational database, it is necessary to store the data in libraries, tables, rows, fields, query the time according to the conditions of a line to match, when the equivalent is very large time and resources, especially the data needs to be retrieved from the disk

3. The NoSQL database storage principle is very simple (typical data type is k-v), there is no complex chain of relationships, such as MySQL query, you need to find the corresponding library, table (usually multiple tables) and fields.

4. NoSQL data can be stored in memory with very fast query speed

5. NoSQL can outperform relational databases in performance, but it does not completely replace relational databases

6. NoSQL because there is no complex data structure, the extension is very easy, support distributed

Common NoSQL databases:

1. K-v form: memcached, Redis is suitable for storing user information, such as session, configuration file, parameters, shopping cart and so on. This information is usually linked to the ID (key), which is a good choice for a key-value database.

2. Document database: MongoDB stores the data as a document. Each document is a collection of a series of data items. Each data item has a name and corresponding value, which can be a simple data type, such as a string, a number, a date, and so on, or a complex type, such as a sequence table and an associated object. The smallest unit of data storage is a document, and document properties stored in the same table can be different, and data can be stored in many forms, such as XML, JSON, or JSONB.

3. Columnstore Hbase

4. Figure neo4j, Infinite graph, Orientdb

21.2 memcached Introduction

memcached Introduction:

1. Memcached was developed by the LiveJournal team of foreign community websites to improve the performance of dynamic Web sites by reducing database access times by caching database query results.

2. Official Site http://www.memcached.org/

3. Simple data structure (K-V), data stored in memory

4. Multithreading

5. Based on C/S architecture, the protocol is simple

6. Libevent-based event handling

7. Self-memory storage processing (slab allowcation)

8. Data expiration mode: Lazy Expiration and LRU

memcached Data Flow:

Slab allocation:

1. The principle of Slab allocation

2. Divide the allocated memory into blocks of various sizes (chunk) and divide the same size blocks into groups (chunk collections), each chunk collection is called slab.

3. memcached memory allocation is in page, the page default value is 1M, can be specified at startup by the-I parameter.

4. Slab is made up of multiple page, and the page is cut into multiple chunk by the specified size.

Slab allocation:

Growth factor:

1. memcached can specify the growth factor factor at startup by using the-f option. This value controls the difference in chunk size. The default value is 1.25.

2. Use the Memcached-tool command to view the different slab states of the specified memcached instance, and you can see that each item occupies a size (chunk size) gap of 1.25

3. Command: # memcached-tool 127.0.0.1:11211 Display

Memcached Data Expiration Method:

1. Lazy Expiration

2. Memcached internal does not monitor whether a record is out of date, but instead looks at the timestamp of the record at get and checks whether the record is out of date. This technique is called lazy (lazy) expiration. As a result, memcached does not consume CPU time on outdated monitoring.

3. LRU

4. Memcached takes precedence over the space of a record that has timed out, but even so, there is a lack of space when appending a new record, and a space is allocated using the least recently used (LRU) mechanism. As the name implies, this is the mechanism for deleting "least recently used" records. Therefore, when there is insufficient memory space (when a new space cannot be obtained from the Slab Class), it is searched from records that have not been used recently, and its space is allocated to the new record. From a practical point of view of caching, the model is ideal.

21.3 Installing memcached

1. Find the memcached installation package:

[email protected] ~]# Yum List |grep memcache

2. install memcached

[[email protected] ~]# yum install-y memcached

3. start memcached

[email protected] ~]# systemctl Start memcached

4. View The listening port :

[email protected] ~]# NETSTAT-LNTP

5. Change the memcached configuration file:

[email protected] ~]# vi/etc/sysconfig/ memcached

. For example, with the listening IP, you can change the options= "" to Options= "127.0.0.1"

6. view memcached Help:

[email protected] ~]# memcached-h

7.

. - m specify memcached to allocate memory

. - c Specifies the maximum number of concurrent

. - u Specifies the user running the memcached service

21.4 View memcached Status

1. view memcached service Status:

[email protected] ~]# Memcached-tool 127.0.0.1 : 11211 Stats

Items of concern:

Curr_items

Get_hits

2. install the NC command:

[[email protected] ~]# Yum install-y Span style= "font-family: Microsoft Jacob Black,"microsoft yahei"; font-size:18px; Color:rgb (24, 78, 135); Font-weight:bold; " >NC

with The CN command memcached Service Status:

[email protected] ~]# echo Stats |nc 127.0.0.1 11211

Items of concern:

Curr_items

Get_hits

3. Install libmemcached :

[email protected] ~]# Yum install-y libmemcached

View memcached Service Status:

[email protected] ~]# MemStat--servers= 127.0.0.1 : 11211

Items of concern:

Curr_items

Get_hits

21.2 memcached Introduction; 21.2 memcached introduction; 21.3 installation memcached

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.