Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read. Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.Foreign namesMemcachedbelongs toCache systemWriting LanguagesUnlimitedmeans of communicationMemcached Protocol Directory
-
1 features
-
2 characteristics
-
? Agreement
-
? event handling
-
? storage mode
-
? Communication distributed
-
3 Features
-
4 Tips for using
-
Version 5 released
1 functional editing
memcachedis a set of distributed cache system, originally Danga Interactive for LiveJournal development, but is used by many software (such as MediaWiki). This is a set of open source software that is released under the BSD License licensing agreement. [1] memcached lacks authentication and security controls, which means that the memcached server should be placed behind a firewall. [The 1] memcached API uses a 32-bit cyclic redundancy check (CRC-32) to calculate the key values and distribute the data across different machines. When the table is full, the next additions will be replaced with the LRU mechanism. Since memcached is often used only as a cache system, applications that use memcached require additional code to update memcached data in the case of writing back to a slower system (like a back-end database) [1] memcached It is a software developed by Brad Fitzpatric, a Danga Interactive company of LiveJournal. has become an important factor in improving Web application extensibility in many services such as Mixi, Hatena, Facebook, Vox, and LiveJournal. Many Web applications save data to an RDBMS, where the application server reads the data and displays it in the browser. However, with the increase of data volume and the concentration of access, the burden of RDBMS, database response deterioration, site display delay and other significant impact. This is the time to memcached. Memcached is a high-performance distributed memory cache server. The general purpose is to reduce the number of database accesses by caching database query results to improve the speed and scalability of dynamic Web applications. The Memcached Daemon (daemon) is written in C, but the client can be written in any language and communicates with the daemon through the Memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries), and when a server S is stopped or crashed, all key/value pairs stored on s are lost. Memcached was developed by Danga Interactive, and the latest version was released in 2010 by the author of Anatoly Vorobey and Brad Fitzpatrick. For lifting LiveJournal. COM access speed. LJ Dynamic page visits thousands of times per second, user 7 million. Memcached significantly reduces database load, better allocation of resources, faster access.2 feature edits Memcached, as a distributed cache server with high-speed operation, has the following characteristics. Simple protocol · Event handling based on Libevent · Internal Memory Storage Method · Memcached distributed without communication with each otherProtocolmemcached Server client communication does not use a format such as complex XML, but uses a simple text-line-based protocol. As a result, you can also save data and get data on memcached by using Telnet. Here is an example. $ telnet localhost 11211Trying 127.0.0.1Connected to Localhost.localdomain (127.0.0.1). Escape character is ' ^] '. Set foo 0 0 3 (Save command) bar (data) STORED (result) get foo (get command) VALUE Foo 0 3 (data) bar (data)Event HandlingLibevent is a library that encapsulates event-handling functions such as Linux's Epoll, BSD-class operating system kqueue, and so on as a unified interface. The Performance of O (1) can be played even if the number of connections to the server increases. Memcached uses this libevent library, so it can perform its high performance on Linux, BSD, Solaris and other operating systems. About event handling is no longer detailed here, you can refer to Dan Kegel's c10k problem.Storage ModeTo improve performance, the data saved in memcached is stored in Memcached's built-in memory storage space. Because the data exists only in memory, restarting the memcached and restarting the operating system will cause all data to disappear. Additionally, when the content capacity reaches the specified value, the unused cache is automatically deleted based on the LRU (Least recently used) algorithm. The memcached itself is a server designed for caching, so there is not too much consideration for permanent data issues.Communication DistributedMemcached Although it is a "distributed" cache server, there is no distributed functionality on the server side. Each memcached does not communicate with each other to share information. So, how to distribute it? This depends entirely on the client's implementation. This article will also describe the distribution of memcached.3 functional editing A visual memcached management system written in PHP memadmin is a visual memcached management and Monitoring tool, using PHP development, small size, simple operation. Main functions: Server parameter monitoring: STATS, SETTINGS, ITEMS, slabs, sizes real-time Refresh server performance monitoring: GET, DELETE, INCR, DECR, CAs and other common operation hit rate real-time monitoring support data traversal, Easy to monitor the storage content Support condition query, filter out the key or value array, JSON and other serialized character reverse sequence display compatible with the Memcache protocol, such as Tokyo Tyrant (except traversal function) Support server connection pool, Easy and concise multi-server Management switch4 using tips for editing Many languages implement a client that connects Memcached, with Perl and PHP as the main. Only the languages listed on the memcached website are available · Perl PHP Python Ruby C# C/c++ Lua and so on. How to use the Memcached-server side to run on the server: #./memcached-d-M 2048-l 10.0.0.40-p 11211 This will start a process that consumes 2G of memory and open 11211 ports for receiving requests. Because 32-bit systems can handle only 4G of memory, 2-3 processes are run on 32-bit servers that use PAE larger than 4G of memory and are monitored on different ports. How to use the Memcached-client end to include a class that describes the client on the application side is straightforward to use. PHP Example: $options ["Servers"] = Array ("192.168.1.41:11211", "192.168.1.42:11212"), $options ["Debug"] = false; $MEMC = New Memcachedclient ($options); $myarr = Array ("One", "One", "3"), $memc->set ("Key_one", $myarr); $val = $memc->get (" Key_one ");p rint $val [0]." \ n "; Prints ' one ' print $val [1]. " \ n "; Prints ' both ' Print $val [2]. " \ n "; Prints 3
installation under CentOSInstallation
Yum-y install memcached set to boot
Chkconfig--level 2345 memcached on start and stop
/etc/init.d/memcached start|stop Supplement: If the installation lacks additional support, you can: Yum groupinstall "Development Tools"
High-performance distributed Memory object cache system memcached