Last updated by dormando@rydia.net
I have collected Frequently Asked Questions about memcached.
- General problems
- What is memcached?
- Where can I get memcached?
- How to install memcached?
- Which platforms can run memcached?
- Under what circumstances is memcached suitable for use?
- Under what circumstances is memcached suitable for use?
- How to access memcached?
- How to Use memcached as a database?
- Can all items in memcached be traversed?
General problems
What is memcached?
Memcached is a high-performance, distributed, and in-Memory Object cache system. Memcached is essentially a general cache system, but it is usually used to reduce the load on the database to accelerate Dynamic Web applications.
The purpose of developing memcached is to speed up the livejournal.com development. Livejournal.com this website has a large number of Web
Server and database server, the number of users accessing each day is as high as 1 million, and the daily PV of dynamic web pages is as high as 2 million +. With memcached, the load of the database is greatly reduced, just like it is okay. Memcached accelerates the response time of dynamic web pages, improves resource utilization, and speeds up database access when memcached does not hit.
Where can I get memcached?
Download it on this download page!
How to install memcached?
You can refer to the installation guide or use the software package management system of the operating system to automatically download and install (APT, yum, etc ).
If your Linux release version does not have memcached, or you have memcached but the version is not new enough, you can install it from the source code. Obtain the tar package of the source code from our download page, and then execute the following command in shell:
$ Tar-zxvf memcached-1.x.x.tar.gz
$./Configure -- enable-threads (if you want to use multithreading)
$ Make
$ Make test
$ Sudo make install
You can use './configure -- help' to view all the options.
Which platforms can run memcached?
Any place with idle memory! Memcached can run on Linux, BSD, and windows. It only requires a small amount of CPU time, so you can run it wherever there is idle memory.
Under what circumstances is memcached suitable for use?
If your website contains a dynamic webpage with a large access volume, the database load is high, and most database requests are read operations, memcached can help you significantly reduce the database load.
Memcached is also applicable in many other scenarios. You can read the memcached FAQ and related guides to find some inspiration. If your database load ratio is low but the CPU usage is high, you can cache the calculated results (computed objects) and rendered templates (enderred templates ). With memcached, You Can cache session data and temporary data to reduce write operations on their databases and cache small but frequently accessed files, cache the results of Web 'services' (non-IBM-advertised Web Services, Translator's note) or RSS feeds...
Even if your resources (CPU, memory, database, etc) are adequate, memcached can at least help you speed up page rendering.
Under what circumstances is memcached not suitable?
See here. (This page is also translated below)
Memcached is really great! But not for every scenario...
- The object size is greater than 1 MB.
- Memcached is not designed to process large multimedia (large media) and large binary blocks (streaming huge blobs ).
- Consider other conditions: http://www.danga.com/mogilefs
- The key must contain more than 250 characters.
- If you have used such a long key, you may have done something wrong.
- Also, you can check the email list about the key length.
- Your VM does not allow you to run memcached
- If your application is hosted on a low-end virtual private server (virtual private server, a slice of a machine), Virtualization Technologies such as VMware and xen are not suitable for running memcached. Memcached does need to take over and control large blocks of memory-If memcached memory is exchanged by OS or hypervisor, memcached's performance will be greatly compromised.
- Your application runs in an insecure environment
- Remember, anyone can access your memcached through Telnet alone. If your application runs on a shared system, keep an eye on it!
- You need to persist the data, or you need the database
- If you only want memcached to provide SQL interfaces, you may need to rethink your understanding of cache and memcached. If you want to learn more about this problem, refer to the blog written by dormano below.
- Links
- 2008/08
- Memcached versus more RDBMS sharding at highscalability.com
- Shocould you use memcached? Shocould you just shard MySQL more? By dormano
How to access memcached?
Generally, your application can use the client database of memcached to access one or more memcached instances.
This client page lists all available API libraries, including stored procedures and triggers for Perl, C, C #, PHP, Python, Java, Ruby, and PostgreSQL.
You can write your own client library based on the memcached protocol.
How to Use memcached as a database?
If you want to use memcached as a data storage medium rather than a cache, you should use the database. MySQL cluster has some features similar to memcached (although it is not easy to install MySQL cluster), and MySQL cluster can be used as a reliable distributed storage medium.
Can all items in memcached be traversed?
No! Memcached does not support or plan to support this operation. This operation is relatively slow and blocks other operations (here the slow speed is compared to other memcached commands ). As mentioned above, memcached is a cache, not a database. Tugela and memcachedb are systems derived from memcached. They are slow, but act more like databases.
Of course, memcached is software after all, so in some sense, the answer is yes. However, this operation is indeed slow and blocks memcached. This is not a problem for the development and testing servers, but the answer is no for the true deployment of 99.9%.
What do we mean by blocking memcached? All memcached non-Debug commands, such as ADD, set, get, and fulsh, consume only constant time for execution regardless of how much data is stored in memcached. The amount of time it takes to execute any command that traverses all items will increase as the amount of data in memcached increases. When other commands cannot be executed because they are waiting (the command for traversing all items is executed), blocking occurs.
Maybe you can say that the "delete all my keys" command takes only half a second on average. I have enough CPU idle time. I will execute this command only once every few seconds, so what's the problem? (can't we traverse all items )? (Of course there is a problem) because of this half second, other requests are delayed for at least half second. It'll take as long as it takes the hardware to process through that queue in order to catch up. So all of your other requests end up taking too
Long.
So we try not to do this. If you really need to traverse all items, consider using MySQL to access data with the primary key. You can also use a secondary index to speed up the search.