Memcache Related Knowledge points summary
1) What is Memcahe?
Memcache is an open-source, high-performance and highly concurrent pure memory cache service software, c/s architecture
2) The role of Memcache
Memcache through the pre-planned memory space, temporarily cache the database data, reduce the business to the database directly high concurrent access to improve database access performance, speed up the ability of Web site cluster dynamic application services
3) Common cache software
A. Expires Web configuration browser-side cache, static pictures, JS, CSS, HTML, etc.
B. Memcache pure memory type, data in back-end database, blog post, user information, etc.
C. memcached memory plus disk, Sina utilize MEMCACHE+BDB
D. RDIs memory plus disk, persistent storage
4) Memcache Total application scenario in Enterprise Architecture
A. Full cache (static cache), such as product classification information in the site pure static content
B. Hotspot cache (with high-frequency access to the front-end Web cache and occasional updates with the database)
C. shared storage as a cluster seesion session
5) memcache distributed cluster
Memcache cluster and Web cluster are not the same, all memecache data sum <= database sum
650) this.width=650; "title=" 1470720151297530.png "alt=" Memcache.png "src=" http://www.lichengbing.cn/ueditor/php/ Upload/image/20160809/1470720151297530.png "/>
A. Terminal implementation: The program loads the IP list of all MC by hashing the key (consistent hash)
As an example, suppose there are 3 clients 1, 2, 3, 3 memcached A, B, C:
Client 1 wants to store the data "Barbaz" with Key "Foo". Client 1 first refers to the node list (A, B, C) and calculates the hash value of key "foo", assuming memcached B is selected. Then, Client 1 directly connect to memcached B, and the data "Barbaz" is stored through key "foo". Client 2 uses the same clients library (which means phase one is the same as the hashing algorithm) and also has the same memcached list (A, B, C).
So, after the same hash calculation (phase one), Client 2 calculates the key "foo" on memcached B, and then it requests memcached B directly to get the data "Barbaz"
B. Load balancing: By hashing the key
6) Principle of memcache memory management mechanism
A.MC early memory management mechanism for MALLOC,MALLOC easy to generate memory fragmentation, resulting in overall system performance degradation
B. The slab mechanism is now used to manage and allocate memory
C.memcache memory is allocated in advance to several slab of size 1M, and then a small object is populated chunk for each slab to cache the real data
D. Synthesis of chunk groups of the same size slab CALSS group, avoiding a large number of repetitive initialization and cleanup, can be reused
7) memcache Delete mechanism
A. Do not actively detect whether the item object is out of date, but rather check whether the item object expires and should be deleted (lazy Delete object mechanism) at get
B. When the object is deleted, it is generally not an anti-memory space, but rather as a tag delete, put the pointer into the slot recycling slots, the next time the allocation of direct use
C. When the memory space is full, the least recently used item object is deleted according to the LRU algorithm
Memadmin Show Memcache Status
1) memadmin
Memadmin is an open source, visual memcached management and monitoring tool
: http://www.junopen.com/memadmin/
2) Deployment
[[email protected] www]# tar xf memadmin-1.0.12.tar.gz[[email protected] Total dosage of Www]# cd memadmin[[email protected] memadmin]# ll 36drwxrwxrwx. 2 Root root 4096 6 Month 19 2013 apps-rwxrwxrwx. 1 root root 1214 6 Month 19 2013 config.phpdrwxrwxrwx. 2 root root 4096 6 Month 19 2013 imagesdrwxrwxrwx. 6 root root 4096 6 Month 19 2013 include-rwxrwxrwx. 1 root root 184 6 Month 19 2013 index.phpdrwxrwxrwx. 2 root root 4096 6 Month 19 2013 Langs-rwxrwxrwx. 1 root root 1489 6 Month 19 2013 License.txt-rwxrwxrwx. 1 root root 1118 6 Month 19 2013 Readme.txtdrwxrwxrwx. 2 root root 4096&nbsP;6 Month 19 2013 views
3) login, initial account and password are admin
650) this.width=650; "title=" 1470722364217000.png "alt=" Blob.png "src=" http://www.lichengbing.cn/ueditor/php/ Upload/image/20160809/1470722364217000.png "/>
4) Add Memcache host 650) this.width=650; "title=" 1470722513159578.png "alt=" blob.png "src="/HTTP/ Www.lichengbing.cn/ueditor/php/upload/image/20160809/1470722513159578.png "/>
5) View various memcache statistics or setup Information
650) this.width=650; "title=" 1470723768526960.png "alt=" Blob.png "src=" http://www.lichengbing.cn/ueditor/php/ Upload/image/20160809/1470723768526960.png "/>
6) Monitor Hit
650) this.width=650; "title=" 1470723858386002.png "alt=" Blob.png "src=" http://www.lichengbing.cn/ueditor/php/ Upload/image/20160809/1470723858386002.png "/>
Monitor memcache status script implementation
#!/bin/sh#ip=$1#port=$2check_mem () { printf "set key1 0 0 4\r\ ntest\r\n "|nc $1 $2 if [ ' printf " get key1\r\n "|nc $ 1 $2|wc -l ' -gt 1 ];then echo ' memcache $1 $2 ok ... " hit= ' printf " stats\r\n "|nc $1 $2|awk ' nr==14 {print $3} ' miss= ' printf ' stats\r\n "|nc $1 $2|awk ' nr==15 {print $3} ' echo "the hit rate is ' echo " ${hit} ${miss} "|awk ' {print $1/($1+$2) *100} '% ' else echo "Memcache $1 $2 error ..." Fi}main () { [ $# -ne 2 ]&&echo "usage:$0 memcacheip Memcacheport "&&exit 1 check_mem $1 $2}main $1 $2 [[email protected] shell]# sh shell_14.sh 10.0.0.105 11211storedmemcache 10.0.0.105 11211 ok ... the hit rate is 92.1875%[[email protected] shell]# sh shell_14.sh 10.0.0.105 11212memcache 10.0.0.105 11212 error ...
Memadmin PHP display Memcahe status information