A detailed introduction to the operating principle of Memcached [Summary]
This article mainly introduces you to the working principle of Memcached in detail. You can also refer to Memcached Video Tutorial or Memcached Manual.
1. Introduction:
Memcache is a high-performance distributed memory object cache system. By maintaining a unified huge hash table in the memory, it can be used to store various Data in various formats, including images, videos, files, and database search results, etc. Simply put, the data is called into the memory and then read from the memory, thus greatly improving the reading speed. Memcached runs in one or more servers as a daemon and will receive client connections and operations at any time.
2. Features:
1. There is no limit to the amount of item data that can be saved in Memcached, as long as there is enough memory.
2. The maximum memory used by a single Memcached process is 2G. To use more memory, you can open multiple Memcached processes on multiple ports
3. The maximum data expiration time of 30 days is set to permanent It will also expire at this time, constant REALTIME_MAXDELTA
4. The maximum key length is 250 bytes, and it cannot be stored if it is larger than this length. The constant KEY_MAX_LENGTH 250 controls
5. The maximum data for a single item is 1MB, and data exceeding 1MB will not be stored. , controlled by constant POWER_BLOCK 1048576,
6. It is the default slab size
7. The maximum number of simultaneous connections is 200, passed
Controlled by freetotal in conn_init(), the maximum number of soft connections is 1024, through settings.maxconns=1024
Control the parameters related to space occupation: settings.factor=1.25, settings.chunk_size=48,
Affects the slab's data occupancy and stepping method
8.memcached is a non-blocking socket communication service based on the libevent library. Due to non-blocking communication, the memory reading and writing speed is very fast.
9.memcached is divided into server and client. Multiple servers and clients can be configured. It is widely used in distributed services.
10.memcached is very effective as a small-scale data distribution platform.
11.memcached has a one-to-one correspondence between key and value. The default key cannot exceed 128 characters. Section, the default size of value is 1M, which is one slab. If you want to store a value of 2M (continuous), you cannot use two slabs, because the two slabs are not consecutive and cannot be stored in the memory. For storage, it is necessary to modify the size of slabs. When multiple keys and values are stored, even if the slabs are not fully used, other data will not be stored.
12. Put in data of low value, otherwise if the server goes down, all the data will be lost
3. Applicable occasions
1. Distributed applications. Since memcached itself is based on a distributed system, it is especially suitable for large distributed systems.
2. Database front-end cache. Databases are often the bottleneck of website systems. Large concurrent access to the database often causes website memory to overflow. Of course we can also use Hibernate's caching mechanism. However, memcached is based on distribution and can be independent of the website application itself, so it is more suitable for large websites to split applications.
3. Data sharing between servers. For example, we split the login system and query system of the website into two applications, place them on different servers, and cluster them. Then after the user logs in, how does the login information synchronize from the login system server to the query system server? Woolen cloth? At this time, we can use memcached. The login system caches the login information, and the query system can obtain the login information, just like obtaining local information.
4. Inapplicable occasions
Memcached will not bring any benefits to applications that do not require "distribution", do not require sharing, or are simply small enough to have only one server. On the contrary, it will slow down the system efficiency, because the network connection also requires resources
This article has certain reference value, I hope it will be helpful to everyone in need!
The above is the detailed content of A detailed introduction to the operating principle of Memcached [Summary]. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Memcached is a commonly used caching technology that can greatly improve the performance of web applications. In PHP, the commonly used Session processing method is to store the Session file on the server's hard disk. However, this method is not optimal because the server's hard disk will become one of the performance bottlenecks. The use of Memcached caching technology can optimize Session processing in PHP and improve the performance of Web applications. Session in PHP

Caching library in PHP8.0: Memcached With the rapid development of the Internet, modern applications require efficient and reliable caching technology to improve performance and handle large amounts of data. Due to PHP's popularity and open source nature, the PHP caching library has become an essential tool in the web development community. Memcached is a widely used open source high-speed memory caching system that can handle millions of simultaneous connected cache requests and can be used in many different types of applications, such as social networks, online

With the development of the Internet, PHP applications have become more and more common in the field of Internet applications. However, high concurrent access by PHP applications can lead to high CPU usage on the server, thus affecting the performance of the application. In order to optimize the performance of PHP applications, Memcached caching technology has become a good choice. This article will introduce how to use Memcached caching technology to optimize the CPU usage of PHP applications. Introduction to Memcached caching technology Memcached is a

With the rapid development of the Internet, large-scale MySQL database backup and recovery has become one of the essential skills for major enterprises and websites. With the widespread application of Memcached, how to back up and restore Memcached has also become an important issue. As one of the main languages for web development, PHP has unique advantages and skills in handling backup and recovery of MySQL and Memcached. This article will introduce in detail the implementation method of PHP processing MySQL and Memcached backup and recovery.

With the continuous increase of network applications and the continuous expansion of data volume, data reading and writing efficiency has become one of the important factors affecting application performance. The application of caching technology can solve this problem well. In PHP applications, Memcached is the most commonly used cache server. Memcached is a high-performance distributed memory object caching system that can store commonly used data in memory and improve the efficiency of data retrieval. This article will introduce how to use PHP and Memcached for cache management, and how to optimize

With the rapid development of modern Internet applications, user experience is crucial to the success of an application. How to ensure high performance and high availability of applications has become one of the important issues that developers need to solve. As one of the widely used programming languages, PHP's performance monitoring and optimization are also very important. Memcached is a high-performance, distributed memory object caching system that can help applications improve performance and scalability. This article will introduce how to use PHP and Memcached to implement performance monitoring.

With the continuous development of Internet technology, audio and video resources have become a very important form of content on the Internet, and PHP, as one of the most widely used languages in network development, is also constantly used in the field of video and audio playback. However, with the increasing number of users of audio and video websites, many websites have discovered a problem: under high concurrency conditions, PHP's processing speed of audio and video slows down significantly, resulting in problems such as inability to play in time or stuck playback. To solve this problem, Memcached caching technology should

With the rapid growth of modern applications, caching has become a vital part of many developers. Caching can greatly improve application performance and reduce server load. In CakePHP, one way to implement caching is to use Memcached. Memcached is a memory-based distributed caching system. It stores data in memory and can read and write data quickly. In a multi-server environment, Memcached can store data in a distributed manner and share it over the network. not only can