Table of Contents
Articles you may be interested in
Home Backend Development PHP Tutorial What is memcached? How to use memcache? _PHP Tutorial

What is memcached? How to use memcache? _PHP Tutorial

Jul 13, 2016 am 10:31 AM
memcached

What is Memcached?

Memcached is a distributed memory object caching system developed by danga.com (the technical team that operates LiveJournal), which is used to reduce database load and improve performance in dynamic systems. 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 services 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. However, unlike Apache, it is more often oriented towards stable and continuous connections, so its actual concurrency capabilities are limited. . Under conservative circumstances, the maximum number of simultaneous connections for memcached is 200, which is related to Linux thread capabilities. 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.

How to use Memcached?

In many cases, memcached has been abused, which inevitably leads to too many people complaining 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? What is it used for? There was no detailed answer. The author wants to make a point here: memcached is not a panacea, and it is not suitable for all occasions.

Memcached is a "distributed" memory object caching system. That is to say, for 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 bring any 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 the local read and write speed of memcached is dozens of times slower than the direct PHP memory array, while the APC and shared memory methods are similar to the direct array. It can be seen that if it is only a local-level cache, using memcached is very uneconomical.

Memcached is often used as a database front-end cache. 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.

Articles you may be interested in

  • PHP reports Fatal error Allowed memory size of...How to solve the error of insufficient memory
  • Installation of memcache under windows And configuration tutorial
  • What does body mean">What does body mean in html in css
  • php function that calculates the current week of the year or month
  • Usage of MySQL replace function to replace string statements
  • About performance comparison when using in_array() foreach array_search() to find whether an array contains
  • Mysql database cache function analysis, debugging and performance summary
  • Detailed explanation of PHP string escape functions (addslashes, stripslashes)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764126.htmlTechArticleWhat is Memcached? Memcached is a distributed memory object caching system developed by danga.com (the technical team that operates LiveJournal). It is used to reduce database load in dynamic systems and improve...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Memcached caching technology optimizes Session processing in PHP Memcached caching technology optimizes Session processing in PHP May 16, 2023 am 08:41 AM

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 Caching library in PHP8.0: Memcached May 14, 2023 am 08:16 AM

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

How to optimize PHP application CPU usage using Memcached caching technology? How to optimize PHP application CPU usage using Memcached caching technology? Jun 21, 2023 pm 05:07 PM

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

PHP and Memcached database backup and recovery PHP and Memcached database backup and recovery May 15, 2023 pm 09:12 PM

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.

Use Memcached caching technology to optimize audio and video playback in PHP Use Memcached caching technology to optimize audio and video playback in PHP May 17, 2023 pm 04:01 PM

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

Cache management with PHP and Memcached Cache management with PHP and Memcached May 23, 2023 pm 02:21 PM

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

PHP and Memcached performance monitoring PHP and Memcached performance monitoring May 15, 2023 pm 09:51 PM

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.

Use Pagoda Panel to deploy cache servers such as Redis and Memcached Use Pagoda Panel to deploy cache servers such as Redis and Memcached Jun 21, 2023 am 09:56 AM

With the development of the Internet, caching technology plays an increasingly important role in Web development. Redis and Memcached, two popular cache servers, are widely used in various web application development. However, for developers who are not familiar with Linux systems, installing and configuring these cache servers can cause some trouble. However, with the help of Pagoda Panel, this process will become quite simple. 1. What is a pagoda panel? Pagoda panel is a Linux server management panel that can

See all articles