I. Memcached INTRODUCTION
Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended Speeding up Dynamic Web applications by alleviating database load.
(developed by LiveJournal's Danga Interactive)
#高性能, distributed Cache system
Cache server:
Caching: Cache, no persistent storage function;
Bypass cache # side-Hanging cache
K/V cache, only supports storage streaming data;
Characteristics:
K/V cache: Serializable data only; Storage: k/v (Key:value)
The intelligence half relies on the client (call memcached API Development program), half relies on the service side;
Distributed cache: Distributed cluster with non-communication;
Distributed System Request Routing method: Modulus method (the number of machines to determine which machine to send to),
consistent hashing algorithm (clockwise Hashi);
Algorithm complexity: O (1)
Purge Expired Cache Entries:
Cache exhaustion: LRU
Cache entry Expiration: Lazy cleanup mechanism
#即会定期检查缓存, when the cache fails, it does not clean up, but it has new cache write-ins
Overwrite the old cached content directly
Two. Installation configuration:
Available directly from the CentOS 7 base warehouse:
Port to listen on:
11211/TCP, 11211/UDP
Main program:/usr/bin/memcached
Configuration file:/etc/sysconfig/memcached
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/89/78/wKioL1gUkfPg_QObAAA9N3RpIOo837.png-wh_500x0-wm_3 -wmp_4-s_927051987.png "title=" Clipboard.png "style=" Float:none; "alt=" wkiol1gukfpg_qobaaa9n3rpioo837.png-wh_50 "/ >
Unit File:memcached.service
Management tools: Memcached-tool
Protocol format: memcached protocol
Text Format
binary format
Three. Memcache Command detailed
Detailed protocol Help:/usr/share/doc/memcached-1.4.15/protocol.txt
Command:
Statistics class: Stats, stats items, stats slabs, stats sizes
Storage class: Set, Add, replace, append, prepend
Command format: <command name> <key> <flags> <exptime> <bytes>
Extra Information Expiration Time size
<cas unique> #回车后才能输入值
Key key to find cached values
Flags can include integer parameters for key-value pairs, which the client uses to store additional information about key-value pairs
# 1 is the default
Expiration the length of time (in seconds, 0) that a key-value pair is saved in the cache
Far
Bytes The byte points stored in the cache
Value stored values (always on the second row)
Retrieving classes: Get, delete, INCR/DECR
Empty: Flush_all
Example:
telnet> add KEY <flags> <expiretime> <bytes> \ r
Telnet> Value parameter Usage
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/89/7A/wKiom1gUkfHBKxIaAAAPuoGTe3o781.png-wh_500x0-wm_3 -wmp_4-s_248115492.png "title=" clipboard (1). png "style=" Float:none; "alt=" Wkiom1gukfhbkxiaaaapuogte3o781.png-wh_ "/>
Common options for memcached programs:
-M <num>:use <num> MB memory Max to use for object storage; The
Default is megabytes.
-C <num>:use <num> Max simultaneous connections; The default is 1024.
-U <username>: Runs the process as a specified user;
-L <IP_ADDR>: Listening IP address, default to native all address;
-P <num>: Listening TCP port, the default is Port 11211.
-U <num>:listen on UDP Port <num>, and the default is Port 11211, 0 is off.
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/89/78/wKioL1gUkfLRK0NEAAEYqJnIHBY380.png-wh_500x0-wm_3 -wmp_4-s_1455204639.png "title=" clipboard (2). png "style=" Float:none; "alt=" Wkiol1gukflrk0neaaeyqjnihby380.png-wh_ "/>
-M: When memory is exhausted, the LRU cleanup cache is not executed, but the new cache entry is rejected until there are extra empty
is available;
-F <factor>: growth factor (the size of the memory chunk increases in multiples); default is 1.25;
-T <threads>: The number of threads initiated to respond to user requests;
memcached default No authentication mechanism, can be used for SASL certification;
Sasl:simple Authentication Secure Layer
three. API:
Php-pecl-memcache
Php-pecl-memcached
Python-memcached
Libmemcached
#此工具包中包含多个memcache的命令行管理工具
Libmemcached-devel
Command-line tools:
Memcached-tool Server:port COMMAND
-------------------------------------------------
[Email protected] ~]# RPM-QL libmemcached
/usr/bin/memaslap
/usr/bin/memcapable
/usr/bin/memcat
/usr/bin/memcp
/usr/bin/memdump
/usr/bin/memerror
/usr/bin/memexist
/usr/bin/memflush
/usr/bin/memparse
/usr/bin/memping
/usr/bin/memrm
/usr/bin/memslap
/usr/bin/memstat
/usr/bin/memtouch
--------------------------------------------------
Four. Using Telnet to manage the memcache example
1. Yum Install Telnet
--telnet localhost 11211
Stats
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/89/7A/wKiom1gUkfKh9dgRAAA-6iEV5Kc557.png-wh_500x0-wm_3 -wmp_4-s_3327932587.png "title=" clipboard (3). png "style=" Float:none; "alt=" Wkiom1gukfkh9dgraaa-6iev5kc557.png-wh_ "/>
Five. Nginx support for Memcache
Required modules: Ngx_http_memcached_module
Syntax:memcached_bind address [transparent] | Off
default:-
Context:http, Server, location
#用于绑定 memcache Server
Syntax:memcached_pass address;
default:-
Context:location, if in location
#绑定memcache Cluster
eg
server {
Location/{
Set $memcached _key "$uri? $args";
#将指定的key into Memcache to generate the cache;
Memcached_pass host:11211;
Error_page 404 502 504 = @fallback;
}
Location @fallback {
Proxy_pass Http://backend;
}
}
============================================================
83-high performance, distributed cache Memcache analysis