Memcached applications on high-load and high-concurrency websites)

Source: Internet
Author: User
You may have some knowledge about memcached or it has already been applied to your website, but some friends have never heard of or used it.
It does not matter. This article aims to comprehensively introduce such products from various perspectives, so as to be as in-depth as possible. I feel very honored to be able to help you in your current or future work. The content I want to introduce includes the following aspects:
1. Introduction to memcached
2. Application scenarios of memcached
3. Install memcached
4. Use memcached
5. deployment architecture of memcached
6. Limitations of memcached
7. Improvements to memcached 1. Introduction
1.1 Background
Memcached is a high-performance, distributed memory object cache system.
Memcached is widely used on websites with high loads and high concurrency. It is a very mature product (it is also known as a technology ). Websites such as Facebook, YouTube, Yahoo, Sina, Sohu, Netease, and Douban all use this product more or less. Memcached has outstanding performance on user-centered websites, such as SNS, blogs, and other websites of Web2.0 applications. Generally, these sites place special emphasis on user experience. Users have high requirements on server response speed, user data is relatively complex, and the connection level is relatively high. Therefore, databases must be updated and searched frequently.
Memcache is one of several open-source projects in danga.com. It was initially developed for the livejournal.com site. At that time, the site PV reached tens of millions on a daily basis, many problems related to load and response speed occurred during use. Therefore, this project was developed to improve the current difficulties of the website. Memcache can handle any number of connections and use non-blocking network I/O. It is very simple and convenient to use. The most commonly used functions are no more than five methods. Official website of memcache: http://www.danga.com/memcached. Features 1.2
1. High Performance
No matter which type of database DBMS (MySQL, Oracle, MSSQL, DB2, Postgres, etc.), how can we optimize it and finally avoid slow storage media (hard disks and tapes) data exchange. However, once I/O operations on the storage media are involved, the access performance decreases sharply. Memcached, as its name implies, all its operations are performed in the memory from beginning to end, so the data access efficiency is very high.
Of course, generally, large websites optimize database operations. There are two common methods:
A. read/write data separation. Master/Slave databases are used to distribute the database pressure and improve the query speed.
B. Split databases horizontally or vertically according to business characteristics. To put it simply, the database access efficiency is improved by changing the database size from large databases to small databases and tables from large tables to small tables. Generally, a database with many tables or more than N records can significantly reduce the service capability of the database, for example, if the number of records in a single MySQL database is about 20 million (my previous work experience), the performance will drop to almost intolerable. For database design and optimization, we can create a separate topic in the future. We will not do much research here.
The database may encounter access bottlenecks in the following situations:
A. Transaction operations
Enterprise-level databases (such as MySQL's InnoDB mode) support transaction operations. Because the transaction is atomic, the data tables involved in the transaction are locked during running. In this case, data accessing these tables may be delayed.
B. Data Update
Any table in the database will also be locked during data update. In this case, the same result is displayed.
The memcached operation basically does not have the above situation (in fact there is also a locking situation, we will discuss it in detail later), so its performance is very high. The official comments on the official website are very fast. In fact, this is also the case. You can search for the relevant lab test results on the Internet, which is everywhere. 2. A professional explanation of distributed systems is as follows:
A configuration method for computer hardware and corresponding functional configuration methods. It is a multi-processor computer system. Each processor forms a unified system through an interconnected network. The system uses a distributed computing structure, that is, the tasks processed by the central processor in the original system are distributed to the corresponding processor, so that different processors with different functions can coordinate with each other and share system peripherals and software. This accelerates the processing speed of the system and simplifies the logic structure of the host. The distributed features of memcache are mainly manifested in two aspects: A. memcache client MC and server-side ms can be separately installed on any independent server.
Of course, it's okay to deploy it on the same server. You can even deploy n memcached instances on one machine.
B. The memcache server ms can be installed on any number of servers to provide parallel storage and computing capabilities.
This is an essential embodiment of distributed features. Ms can form a cluster composed of multiple servers to provide services for MC. 1.3 usage
1. Improve System concurrency
2. Reduce the burden on the database
These two functions are easy to understand. Because of the high performance of memcached, memcached can serve more connections at the same time, greatly improving the system's concurrent processing capability. In addition, memcached is usually deployed between the business logic layer (foreground application) and the storage layer (primary database) as the data buffer of the database and foreground application, therefore, you can quickly respond to front-end requests and reduce database access.
The following is a memcached deployment logic, where Mc refers to memcached client and Ms refers to memcached server: 1.4 working mechanism. Memcached is a guardianProgramThe client can run on one or more servers at any time. The client can be written in various languages, currently, known client APIs include Perl, PHP, Python, Ruby, Java, C #, and C. The client first establishes a connection with the memcached service and then accesses the object. Each accessed object has a unique identifier key, which is used for access operations. The validity period can be set during storage. Objects stored in memcached are actually stored in the memory rather than on the hard disk. After the memcached process runs, it will pre-apply for a large memory space and manage it on its own. After it is used up, it will apply for another one, instead of applying to the operating system whenever needed. Memcached saves the object in a huge hash table and uses newhashAlgorithmTo manage the hash table for further performance improvement. Therefore, when the memory allocated to memcached is large enough, the time consumed by memcached is basically a network socket connection.
Memcached schedules data in LRU mode. LRU is the abbreviation of least recently used, that is, the least recently used page replacement algorithm, is a virtual page storage management service. The LRU algorithm is related to the operating system in the actual working environment. For example, for a 32-bit operating system, the maximum addressing space is 4 GB. If the current memory usage exceeds this limit, memory will be transferred out, and the memory will always maintain the latest and most commonly used data. The 64-bit operating system greatly extends the addressing capability of the memory. Therefore, many memcached services are running on 64-bit systems.

From: http://wangzebin.blog.51cto.com/653300/128235

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.