Memcached application and analysis (19 ). ◎ What is Memcached? before explaining this problem, we must first understand what it is. Many people regard it as a storage carrier in the form of SharedMemory. although memcache ◎ what is Memcached
Before explaining this question, we must first know what it is "not ". 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.
◎ What is Memcached suitable?
In many cases, memcached has been abused, which of course has to be complained about. I often see people posting on the forum, similar to "how to improve efficiency". The reply is "using memcached". As for how to use and where to use memcached, there is no such thing. Memcached is not omnipotent, and it is not applicable 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 front-end cache of the database tutorial. 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.
1 2 3 4 5 6 7 8 9
Before explaining this problem, we must first understand what it is. Many people use it as a storage carrier in the form of SharedMemory, although memcache...