What is memcached? How to use memcache? _ PHP Tutorial

Source: Internet
Author: User
Tags apc
What is memcached? How to use memcache ?. What is Memcached? Memcached is a distributed memory object cache system developed by danga.com (technical team operating LiveJournal) to reduce database load in a dynamic system. what is Memcached?

Memcached is a distributed memory object cache system developed by danga.com (technical team operating LiveJournal) to reduce database load and improve performance in dynamic systems. Many people use it as a storage carrier in the form of SharedMemory. although memcached uses the same "Key => Value" method to organize data, however, it is very different from local caches such as shared memory and APC. Memcached is distributed, that is, it is not local. It is based on network connections (of course it can also use localhost) to complete the service. it is an application-independent program or Daemon process ).

Memcached uses the libevent library to implement network connection services. In theory, it can handle infinite connections, but unlike Apache, it is more stable and persistent connection oriented, therefore, its actual concurrency capability is limited. Under Conservative circumstances, the maximum number of simultaneous connections of memcached is 200, which is related to the Linux thread capability. this value can be adjusted. For more information about libevent, see related documentation.

Memcached memory usage is also different from APC. APC is based on shared memory and MMAP. memcachd has its own memory allocation algorithm and management method. it has nothing to do with shared memory and has no restrictions on shared memory. generally, each memcached process can manage 2 GB of memory space. if you need more space, you can increase the number of processes.

How to use Memcached?

In many cases, memcached has been abused, so many people may complain about it. I often see people posting on the forum, similar to "how to improve efficiency". The reply is "using memcached". how can I use it? Where is it used? What is it? And so on. Here, the author wants to clarify that memcached is not omnipotent and does not apply to all occasions.

Memcached is a "distributed" memory object cache system. that is to say, applications that do not require "distribution", do not need to be shared, or are simply as small as those with only one server, memcached does not bring any benefits. On the contrary, memcached slows down system efficiency because network connections also require resources, even local UNIX connections.

According to my previous test data, the local read/write speed of memcached is dozens of times slower than the direct PHP memory array, while the APC and shared memory modes are similar to direct arrays. It can be seen that using memcached is not cost-effective if it is only a local cache.

Memcached is often used as the database front-end cache. Because it has much less overhead than the database, such as SQL parsing and disk operations, and uses memory to manage data, it can provide better performance than directly reading the database, in large systems, the same data is frequently accessed. memcached can greatly reduce the database pressure and improve the system execution efficiency. In addition, memcached is often used as a storage medium for data sharing between servers. for example, in the SSO system, data stored in the single-point logon status of the system can be stored in memcached and shared by multiple applications.

It should be noted that memcached uses memory to manage data, so it is easy to lose. when the server is restarted or the memcached process is suspended, data will be lost, so memcached cannot be used to persistently store data. Many people mistakenly understand that memcached has a very good performance, so far as the comparison of memory and hard disk, in fact, memcached does not get hundreds of thousands of read/write speeds to use memory, its actual bottleneck lies in network connection. compared with the database system that uses disks, it has the advantage of being "light" because it does not overhead and has direct read/write methods, it can easily cope with a very large amount of data exchange, so it is often possible that the two Gigabit network bandwidth is full, the memcached process itself does not occupy much CPU resources.

Articles you may be interested in
  • PHP reports Fatal error Allowed memory size of... how should we solve the problem of insufficient memory?
  • Install and configure memcache in windows
  • What does body mean? "> html in css> body?
  • Php calculates the number of weeks in a year or January.
  • MySQL replace function replacement string statement usage
  • Performance Comparison of using in_array () foreach array_search () to find whether an array contains
  • Mysql database cache function analysis, debugging, and Performance Summary
  • PHP string escape functions (addslashes, stripslashes)

Why? Memcached is a distributed memory object cache system developed by danga.com (technical team operating LiveJournal) to reduce database load in a dynamic system...

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.