MySQL High performance memcached (1)

Source: Internet
Author: User

This article will introduce the installation and use of memcached


What is Memcached?
Free & Open Source, High-performance, distributed memory object caching system, generic in nature, and intended for us E in speeding to dynamic Web applications by alleviating database load.
Memcached is a in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database C Alls, API calls, or page rendering.
Memcached is simple yet powerful. Its promotes quick deployment, ease of development, and solves many problems facing large data caches. Its APIs are available for most popular languages.




Why use Memcached?
Benefits of using memcached include:
? Because All information are stored in RAM, the access speed is faster than loading the information
Each time from disk.
? Because the "value" portion of the Key-value pair does not having any data type restrictions, can
Cache data such as complex structures, documents, images, or a mixture of such things.
? If You use the in-memory cache to hold transient information, or as a read-only cache for information
Also stored in a database, the failure of any memcached servers is not critical. For persistent data, you
Can fall back to a alternative lookup method using database queries, and reload the data into RAM
On a different server.
The typical usage environment is to modify your application So, information is read from the cache
Provided by memcached. If the information is not in memcached and then the data was loaded from the
MySQL database and written into the cache so, the requests for the same object benefit from the

Cached data.



Case:
Fotolog, as they themselves point out, is probably the largest site nobody have ever heard of, pulling in + page views t Han even Flickr. Fotolog has Wuyi instances of memcached on servers with 175G in use and 254G available. As a large successful photo-blogging site they has very demanding performance and scaling requirements. To meet those requirements they ' ve developed a sophisticated approach to using memcached the others can learn from and EM Ulate.

Downloads for memcached:
Http://www.memcached.org/files/memcached-1.4.21.tar.gz


In Redhat, the system comes with a memcached, which can be installed using Yum:
Yum Install memcached


You can also download the package for installation, which is explained in detail here.


Basic use:

[[email protected] bin]# memcached-hmemcached 1.4.4-p <num> TCP port number to listen on (default:11211) -U <num> UDP port number to listen on (default:11211, 0 is off)-s <file> UNIX socket path to listen  On (disables network support)-a <mask> access mask for UNIX sockets, in octal (default:0700)-L <ip_addr> interface to listen in (Default:inaddr_any, all addresses)-D run as a daemon-r maximize core file L Imit-u <username> assume identity of <username> (only if run as root)-M <num> max memory to use F or items in megabytes (default:64 MB)-M return error on memory exhausted (rather than removing items)-C <nu  M> Max simultaneous connections (default:1024)-K lock down all paged memory.  Note that there are a limit on how much memory you may lock. Trying to allocate more than this would fail, so is sure you set the LImit correctly for the user, started the daemon with (not for-u <username> user;           Under SH This is do with ' ulimit-s-l num_kb ').-v Verbose (print errors/warnings while in event loop)-VV Very verbose (also print client commands/reponses)-vvv extremely verbose (also print internal state transi  tions)-H print this help and exit-i print memcached and libevent license-p <file> save PID    In <file>, only used with-d option-f <factor> chunk size growth factor (default:1.25)-N <bytes> Minimum space allocated for key+value+flags (default:48)-L Try to use large memory pages (if available). Increasing the memory page size could reduce the number of TLB misses and improve the Performanc E. In order to get large pages from the OS, memcached'll allocate the total item-cache in one Large chunk.-d <char> UsE <char> as the delimiter between key prefixes and IDs. This is used for Per-prefix stats reporting. The default is ":" (colon). If This option is specified, stats collection are turned on automatically; If not and then it is turned on by sending the ' Stats detail on ' command to the SERVER.-T <num> n              Umber of threads to use (Default:4)-R Maximum number of requests per event, limits the number of             Requests process for a given connection to prevent starvation (default:20)-C Disable use of Cas-b Set the backlog queue limit (default:1024)-B Binding protocol-one of ASCII, binary, or auto (def Ault)-I Override the size of each slab page. Adjusts max item size (DEFAULT:1MB, min:1k, max:128m)
Initialize memcached:

Memcached-u root-d-M 512-p 11211-l 192.168.56.12[[email protected] bin]# ps-ef |grep memroot      4382     1  0 02 : A.        00:00:00 memcached-u root-d-M 512-p 11211-l 192.168.56.12
To view the status of the current memcached:

[[email protected] bin]# telnet 192.168.56.12 11211 Trying 192.168.56.12...Connected to 192.168.56.12.Escape Character is ' ^] '. Statsstat pid 4382STAT uptime 7288STAT time 1418893354STAT version 1.4.4STAT pointer_size 64STAT Rusage_ User 0.353946STAT Rusage_system 0.379942STAT curr_connections 5STAT total_connections 8STAT connection_structures 6STAT Cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT get_hits 0STAT get_misses 0STAT delete_misses 0STAT delete_hits 0STAT incr_mis SES 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT auth_cmds 0ST At Auth_errors 0STAT bytes_read 144STAT bytes_written 1732STAT limit_maxbytes 536870912STAT Accepting_conns 1STAT listen_   Disabled_num 0STAT Threads 4STAT conn_yields 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT evictions 0END corresponding parameter explanation: PID Memcache server's process iduptime the number of seconds the server has been running Time Server current UNIX timestamp version memcache pointer_size current operating system pointer size (32-bit system is generally 32bit) rusage Cumulative user Time of the _user process Rusage_system processSystem time Curr_items The number of items currently stored by the server Total_items the total number of items stored since the server was started bytes the number of bytes consumed by the current server store items curr_connections  Number of connections currently open total_connections number of connections that have been opened since the server started connection_structures the number of connection constructs that the server allocates cmd_get get command (GET) Total requests Cmd_set  Set command (Save) total number of requests get_hits total number of hits Get_misses total misses evictions  The number of items deleted for free memory (the space allocated to memcache needs to be removed after the old items to get the space allocated to the new items) bytes_read Total bytes read (request bytes) Bytes_written Total Bytes sent (bytes of result) Limit_maxbytes allocated to Memcache memory size (bytes) threads current thread count




MySQL High performance memcached (1)

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.