2018-5-21 NoSQL, memcached installation

Source: Internet
Author: User
Tags memcached mysql query

21.1 NoSQL Introduction


• What is NoSQL

• Non-relational databases are NoSQL, relational databases represent MySQL

For relational databases, 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

· NoSQL Database Storage principle is very simple (the 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.

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

· NoSQL can outperform relational databases in performance, but it doesn't completely replace relational databases

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


• Common NoSQL databases

· k-v (key-value) :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.

· 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.

• Column Storage Hbase

• Figure neo4j, Infinite graph, Orientdb




21.2 memrcached Introduction


· Memcached is a foreign community website LiveJournal team developed to improve dynamic Web site performance by reducing database access times by caching database query results.

• Official site http://www.memcached.org/

• Data structure is simple (k-v), data stored in memory , restart the system or restart the service, the data is lost, so regularly back up to disk

• Multithreading

• Simple protocol based on C/s architecture

• Libevent-based event handling

• Autonomous memory storage processing (slab allowcation)

• Data expiration methods: Lazy Expiration and LRU


· memcached Data Flow


· Slab allocation

· The principle of Slab allocation

• 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.

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

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


· Growth factor

· 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.

• View the different slab states of the specified memcached instance through the Memcached-tool command, you can see that the size (chunk size) gap of each item is 1.25

• Command: # memcached-tool 127.0.0.1:11211 Display


· memcached How to expire data

1,lazy Expiration

· Memcached internally does not monitor whether the 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.

2,LRU

· 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



Installation

[Email protected] ~]# Rpm-qa libevent

Libevent-2.0.21-4.el7.x86_64

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

(Process slightly)

has been installed:

Memcached.x86_64 0:1.4.15-10.el7_3.1

[Email protected] ~]# systemctl start memcached

[[Email protected] ~]# PS aux |grep memcache

memcach+ 1551 0.0 0.1 325564 1180? SSL 20:53 0:00/usr/bin/memcached-u memcached-p 11211-m 64-c 1024

Root 1558 0.0 0.0 112676 984 pts/0 r+ 20:53 0:00 grep--color=auto memcache

(-u specify user,-p specify port,-m allocates memory,-C max concurrency, parameter can be set at startup)


• There are two ways to change parameters : One to manually specify when starting a service, and two to set in/etc/sysconfig/memcached

[Email protected] ~]# vim/etc/sysconfig/memcached

Port= "11211"

User= "Memcached"

maxconn= "1024"

Cachesize= "64"

Options= "127.0.0.1"


memcached

-U Specify user

-P Specify port

-M specify memcached to allocate memory

-C Maximum Concurrent number

-l Specifies the IP to listen on

-D Background Boot

(usually change allocated memory at most)




21.4 View MEMCACHEDQ Status


• View memcached status There are 3 methods:1,memcached-tool tool; 2,nc command; 3,memstat command


Memcached-tool Tools

[Email protected] ~]# Memcached-tool 127.0.0.1:11211 stats

Get_hits divided by Curr_items to calculate the hit ratio.


NC Command

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

(Process slightly)

has been installed:

Nmap-ncat.x86_64 2:6.40-13.EL7

• Query memcached Status:

[Email protected] ~]# echo Stats | NC 127.0.0.1 11211


memstat: If libmemcached is installed, you can use the command MemStat

[Email protected] ~]# Rpm-qa libmemcached

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

(Process slightly)

has been installed:

Libmemcached.x86_64 0:1.0.16-5.EL7

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


Summary:

[Email protected] ~]# Memcached-tool 127.0.0.1:11211 stats

[Email protected] ~]# echo Stats | NC 127.0.0.1 11211

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


2018-5-21 NoSQL, memcached installation

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.