Home > Backend Development > PHP Tutorial > Memcached Application and Analysis (1/9)_PHP Tutorial

Memcached Application and Analysis (1/9)_PHP Tutorial

WBOY
Release: 2016-07-20 11:10:10
Original
962 people have browsed it

◎What is Memcached

Before elaborating on this issue, we must first clarify what it "is not". Many people use it as a storage carrier like SharedMemory. Although memcached uses the same "Key=>Value" method to organize data, it is very different from local caches such as shared memory and APC. Memcached is distributed, which means it is not local. It completes the service based on network connection (of course it can also use localhost). It is an application-independent program or daemon process (Daemon mode).

Memcached uses the libevent library to implement network connection services. In theory, it can handle an unlimited number of connections, but it is different from Apache. It is more often oriented towards stable continuous connections, so its actual concurrency capability is There are restrictions. Under conservative circumstances, the maximum number of simultaneous connections for memcached is 200, which is related to the Linux thread capability. This value can be adjusted. For information about libevent, please refer to relevant 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. Normally, each memcached process can manage 2GB of memory space. If If more space is needed, the number of processes can be increased.

◎What occasions is Memcached suitable for?

In many cases, memcached has been abused, which of course inevitably leads to complaints about it. I often see people posting on forums, similar to "how to improve efficiency", and the reply is "use memcached". As for how to use it, where to use it, and what it is used for, there is no sentence. Memcached is not a panacea, nor is it suitable for all situations.

Memcached is a "distributed" memory object caching system, that is to say, those applications that do not need to be "distributed", do not need to be shared, or are simply small enough to have only one server, memcached will not Bringing no benefits, on the contrary, it will slow down the system efficiency, because network connections also require resources, even UNIX local connections. My previous test data showed that memcached local read and write speeds are dozens of times slower than direct PHP memory arrays, while APC and shared memory methods are similar to direct arrays. It can be seen that if it is only a local-level cache, using memcached is very uneconomical.

Memcached is often used as the front-end cache in database tutorials. Because it has a lot less overhead such as SQL parsing and disk operations than a database, and it uses memory to manage data, it can provide better performance than directly reading the database. In large systems, it is very difficult to access the same data. Frequently, memcached can greatly reduce database pressure and improve system execution efficiency. In addition, memcached is often used as a storage medium for data sharing between servers. For example, data that saves the system's single sign-on status in an SSO system can be saved in memcached and shared by multiple applications.

It should be noted that memcached uses memory to manage data, so it is volatile. When the server is restarted or the memcached process is terminated, the data will be lost, so memcached cannot be used to persist data. Many people misunderstand that memcached's performance is very good, even compared to the comparison between memory and hard disk. In fact, memcached's use of memory will not increase the read and write speed by hundreds or thousands. Its actual bottleneck lies in the network connection, which is related to the use of memory. Compared with the disk database system, the advantage is that it is very "light". Because there is no excessive overhead and direct reading and writing methods, it can easily handle a very large amount of data exchange, so there are often two gigabit network bandwidths. They are all fully loaded, and the memcached process itself does not occupy much CPU resources.

1 2 3 4 5 6 7 8 9

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444750.htmlTechArticle◎What is Memcached? Before elaborating on this issue, we must first understand what it is not. Many people use it as a storage medium like SharedMemory, although memcache...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template