NoSQL Introduction, Memrcached Introduction, installing memcached, viewing MEMCACHEDQ status

Source: Internet
Author: User
Tags memcached mysql query

Nosql

What is NoSQL
Non-relational databases are NoSQL, relational databases represent MySQL
For the relational database, it is necessary to store the data in the library, table, row, field, 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 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.
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 Store Hbase
Figure neo4j, Infinite graph, Orientdb

memcached 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/
Simple data structure (K-V), data stored in memory
Multithreading
Simple protocol based on C/s architecture
Libevent-based event handling
Autonomic 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.
The slab is 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.
Viewing the different slab states of a specified memcached instance with the Memcached-tool command, you can see that each item occupies a size (chunk size) gap of 1.25
Command: # memcached-tool 127.0.0.1:11211 Display

memcached How to expire data
The 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.
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.

memcached Installation
Enter to/USR/LOCAL/SRC
Yum install-y memcached libmemcached libevent
Start
Systemctl start memcached
To see if the launch was successful
[Email protected] src]# PS aux|grep memcached
memcach+ 1631 0.3 0.1 325564 1180? SSL 22:28 0:00/usr/bin/memcached-u memcached-p 11211-m 64-c 1024
Root 1654 0.0 0.0 112676 984 pts/0 s+ 22:28 0:00 grep--color=auto memcached

We can also start it in the form of a command line, which can add some parameters, where-m specifies memcached allocation memory-c specifies the maximum number of concurrent-u specifies the user running the Memcached service-L listener Port-D background boot.
For example:/usr/bin/memcached-u memcached-p 11211-m 64-c 1024

Vim/etc/sysconfig/memcached can configure parameters
Port= "11211" (port)
User= "memcached" (user)
Maxconn= "1024" (maximum number of connections)
Cachesize= "64" (memory)
Options= "127.0.0.1" (Listening port)

View memcached Run Status
Memcached-tool 127.0.0.1:11211 Stats
[Email protected] src]# Memcached-tool 127.0.0.1:11211 stats
#127.0.0.1:11211 Field Value
Accepting_conns 1
Auth_cmds 0
Auth_errors 0
Bytes 0
Bytes_read 7
Bytes_written 0
Cas_badval 0
Cas_hits 0
Cas_misses 0
Cmd_flush 0
Cmd_get 0
Cmd_set 0
Cmd_touch 0
Conn_yields 0
Connection_structures 11
Curr_connections 10
Curr_items 0
Decr_hits 0
Decr_misses 0
Delete_hits 0
Delete_misses 0
evicted_unfetched 0
Evictions 0
expired_unfetched 0
Get_hits 0
Get_misses 0
Hash_bytes 524288
Hash_is_expanding 0
Hash_power_level 16
Incr_hits 0
Incr_misses 0
Libevent 2.0.21-stable
Limit_maxbytes 67108864
Listen_disabled_num 0
PID 1879
Pointer_size 64
Reclaimed 0
Reserved_fds 20
Rusage_system 0.057735
Rusage_user 0.003849
Threads 4
Time 1530631114
Total_connections 11
Total_items 0
Touch_hits 0
Touch_misses 0
Uptime 107
Version 1.4.15
Here we need to focus on get-hits and Cmd_get, where cmd_get represents the total get count, Get_hits represents the total hit count of get, hit rate = Get_hits/cmd_get.

We can also use NC commands, first Yum installs
Yum install-y NC
And then through the command
echo Stats |nc 127.0.0.1 11211来 view
The NC command must be combined with IP and port
STAT PID 1879
STAT Uptime 540
STAT Time 1530631547
STAT version 1.4.15
STAT libevent 2.0.21-stable
STAT Pointer_size 64
STAT Rusage_user 0.017037
STAT Rusage_system 0.057735
STAT Curr_connections 10
STAT total_connections 12
STAT Connection_structures 11
STAT Reserved_fds 20
STAT Cmd_get 0
STAT Cmd_set 0
STAT Cmd_flush 0
STAT Cmd_touch 0
STAT Get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT Delete_hits 0
STAT incr_misses 0
STAT Incr_hits 0
STAT decr_misses 0
STAT Decr_hits 0
STAT cas_misses 0
STAT Cas_hits 0
STAT Cas_badval 0
STAT Touch_hits 0
STAT touch_misses 0
STAT Auth_cmds 0
STAT auth_errors 0
STAT Bytes_read 13
STAT Bytes_written 1024
STAT limit_maxbytes 67108864
STAT Accepting_conns 1
STAT Listen_disabled_num 0
STAT Threads 4
STAT Conn_yields 0
STAT Hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT bytes 0
STAT Curr_items 0
STAT Total_items 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT Evictions 0
STAT reclaimed 0
END

If libmemcached is installed, you can use the command MemStat--servers=127.0.0.1:11211 to view the memcached service status
server:127.0.0.1 (11211)
pid:1879
uptime:755
time:1530631762
version:1.4.15
Libevent:2.0.21-stable
Pointer_size:64
rusage_user:0.020084
rusage_system:0.060253
Curr_connections:10
Total_connections:13
Connection_structures:11
Reserved_fds:20
cmd_get:0
cmd_set:0
cmd_flush:0
cmd_touch:0
get_hits:0
get_misses:0
delete_misses:0
delete_hits:0
incr_misses:0
incr_hits:0
decr_misses:0
decr_hits:0
cas_misses:0
cas_hits:0
cas_badval:0
touch_hits:0
touch_misses:0
auth_cmds:0
auth_errors:0
Bytes_read:30
bytes_written:2068
limit_maxbytes:67108864
Accepting_conns:1
listen_disabled_num:0
Threads:4
conn_yields:0
Hash_power_level:16
hash_bytes:524288
hash_is_expanding:0
bytes:0
curr_items:0
total_items:0
expired_unfetched:0
evicted_unfetched:0
evictions:0
reclaimed:0

NoSQL Introduction, Memrcached Introduction, installing memcached, viewing MEMCACHEDQ status

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.